]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/job-queue/handlers/activitypub-http-fetcher.ts
Limit user tokens cache
[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'
418d092a
C
8import { createAccountPlaylists } from '../../activitypub/playlist'
9import { AccountModel } from '../../../models/account/account'
f6eebcb3 10
418d092a 11type FetchType = 'activity' | 'video-likes' | 'video-dislikes' | 'video-shares' | 'video-comments' | 'account-playlists'
c986175d 12
94a5ff8a 13export type ActivitypubHttpFetcherPayload = {
f6eebcb3
C
14 uri: string
15 type: FetchType
16 videoId?: number
418d092a 17 accountId?: number
94a5ff8a
C
18}
19
94831479 20async function processActivityPubHttpFetcher (job: Bull.Job) {
94a5ff8a
C
21 logger.info('Processing ActivityPub fetcher in job %d.', job.id)
22
f6eebcb3
C
23 const payload = job.data as ActivitypubHttpFetcherPayload
24
25 let video: VideoModel
26 if (payload.videoId) video = await VideoModel.loadAndPopulateAccountAndServerAndTags(payload.videoId)
c986175d 27
418d092a
C
28 let account: AccountModel
29 if (payload.accountId) account = await AccountModel.load(payload.accountId)
30
f6eebcb3 31 const fetcherType: { [ id in FetchType ]: (items: any[]) => Promise<any> } = {
5c6d985f 32 'activity': items => processActivities(items, { outboxUrl: payload.uri }),
f6eebcb3
C
33 'video-likes': items => createRates(items, video, 'like'),
34 'video-dislikes': items => createRates(items, video, 'dislike'),
35 'video-shares': items => addVideoShares(items, video),
418d092a
C
36 'video-comments': items => addVideoComments(items, video),
37 'account-playlists': items => createAccountPlaylists(items, account)
c986175d 38 }
f6eebcb3
C
39
40 return crawlCollectionPage(payload.uri, fetcherType[payload.type])
c986175d
C
41}
42
c986175d
C
43// ---------------------------------------------------------------------------
44
45export {
94a5ff8a 46 processActivityPubHttpFetcher
c986175d 47}