]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/job-queue/handlers/activitypub-http-fetcher.ts
Refractor videos AP functions
[github/Chocobozzz/PeerTube.git] / server / lib / job-queue / handlers / activitypub-http-fetcher.ts
CommitLineData
94831479 1import * as Bull from 'bull'
da854ddd 2import { logger } from '../../../helpers/logger'
3fd3ab2d 3import { processActivities } from '../../activitypub/process'
f6eebcb3 4import { addVideoComments } from '../../activitypub/video-comments'
8fffe21a 5import { crawlCollectionPage } from '../../activitypub/crawl'
4157cdb1
C
6import { VideoModel } from '../../../models/video/video'
7import { addVideoShares, createRates } from '../../activitypub'
f6eebcb3
C
8
9type FetchType = 'activity' | 'video-likes' | 'video-dislikes' | 'video-shares' | 'video-comments'
c986175d 10
94a5ff8a 11export type ActivitypubHttpFetcherPayload = {
f6eebcb3
C
12 uri: string
13 type: FetchType
14 videoId?: number
94a5ff8a
C
15}
16
94831479 17async 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
38export {
94a5ff8a 39 processActivityPubHttpFetcher
c986175d 40}