]>
Commit | Line | Data |
---|---|---|
5a921e7b | 1 | import { Job } from 'bullmq' |
b49f22d8 | 2 | import { ActivitypubHttpFetcherPayload, FetchType } from '@shared/models' |
da854ddd | 3 | import { logger } from '../../../helpers/logger' |
b49f22d8 | 4 | import { VideoModel } from '../../../models/video/video' |
2ba92871 | 5 | import { VideoCommentModel } from '../../../models/video/video-comment' |
b49f22d8 | 6 | import { VideoShareModel } from '../../../models/video/video-share' |
37a44fc9 | 7 | import { MVideoFullLight } from '../../../types/models' |
b49f22d8 | 8 | import { crawlCollectionPage } from '../../activitypub/crawl' |
49af5ac8 | 9 | import { createAccountPlaylists } from '../../activitypub/playlists' |
b49f22d8 C |
10 | import { processActivities } from '../../activitypub/process' |
11 | import { addVideoShares } from '../../activitypub/share' | |
12 | import { addVideoComments } from '../../activitypub/video-comments' | |
94a5ff8a | 13 | |
41fb13c3 | 14 | async function processActivityPubHttpFetcher (job: Job) { |
bd911b54 | 15 | logger.info('Processing ActivityPub fetcher in job %s.', job.id) |
94a5ff8a | 16 | |
f6eebcb3 C |
17 | const payload = job.data as ActivitypubHttpFetcherPayload |
18 | ||
453e83ea | 19 | let video: MVideoFullLight |
4fae2b1f | 20 | if (payload.videoId) video = await VideoModel.loadFull(payload.videoId) |
c986175d | 21 | |
f6eebcb3 | 22 | const fetcherType: { [ id in FetchType ]: (items: any[]) => Promise<any> } = { |
1198edf4 | 23 | 'activity': items => processActivities(items, { outboxUrl: payload.uri, fromFetch: true }), |
f6eebcb3 | 24 | 'video-shares': items => addVideoShares(items, video), |
6b9c966f | 25 | 'video-comments': items => addVideoComments(items), |
37a44fc9 | 26 | 'account-playlists': items => createAccountPlaylists(items) |
c986175d | 27 | } |
f6eebcb3 | 28 | |
b49f22d8 | 29 | const cleanerType: { [ id in FetchType ]?: (crawlStartDate: Date) => Promise<any> } = { |
2ba92871 C |
30 | 'video-shares': crawlStartDate => VideoShareModel.cleanOldSharesOf(video.id, crawlStartDate), |
31 | 'video-comments': crawlStartDate => VideoCommentModel.cleanOldCommentsOf(video.id, crawlStartDate) | |
32 | } | |
33 | ||
34 | return crawlCollectionPage(payload.uri, fetcherType[payload.type], cleanerType[payload.type]) | |
c986175d C |
35 | } |
36 | ||
c986175d C |
37 | // --------------------------------------------------------------------------- |
38 | ||
39 | export { | |
94a5ff8a | 40 | processActivityPubHttpFetcher |
c986175d | 41 | } |