]>
Commit | Line | Data |
---|---|---|
94831479 | 1 | import * as Bull from 'bull' |
da854ddd | 2 | import { logger } from '../../../helpers/logger' |
3fd3ab2d | 3 | import { processActivities } from '../../activitypub/process' |
f6eebcb3 | 4 | import { addVideoComments } from '../../activitypub/video-comments' |
8fffe21a | 5 | import { crawlCollectionPage } from '../../activitypub/crawl' |
4157cdb1 C |
6 | import { VideoModel } from '../../../models/video/video' |
7 | import { addVideoShares, createRates } from '../../activitypub' | |
f6eebcb3 C |
8 | |
9 | type FetchType = 'activity' | 'video-likes' | 'video-dislikes' | 'video-shares' | 'video-comments' | |
c986175d | 10 | |
94a5ff8a | 11 | export type ActivitypubHttpFetcherPayload = { |
f6eebcb3 C |
12 | uri: string |
13 | type: FetchType | |
14 | videoId?: number | |
94a5ff8a C |
15 | } |
16 | ||
94831479 | 17 | async function processActivityPubHttpFetcher (job: Bull.Job) { |
94a5ff8a C |
18 | logger.info('Processing ActivityPub fetcher in job %d.', job.id) |
19 | ||
f6eebcb3 C |
20 | const payload = job.data as ActivitypubHttpFetcherPayload |
21 | ||
22 | let video: VideoModel | |
23 | if (payload.videoId) video = await VideoModel.loadAndPopulateAccountAndServerAndTags(payload.videoId) | |
c986175d | 24 | |
f6eebcb3 C |
25 | const fetcherType: { [ id in FetchType ]: (items: any[]) => Promise<any> } = { |
26 | 'activity': items => processActivities(items), | |
27 | 'video-likes': items => createRates(items, video, 'like'), | |
28 | 'video-dislikes': items => createRates(items, video, 'dislike'), | |
29 | 'video-shares': items => addVideoShares(items, video), | |
30 | 'video-comments': items => addVideoComments(items, video) | |
c986175d | 31 | } |
f6eebcb3 C |
32 | |
33 | return crawlCollectionPage(payload.uri, fetcherType[payload.type]) | |
c986175d C |
34 | } |
35 | ||
c986175d C |
36 | // --------------------------------------------------------------------------- |
37 | ||
38 | export { | |
94a5ff8a | 39 | processActivityPubHttpFetcher |
c986175d | 40 | } |