1 import * as Bull from 'bull'
2 import { logger } from '../../../helpers/logger'
3 import { fetchVideoByUrl } from '../../../helpers/video'
4 import { refreshActorIfNeeded, refreshVideoIfNeeded, refreshVideoPlaylistIfNeeded } from '../../activitypub'
5 import { ActorModel } from '../../../models/activitypub/actor'
6 import { VideoPlaylistModel } from '../../../models/video/video-playlist'
8 export type RefreshPayload = {
9 type: 'video' | 'video-playlist' | 'actor'
13 async function refreshAPObject (job: Bull.Job) {
14 const payload = job.data as RefreshPayload
16 logger.info('Processing AP refresher in job %d for %s.', job.id, payload.url)
18 if (payload.type === 'video') return refreshVideo(payload.url)
19 if (payload.type === 'video-playlist') return refreshVideoPlaylist(payload.url)
20 if (payload.type === 'actor') return refreshActor(payload.url)
23 // ---------------------------------------------------------------------------
29 // ---------------------------------------------------------------------------
31 async function refreshVideo (videoUrl: string) {
32 const fetchType = 'all' as 'all'
33 const syncParam = { likes: true, dislikes: true, shares: true, comments: true, thumbnail: true }
35 const videoFromDatabase = await fetchVideoByUrl(videoUrl, fetchType)
36 if (videoFromDatabase) {
37 const refreshOptions = {
38 video: videoFromDatabase,
39 fetchedType: fetchType,
43 await refreshVideoIfNeeded(refreshOptions)
47 async function refreshActor (actorUrl: string) {
48 const fetchType = 'all' as 'all'
49 const actor = await ActorModel.loadByUrlAndPopulateAccountAndChannel(actorUrl)
52 await refreshActorIfNeeded(actor, fetchType)
56 async function refreshVideoPlaylist (playlistUrl: string) {
57 const playlist = await VideoPlaylistModel.loadByUrlAndPopulateAccount(playlistUrl)
60 await refreshVideoPlaylistIfNeeded(playlist)