]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/job-queue/handlers/activitypub-http-fetcher.ts
Use random names for VOD HLS playlists
[github/Chocobozzz/PeerTube.git] / server / lib / job-queue / handlers / activitypub-http-fetcher.ts
CommitLineData
94831479 1import * as Bull from 'bull'
b49f22d8 2import { ActivitypubHttpFetcherPayload, FetchType } from '@shared/models'
da854ddd 3import { logger } from '../../../helpers/logger'
2ba92871 4import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
b49f22d8 5import { VideoModel } from '../../../models/video/video'
2ba92871 6import { VideoCommentModel } from '../../../models/video/video-comment'
b49f22d8 7import { VideoShareModel } from '../../../models/video/video-share'
37a44fc9 8import { MVideoFullLight } from '../../../types/models'
b49f22d8 9import { crawlCollectionPage } from '../../activitypub/crawl'
49af5ac8 10import { createAccountPlaylists } from '../../activitypub/playlists'
b49f22d8
C
11import { processActivities } from '../../activitypub/process'
12import { addVideoShares } from '../../activitypub/share'
13import { addVideoComments } from '../../activitypub/video-comments'
14import { createRates } from '../../activitypub/video-rates'
94a5ff8a 15
94831479 16async function processActivityPubHttpFetcher (job: Bull.Job) {
94a5ff8a
C
17 logger.info('Processing ActivityPub fetcher in job %d.', job.id)
18
f6eebcb3
C
19 const payload = job.data as ActivitypubHttpFetcherPayload
20
453e83ea 21 let video: MVideoFullLight
f6eebcb3 22 if (payload.videoId) video = await VideoModel.loadAndPopulateAccountAndServerAndTags(payload.videoId)
c986175d 23
f6eebcb3 24 const fetcherType: { [ id in FetchType ]: (items: any[]) => Promise<any> } = {
1198edf4 25 'activity': items => processActivities(items, { outboxUrl: payload.uri, fromFetch: true }),
f6eebcb3
C
26 'video-likes': items => createRates(items, video, 'like'),
27 'video-dislikes': items => createRates(items, video, 'dislike'),
28 'video-shares': items => addVideoShares(items, video),
6b9c966f 29 'video-comments': items => addVideoComments(items),
37a44fc9 30 'account-playlists': items => createAccountPlaylists(items)
c986175d 31 }
f6eebcb3 32
b49f22d8 33 const cleanerType: { [ id in FetchType ]?: (crawlStartDate: Date) => Promise<any> } = {
2ba92871
C
34 'video-likes': crawlStartDate => AccountVideoRateModel.cleanOldRatesOf(video.id, 'like' as 'like', crawlStartDate),
35 'video-dislikes': crawlStartDate => AccountVideoRateModel.cleanOldRatesOf(video.id, 'dislike' as 'dislike', crawlStartDate),
36 'video-shares': crawlStartDate => VideoShareModel.cleanOldSharesOf(video.id, crawlStartDate),
37 'video-comments': crawlStartDate => VideoCommentModel.cleanOldCommentsOf(video.id, crawlStartDate)
38 }
39
40 return crawlCollectionPage(payload.uri, fetcherType[payload.type], cleanerType[payload.type])
c986175d
C
41}
42
c986175d
C
43// ---------------------------------------------------------------------------
44
45export {
94a5ff8a 46 processActivityPubHttpFetcher
c986175d 47}