From f6eebcb336c067e160a62020a5140d8d992ba384 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 22 Aug 2018 11:51:39 +0200 Subject: Add ability to search a video with an URL --- .../job-queue/handlers/activitypub-http-fetcher.ts | 26 +++++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'server/lib/job-queue/handlers') diff --git a/server/lib/job-queue/handlers/activitypub-http-fetcher.ts b/server/lib/job-queue/handlers/activitypub-http-fetcher.ts index f21da087e..72d670277 100644 --- a/server/lib/job-queue/handlers/activitypub-http-fetcher.ts +++ b/server/lib/job-queue/handlers/activitypub-http-fetcher.ts @@ -1,22 +1,36 @@ import * as Bull from 'bull' import { logger } from '../../../helpers/logger' import { processActivities } from '../../activitypub/process' -import { ActivitypubHttpBroadcastPayload } from './activitypub-http-broadcast' +import { VideoModel } from '../../../models/video/video' +import { addVideoShares, createRates } from '../../activitypub/videos' +import { addVideoComments } from '../../activitypub/video-comments' import { crawlCollectionPage } from '../../activitypub/crawl' -import { Activity } from '../../../../shared/models/activitypub' + +type FetchType = 'activity' | 'video-likes' | 'video-dislikes' | 'video-shares' | 'video-comments' export type ActivitypubHttpFetcherPayload = { - uris: string[] + uri: string + type: FetchType + videoId?: number } async function processActivityPubHttpFetcher (job: Bull.Job) { logger.info('Processing ActivityPub fetcher in job %d.', job.id) - const payload = job.data as ActivitypubHttpBroadcastPayload + const payload = job.data as ActivitypubHttpFetcherPayload + + let video: VideoModel + if (payload.videoId) video = await VideoModel.loadAndPopulateAccountAndServerAndTags(payload.videoId) - for (const uri of payload.uris) { - await crawlCollectionPage(uri, (items) => processActivities(items)) + const fetcherType: { [ id in FetchType ]: (items: any[]) => Promise } = { + 'activity': items => processActivities(items), + '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) } + + return crawlCollectionPage(payload.uri, fetcherType[payload.type]) } // --------------------------------------------------------------------------- -- cgit v1.2.3