PeerTube/server/lib/job-queue/handlers/activitypub-http-fetcher.ts

42 lines
1.8 KiB
TypeScript
Raw Normal View History

2022-08-08 03:42:08 -05:00
import { Job } from 'bullmq'
2020-12-08 07:30:29 -06:00
import { ActivitypubHttpFetcherPayload, FetchType } from '@shared/models'
2017-12-28 04:16:08 -06:00
import { logger } from '../../../helpers/logger'
2020-12-08 07:30:29 -06:00
import { VideoModel } from '../../../models/video/video'
2019-03-19 10:23:02 -05:00
import { VideoCommentModel } from '../../../models/video/video-comment'
2020-12-08 07:30:29 -06:00
import { VideoShareModel } from '../../../models/video/video-share'
2021-06-17 09:02:38 -05:00
import { MVideoFullLight } from '../../../types/models'
2020-12-08 07:30:29 -06:00
import { crawlCollectionPage } from '../../activitypub/crawl'
2021-06-03 07:30:09 -05:00
import { createAccountPlaylists } from '../../activitypub/playlists'
2020-12-08 07:30:29 -06:00
import { processActivities } from '../../activitypub/process'
import { addVideoShares } from '../../activitypub/share'
import { addVideoComments } from '../../activitypub/video-comments'
2021-08-27 07:32:44 -05:00
async function processActivityPubHttpFetcher (job: Job) {
2022-08-08 08:48:17 -05:00
logger.info('Processing ActivityPub fetcher in job %s.', job.id)
const payload = job.data as ActivitypubHttpFetcherPayload
2019-08-15 04:53:26 -05:00
let video: MVideoFullLight
2022-06-28 07:57:51 -05:00
if (payload.videoId) video = await VideoModel.loadFull(payload.videoId)
2017-11-22 03:29:55 -06:00
const fetcherType: { [ id in FetchType ]: (items: any[]) => Promise<any> } = {
2019-08-02 03:53:36 -05:00
'activity': items => processActivities(items, { outboxUrl: payload.uri, fromFetch: true }),
'video-shares': items => addVideoShares(items, video),
2019-08-06 10:19:53 -05:00
'video-comments': items => addVideoComments(items),
2021-06-17 09:02:38 -05:00
'account-playlists': items => createAccountPlaylists(items)
2017-11-22 03:29:55 -06:00
}
2020-12-08 07:30:29 -06:00
const cleanerType: { [ id in FetchType ]?: (crawlStartDate: Date) => Promise<any> } = {
2019-03-19 10:23:02 -05:00
'video-shares': crawlStartDate => VideoShareModel.cleanOldSharesOf(video.id, crawlStartDate),
'video-comments': crawlStartDate => VideoCommentModel.cleanOldCommentsOf(video.id, crawlStartDate)
}
return crawlCollectionPage(payload.uri, fetcherType[payload.type], cleanerType[payload.type])
2017-11-22 03:29:55 -06:00
}
// ---------------------------------------------------------------------------
export {
processActivityPubHttpFetcher
2017-11-22 03:29:55 -06:00
}