diff options
Diffstat (limited to 'server/lib/job-queue/handlers')
-rw-r--r-- | server/lib/job-queue/handlers/activitypub-http-fetcher.ts | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/server/lib/job-queue/handlers/activitypub-http-fetcher.ts b/server/lib/job-queue/handlers/activitypub-http-fetcher.ts index f21da087e..72d670277 100644 --- a/server/lib/job-queue/handlers/activitypub-http-fetcher.ts +++ b/server/lib/job-queue/handlers/activitypub-http-fetcher.ts | |||
@@ -1,22 +1,36 @@ | |||
1 | import * as Bull from 'bull' | 1 | import * as Bull from 'bull' |
2 | import { logger } from '../../../helpers/logger' | 2 | import { logger } from '../../../helpers/logger' |
3 | import { processActivities } from '../../activitypub/process' | 3 | import { processActivities } from '../../activitypub/process' |
4 | import { ActivitypubHttpBroadcastPayload } from './activitypub-http-broadcast' | 4 | import { VideoModel } from '../../../models/video/video' |
5 | import { addVideoShares, createRates } from '../../activitypub/videos' | ||
6 | import { addVideoComments } from '../../activitypub/video-comments' | ||
5 | import { crawlCollectionPage } from '../../activitypub/crawl' | 7 | import { crawlCollectionPage } from '../../activitypub/crawl' |
6 | import { Activity } from '../../../../shared/models/activitypub' | 8 | |
9 | type FetchType = 'activity' | 'video-likes' | 'video-dislikes' | 'video-shares' | 'video-comments' | ||
7 | 10 | ||
8 | export type ActivitypubHttpFetcherPayload = { | 11 | export type ActivitypubHttpFetcherPayload = { |
9 | uris: string[] | 12 | uri: string |
13 | type: FetchType | ||
14 | videoId?: number | ||
10 | } | 15 | } |
11 | 16 | ||
12 | async function processActivityPubHttpFetcher (job: Bull.Job) { | 17 | async function processActivityPubHttpFetcher (job: Bull.Job) { |
13 | logger.info('Processing ActivityPub fetcher in job %d.', job.id) | 18 | logger.info('Processing ActivityPub fetcher in job %d.', job.id) |
14 | 19 | ||
15 | const payload = job.data as ActivitypubHttpBroadcastPayload | 20 | const payload = job.data as ActivitypubHttpFetcherPayload |
21 | |||
22 | let video: VideoModel | ||
23 | if (payload.videoId) video = await VideoModel.loadAndPopulateAccountAndServerAndTags(payload.videoId) | ||
16 | 24 | ||
17 | for (const uri of payload.uris) { | 25 | const fetcherType: { [ id in FetchType ]: (items: any[]) => Promise<any> } = { |
18 | await crawlCollectionPage<Activity>(uri, (items) => processActivities(items)) | 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) | ||
19 | } | 31 | } |
32 | |||
33 | return crawlCollectionPage(payload.uri, fetcherType[payload.type]) | ||
20 | } | 34 | } |
21 | 35 | ||
22 | // --------------------------------------------------------------------------- | 36 | // --------------------------------------------------------------------------- |