X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fjob-queue%2Fhandlers%2Factivitypub-http-fetcher.ts;h=0182c5169f17ac0c2be83afdee3337499f64fea0;hb=818c449b3c34e9f324ac744120c8774e724ab25e;hp=67ccfa9956ec12c3982ad6a5f19b410cc6c76eed;hpb=ae28cdf327d782e629379eee1999096ca2a5d74b;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 67ccfa995..0182c5169 100644 --- a/server/lib/job-queue/handlers/activitypub-http-fetcher.ts +++ b/server/lib/job-queue/handlers/activitypub-http-fetcher.ts @@ -1,17 +1,25 @@ import * as Bull from 'bull' +import * as Bluebird from 'bluebird' 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 { MAccountDefault, MVideoFullLight } from '../../../typings/models' -type FetchType = 'activity' | 'video-likes' | 'video-dislikes' | 'video-shares' | '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) { @@ -19,18 +27,29 @@ async function processActivityPubHttpFetcher (job: Bull.Job) { const payload = job.data as ActivitypubHttpFetcherPayload - let video: VideoModel + let video: MVideoFullLight if (payload.videoId) video = await VideoModel.loadAndPopulateAccountAndServerAndTags(payload.videoId) + let account: MAccountDefault + if (payload.accountId) account = await AccountModel.load(payload.accountId) + const fetcherType: { [ id in FetchType ]: (items: any[]) => Promise } = { - 'activity': items => processActivities(items, { outboxUrl: payload.uri }), + '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) + 'video-comments': items => addVideoComments(items), + 'account-playlists': items => createAccountPlaylists(items, account) + } + + 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), + 'video-shares': crawlStartDate => VideoShareModel.cleanOldSharesOf(video.id, crawlStartDate), + 'video-comments': crawlStartDate => VideoCommentModel.cleanOldCommentsOf(video.id, crawlStartDate) } - return crawlCollectionPage(payload.uri, fetcherType[payload.type]) + return crawlCollectionPage(payload.uri, fetcherType[payload.type], cleanerType[payload.type]) } // ---------------------------------------------------------------------------