1
0
Fork 0
peertube/server/lib/job-queue/handlers/activitypub-http-fetcher.ts

41 lines
1.5 KiB
TypeScript
Raw Normal View History

2018-07-10 11:02:20 -04:00
import * as Bull from 'bull'
2017-12-28 05:16:08 -05:00
import { logger } from '../../../helpers/logger'
2017-12-12 11:53:50 -05:00
import { processActivities } from '../../activitypub/process'
import { VideoModel } from '../../../models/video/video'
import { addVideoShares, createRates } from '../../activitypub/videos'
import { addVideoComments } from '../../activitypub/video-comments'
import { crawlCollectionPage } from '../../activitypub/crawl'
type FetchType = 'activity' | 'video-likes' | 'video-dislikes' | 'video-shares' | 'video-comments'
2017-11-22 04:29:55 -05:00
export type ActivitypubHttpFetcherPayload = {
uri: string
type: FetchType
videoId?: number
}
2018-07-10 11:02:20 -04:00
async function processActivityPubHttpFetcher (job: Bull.Job) {
logger.info('Processing ActivityPub fetcher in job %d.', job.id)
const payload = job.data as ActivitypubHttpFetcherPayload
let video: VideoModel
if (payload.videoId) video = await VideoModel.loadAndPopulateAccountAndServerAndTags(payload.videoId)
2017-11-22 04:29:55 -05:00
const fetcherType: { [ id in FetchType ]: (items: any[]) => Promise<any> } = {
'activity': items => processActivities(items),
'video-likes': items => createRates(items, video, 'like'),
'video-dislikes': items => createRates(items, video, 'dislike'),
'video-shares': items => addVideoShares(items, video),
'video-comments': items => addVideoComments(items, video)
2017-11-22 04:29:55 -05:00
}
return crawlCollectionPage(payload.uri, fetcherType[payload.type])
2017-11-22 04:29:55 -05:00
}
// ---------------------------------------------------------------------------
export {
processActivityPubHttpFetcher
2017-11-22 04:29:55 -05:00
}