From 04b8c3fba614efc3827f583096c78b08cb668470 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 20 Nov 2018 10:05:51 +0100 Subject: Delete invalid or deleted remote videos --- .../job-queue/handlers/activitypub-refresher.ts | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 server/lib/job-queue/handlers/activitypub-refresher.ts (limited to 'server/lib/job-queue/handlers/activitypub-refresher.ts') diff --git a/server/lib/job-queue/handlers/activitypub-refresher.ts b/server/lib/job-queue/handlers/activitypub-refresher.ts new file mode 100644 index 000000000..7752b3b40 --- /dev/null +++ b/server/lib/job-queue/handlers/activitypub-refresher.ts @@ -0,0 +1,40 @@ +import * as Bull from 'bull' +import { logger } from '../../../helpers/logger' +import { fetchVideoByUrl } from '../../../helpers/video' +import { refreshVideoIfNeeded } from '../../activitypub' + +export type RefreshPayload = { + videoUrl: string + type: 'video' +} + +async function refreshAPObject (job: Bull.Job) { + const payload = job.data as RefreshPayload + logger.info('Processing AP refresher in job %d.', job.id) + + if (payload.type === 'video') return refreshAPVideo(payload.videoUrl) +} + +// --------------------------------------------------------------------------- + +export { + refreshAPObject +} + +// --------------------------------------------------------------------------- + +async function refreshAPVideo (videoUrl: string) { + const fetchType = 'all' as 'all' + const syncParam = { likes: true, dislikes: true, shares: true, comments: true, thumbnail: true } + + const videoFromDatabase = await fetchVideoByUrl(videoUrl, fetchType) + if (videoFromDatabase) { + const refreshOptions = { + video: videoFromDatabase, + fetchedType: fetchType, + syncParam + } + + await refreshVideoIfNeeded(refreshOptions) + } +} -- cgit v1.2.3