]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/job-queue/handlers/activitypub-http-fetcher.ts
Cache refresh actor promise
[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'
418d092a 4import { AccountModel } from '../../../models/account/account'
2ba92871 5import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
b49f22d8 6import { VideoModel } from '../../../models/video/video'
2ba92871 7import { VideoCommentModel } from '../../../models/video/video-comment'
b49f22d8 8import { VideoShareModel } from '../../../models/video/video-share'
26d6bf65 9import { MAccountDefault, MVideoFullLight } from '../../../types/models'
b49f22d8 10import { crawlCollectionPage } from '../../activitypub/crawl'
49af5ac8 11import { createAccountPlaylists } from '../../activitypub/playlists'
b49f22d8
C
12import { processActivities } from '../../activitypub/process'
13import { addVideoShares } from '../../activitypub/share'
14import { addVideoComments } from '../../activitypub/video-comments'
15import { createRates } from '../../activitypub/video-rates'
94a5ff8a 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
453e83ea 22 let video: MVideoFullLight
f6eebcb3 23 if (payload.videoId) video = await VideoModel.loadAndPopulateAccountAndServerAndTags(payload.videoId)
c986175d 24
453e83ea 25 let account: MAccountDefault
418d092a
C
26 if (payload.accountId) account = await AccountModel.load(payload.accountId)
27
f6eebcb3 28 const fetcherType: { [ id in FetchType ]: (items: any[]) => Promise<any> } = {
1198edf4 29 'activity': items => processActivities(items, { outboxUrl: payload.uri, fromFetch: true }),
f6eebcb3
C
30 'video-likes': items => createRates(items, video, 'like'),
31 'video-dislikes': items => createRates(items, video, 'dislike'),
32 'video-shares': items => addVideoShares(items, video),
6b9c966f 33 'video-comments': items => addVideoComments(items),
418d092a 34 'account-playlists': items => createAccountPlaylists(items, account)
c986175d 35 }
f6eebcb3 36
b49f22d8 37 const cleanerType: { [ id in FetchType ]?: (crawlStartDate: Date) => Promise<any> } = {
2ba92871
C
38 'video-likes': crawlStartDate => AccountVideoRateModel.cleanOldRatesOf(video.id, 'like' as 'like', crawlStartDate),
39 'video-dislikes': crawlStartDate => AccountVideoRateModel.cleanOldRatesOf(video.id, 'dislike' as 'dislike', crawlStartDate),
40 'video-shares': crawlStartDate => VideoShareModel.cleanOldSharesOf(video.id, crawlStartDate),
41 'video-comments': crawlStartDate => VideoCommentModel.cleanOldCommentsOf(video.id, crawlStartDate)
42 }
43
44 return crawlCollectionPage(payload.uri, fetcherType[payload.type], cleanerType[payload.type])
c986175d
C
45}
46
c986175d
C
47// ---------------------------------------------------------------------------
48
49export {
94a5ff8a 50 processActivityPubHttpFetcher
c986175d 51}