1 import * as Bull from 'bull'
2 import { logger } from '../../../helpers/logger'
3 import { fetchVideoByUrl } from '../../../helpers/video'
4 import { refreshVideoIfNeeded, refreshActorIfNeeded } from '../../activitypub'
5 import { ActorModel } from '../../../models/activitypub/actor'
7 export type RefreshPayload = {
8 type: 'video' | 'actor'
12 async function refreshAPObject (job: Bull.Job) {
13 const payload = job.data as RefreshPayload
15 logger.info('Processing AP refresher in job %d for %s.', job.id, payload.url)
17 if (payload.type === 'video') return refreshVideo(payload.url)
18 if (payload.type === 'actor') return refreshActor(payload.url)
21 // ---------------------------------------------------------------------------
28 // ---------------------------------------------------------------------------
30 async function refreshVideo (videoUrl: string) {
31 const fetchType = 'all' as 'all'
32 const syncParam = { likes: true, dislikes: true, shares: true, comments: true, thumbnail: true }
34 const videoFromDatabase = await fetchVideoByUrl(videoUrl, fetchType)
35 if (videoFromDatabase) {
36 const refreshOptions = {
37 video: videoFromDatabase,
38 fetchedType: fetchType,
42 await refreshVideoIfNeeded(refreshOptions)
46 async function refreshActor (actorUrl: string) {
47 const fetchType = 'all' as 'all'
48 const actor = await ActorModel.loadByUrlAndPopulateAccountAndChannel(actorUrl)
51 await refreshActorIfNeeded(actor, fetchType)