1
0
Fork 0
peertube/server/lib/job-queue/handlers/activitypub-http-fetcher.ts

53 lines
2.6 KiB
TypeScript
Raw Normal View History

2018-07-10 15:02:20 +00:00
import * as Bull from 'bull'
2019-03-19 15:23:02 +00:00
import * as Bluebird from 'bluebird'
2017-12-28 10:16:08 +00:00
import { logger } from '../../../helpers/logger'
2017-12-12 16:53:50 +00:00
import { processActivities } from '../../activitypub/process'
import { addVideoComments } from '../../activitypub/video-comments'
import { crawlCollectionPage } from '../../activitypub/crawl'
2018-09-19 09:16:23 +00:00
import { VideoModel } from '../../../models/video/video'
2020-04-23 07:32:53 +00:00
import { addVideoShares } from '../../activitypub/share'
import { createRates } from '../../activitypub/video-rates'
2019-02-26 09:55:40 +00:00
import { createAccountPlaylists } from '../../activitypub/playlist'
import { AccountModel } from '../../../models/account/account'
2019-03-19 15:23:02 +00:00
import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
import { VideoShareModel } from '../../../models/video/video-share'
import { VideoCommentModel } from '../../../models/video/video-comment'
2020-06-18 08:45:25 +00:00
import { MAccountDefault, MVideoFullLight } from '../../../types/models'
2020-04-23 07:32:53 +00:00
import { ActivitypubHttpFetcherPayload, FetchType } from '@shared/models'
2018-07-10 15:02:20 +00:00
async function processActivityPubHttpFetcher (job: Bull.Job) {
logger.info('Processing ActivityPub fetcher in job %d.', job.id)
const payload = job.data as ActivitypubHttpFetcherPayload
2019-08-15 09:53:26 +00:00
let video: MVideoFullLight
if (payload.videoId) video = await VideoModel.loadAndPopulateAccountAndServerAndTags(payload.videoId)
2017-11-22 09:29:55 +00:00
2019-08-15 09:53:26 +00:00
let account: MAccountDefault
2019-02-26 09:55:40 +00:00
if (payload.accountId) account = await AccountModel.load(payload.accountId)
const fetcherType: { [ id in FetchType ]: (items: any[]) => Promise<any> } = {
2019-08-02 08:53:36 +00:00
'activity': items => processActivities(items, { outboxUrl: payload.uri, fromFetch: true }),
'video-likes': items => createRates(items, video, 'like'),
'video-dislikes': items => createRates(items, video, 'dislike'),
'video-shares': items => addVideoShares(items, video),
2019-08-06 15:19:53 +00:00
'video-comments': items => addVideoComments(items),
2019-02-26 09:55:40 +00:00
'account-playlists': items => createAccountPlaylists(items, account)
2017-11-22 09:29:55 +00:00
}
2019-03-19 15:23:02 +00:00
const cleanerType: { [ id in FetchType ]?: (crawlStartDate: Date) => Bluebird<any> } = {
'video-likes': crawlStartDate => AccountVideoRateModel.cleanOldRatesOf(video.id, 'like' as 'like', crawlStartDate),
'video-dislikes': crawlStartDate => AccountVideoRateModel.cleanOldRatesOf(video.id, 'dislike' as 'dislike', crawlStartDate),
'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 09:29:55 +00:00
}
// ---------------------------------------------------------------------------
export {
processActivityPubHttpFetcher
2017-11-22 09:29:55 +00:00
}