2018-11-20 10:05:51 +01:00
|
|
|
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
|
2018-12-04 15:12:54 +01:00
|
|
|
|
|
|
|
logger.info('Processing AP refresher in job %d for video %s.', job.id, payload.videoUrl)
|
2018-11-20 10:05:51 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|