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