1 import * as Bull from 'bull'
2 import { logger } from '../../../helpers/logger'
3 import { fetchVideoByUrl } from '../../../helpers/video'
4 import { refreshVideoIfNeeded } from '../../activitypub'
6 export type RefreshPayload = {
11 async function refreshAPObject (job: Bull.Job) {
12 const payload = job.data as RefreshPayload
13 logger.info('Processing AP refresher in job %d.', job.id)
15 if (payload.type === 'video') return refreshAPVideo(payload.videoUrl)
18 // ---------------------------------------------------------------------------
24 // ---------------------------------------------------------------------------
26 async function refreshAPVideo (videoUrl: string) {
27 const fetchType = 'all' as 'all'
28 const syncParam = { likes: true, dislikes: true, shares: true, comments: true, thumbnail: true }
30 const videoFromDatabase = await fetchVideoByUrl(videoUrl, fetchType)
31 if (videoFromDatabase) {
32 const refreshOptions = {
33 video: videoFromDatabase,
34 fetchedType: fetchType,
38 await refreshVideoIfNeeded(refreshOptions)