X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fjob-queue%2Fhandlers%2Factivitypub-http-fetcher.ts;h=04b25f955958a0c4cdd5423b9e5249c51786576f;hb=7500d6c9000b531fda1fd64e188b7cf83803941a;hp=c3f59dc7781186d4dfc797b66298bd0fafe50e67;hpb=6b9c966f6428c9e47bead3410a0401e8ebd744bf;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/job-queue/handlers/activitypub-http-fetcher.ts b/server/lib/job-queue/handlers/activitypub-http-fetcher.ts index c3f59dc77..04b25f955 100644 --- a/server/lib/job-queue/handlers/activitypub-http-fetcher.ts +++ b/server/lib/job-queue/handlers/activitypub-http-fetcher.ts @@ -1,35 +1,28 @@ import * as Bull from 'bull' -import * as Bluebird from 'bluebird' +import { ActivitypubHttpFetcherPayload, FetchType } from '@shared/models' import { logger } from '../../../helpers/logger' -import { processActivities } from '../../activitypub/process' -import { addVideoComments } from '../../activitypub/video-comments' -import { crawlCollectionPage } from '../../activitypub/crawl' -import { VideoModel } from '../../../models/video/video' -import { addVideoShares, createRates } from '../../activitypub' -import { createAccountPlaylists } from '../../activitypub/playlist' import { AccountModel } from '../../../models/account/account' import { AccountVideoRateModel } from '../../../models/account/account-video-rate' -import { VideoShareModel } from '../../../models/video/video-share' +import { VideoModel } from '../../../models/video/video' import { VideoCommentModel } from '../../../models/video/video-comment' - -type FetchType = 'activity' | 'video-likes' | 'video-dislikes' | 'video-shares' | 'video-comments' | 'account-playlists' - -export type ActivitypubHttpFetcherPayload = { - uri: string - type: FetchType - videoId?: number - accountId?: number -} +import { VideoShareModel } from '../../../models/video/video-share' +import { MAccountDefault, MVideoFullLight } from '../../../types/models' +import { crawlCollectionPage } from '../../activitypub/crawl' +import { createAccountPlaylists } from '../../activitypub/playlists' +import { processActivities } from '../../activitypub/process' +import { addVideoShares } from '../../activitypub/share' +import { addVideoComments } from '../../activitypub/video-comments' +import { createRates } from '../../activitypub/video-rates' async function processActivityPubHttpFetcher (job: Bull.Job) { logger.info('Processing ActivityPub fetcher in job %d.', job.id) const payload = job.data as ActivitypubHttpFetcherPayload - let video: VideoModel + let video: MVideoFullLight if (payload.videoId) video = await VideoModel.loadAndPopulateAccountAndServerAndTags(payload.videoId) - let account: AccountModel + let account: MAccountDefault if (payload.accountId) account = await AccountModel.load(payload.accountId) const fetcherType: { [ id in FetchType ]: (items: any[]) => Promise } = { @@ -41,7 +34,7 @@ async function processActivityPubHttpFetcher (job: Bull.Job) { 'account-playlists': items => createAccountPlaylists(items, account) } - const cleanerType: { [ id in FetchType ]?: (crawlStartDate: Date) => Bluebird } = { + const cleanerType: { [ id in FetchType ]?: (crawlStartDate: Date) => Promise } = { '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),