]>
Commit | Line | Data |
---|---|---|
94831479 | 1 | import * as Bull from 'bull' |
2ba92871 | 2 | import * as Bluebird from 'bluebird' |
da854ddd | 3 | import { logger } from '../../../helpers/logger' |
3fd3ab2d | 4 | import { processActivities } from '../../activitypub/process' |
f6eebcb3 | 5 | import { addVideoComments } from '../../activitypub/video-comments' |
8fffe21a | 6 | import { crawlCollectionPage } from '../../activitypub/crawl' |
4157cdb1 | 7 | import { VideoModel } from '../../../models/video/video' |
8dc8a34e C |
8 | import { addVideoShares } from '../../activitypub/share' |
9 | import { createRates } from '../../activitypub/video-rates' | |
418d092a C |
10 | import { createAccountPlaylists } from '../../activitypub/playlist' |
11 | import { AccountModel } from '../../../models/account/account' | |
2ba92871 C |
12 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' |
13 | import { VideoShareModel } from '../../../models/video/video-share' | |
14 | import { VideoCommentModel } from '../../../models/video/video-comment' | |
453e83ea | 15 | import { MAccountDefault, MVideoFullLight } from '../../../typings/models' |
8dc8a34e | 16 | import { ActivitypubHttpFetcherPayload, FetchType } from '@shared/models' |
94a5ff8a | 17 | |
94831479 | 18 | async function processActivityPubHttpFetcher (job: Bull.Job) { |
94a5ff8a C |
19 | logger.info('Processing ActivityPub fetcher in job %d.', job.id) |
20 | ||
f6eebcb3 C |
21 | const payload = job.data as ActivitypubHttpFetcherPayload |
22 | ||
453e83ea | 23 | let video: MVideoFullLight |
f6eebcb3 | 24 | if (payload.videoId) video = await VideoModel.loadAndPopulateAccountAndServerAndTags(payload.videoId) |
c986175d | 25 | |
453e83ea | 26 | let account: MAccountDefault |
418d092a C |
27 | if (payload.accountId) account = await AccountModel.load(payload.accountId) |
28 | ||
f6eebcb3 | 29 | const fetcherType: { [ id in FetchType ]: (items: any[]) => Promise<any> } = { |
1198edf4 | 30 | 'activity': items => processActivities(items, { outboxUrl: payload.uri, fromFetch: true }), |
f6eebcb3 C |
31 | 'video-likes': items => createRates(items, video, 'like'), |
32 | 'video-dislikes': items => createRates(items, video, 'dislike'), | |
33 | 'video-shares': items => addVideoShares(items, video), | |
6b9c966f | 34 | 'video-comments': items => addVideoComments(items), |
418d092a | 35 | 'account-playlists': items => createAccountPlaylists(items, account) |
c986175d | 36 | } |
f6eebcb3 | 37 | |
2ba92871 C |
38 | const cleanerType: { [ id in FetchType ]?: (crawlStartDate: Date) => Bluebird<any> } = { |
39 | 'video-likes': crawlStartDate => AccountVideoRateModel.cleanOldRatesOf(video.id, 'like' as 'like', crawlStartDate), | |
40 | 'video-dislikes': crawlStartDate => AccountVideoRateModel.cleanOldRatesOf(video.id, 'dislike' as 'dislike', crawlStartDate), | |
41 | 'video-shares': crawlStartDate => VideoShareModel.cleanOldSharesOf(video.id, crawlStartDate), | |
42 | 'video-comments': crawlStartDate => VideoCommentModel.cleanOldCommentsOf(video.id, crawlStartDate) | |
43 | } | |
44 | ||
45 | return crawlCollectionPage(payload.uri, fetcherType[payload.type], cleanerType[payload.type]) | |
c986175d C |
46 | } |
47 | ||
c986175d C |
48 | // --------------------------------------------------------------------------- |
49 | ||
50 | export { | |
94a5ff8a | 51 | processActivityPubHttpFetcher |
c986175d | 52 | } |