X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fjob-queue%2Fhandlers%2Factivitypub-http-fetcher.ts;h=b6cb3c4a694df286382b16b90f2a8cc85c2596a8;hb=405c83f9af377a663a4c8e9ad025fd5c10496922;hp=4da645f072e0e8d475e1277f666bbb546e79b06f;hpb=1198edf4bb06ce5f1668b97cf9ca8fb483fe3f41;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 4da645f07..b6cb3c4a6 100644 --- a/server/lib/job-queue/handlers/activitypub-http-fetcher.ts +++ b/server/lib/job-queue/handlers/activitypub-http-fetcher.ts @@ -1,49 +1,32 @@ -import * as Bull from 'bull' -import * as Bluebird from 'bluebird' +import { Job } from 'bullmq' +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 { VideoCommentModel } from '../../../models/video/video-comment' +import { VideoShareModel } from '../../../models/video/video-share' +import { 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' -type FetchType = 'activity' | 'video-likes' | 'video-dislikes' | 'video-shares' | 'video-comments' | 'account-playlists' - -export type ActivitypubHttpFetcherPayload = { - uri: string - type: FetchType - videoId?: number - accountId?: number -} - -async function processActivityPubHttpFetcher (job: Bull.Job) { - logger.info('Processing ActivityPub fetcher in job %d.', job.id) +async function processActivityPubHttpFetcher (job: Job) { + logger.info('Processing ActivityPub fetcher in job %s.', job.id) const payload = job.data as ActivitypubHttpFetcherPayload - let video: VideoModel - if (payload.videoId) video = await VideoModel.loadAndPopulateAccountAndServerAndTags(payload.videoId) - - let account: AccountModel - if (payload.accountId) account = await AccountModel.load(payload.accountId) + let video: MVideoFullLight + if (payload.videoId) video = await VideoModel.loadFull(payload.videoId) const fetcherType: { [ id in FetchType ]: (items: any[]) => Promise } = { '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), - 'video-comments': items => addVideoComments(items, video), - 'account-playlists': items => createAccountPlaylists(items, account) + 'video-comments': items => addVideoComments(items), + 'account-playlists': items => createAccountPlaylists(items) } - const cleanerType: { [ id in FetchType ]?: (crawlStartDate: Date) => Bluebird } = { - 'video-likes': crawlStartDate => AccountVideoRateModel.cleanOldRatesOf(video.id, 'like' as 'like', crawlStartDate), - 'video-dislikes': crawlStartDate => AccountVideoRateModel.cleanOldRatesOf(video.id, 'dislike' as 'dislike', crawlStartDate), + const cleanerType: { [ id in FetchType ]?: (crawlStartDate: Date) => Promise } = { 'video-shares': crawlStartDate => VideoShareModel.cleanOldSharesOf(video.id, crawlStartDate), 'video-comments': crawlStartDate => VideoCommentModel.cleanOldCommentsOf(video.id, crawlStartDate) }