2018-11-20 04:05:51 -05:00
|
|
|
import * as Bull from 'bull'
|
|
|
|
import { logger } from '../../../helpers/logger'
|
|
|
|
import { fetchVideoByUrl } from '../../../helpers/video'
|
2019-03-19 09:13:53 -04:00
|
|
|
import { refreshActorIfNeeded, refreshVideoIfNeeded, refreshVideoPlaylistIfNeeded } from '../../activitypub'
|
2019-01-14 05:30:15 -05:00
|
|
|
import { ActorModel } from '../../../models/activitypub/actor'
|
2019-03-19 09:13:53 -04:00
|
|
|
import { VideoPlaylistModel } from '../../../models/video/video-playlist'
|
2018-11-20 04:05:51 -05:00
|
|
|
|
|
|
|
export type RefreshPayload = {
|
2019-03-19 09:13:53 -04:00
|
|
|
type: 'video' | 'video-playlist' | 'actor'
|
2019-01-14 05:30:15 -05:00
|
|
|
url: string
|
2018-11-20 04:05:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
async function refreshAPObject (job: Bull.Job) {
|
|
|
|
const payload = job.data as RefreshPayload
|
2018-12-04 09:12:54 -05:00
|
|
|
|
2019-01-14 05:30:15 -05:00
|
|
|
logger.info('Processing AP refresher in job %d for %s.', job.id, payload.url)
|
2018-11-20 04:05:51 -05:00
|
|
|
|
2019-01-14 05:30:15 -05:00
|
|
|
if (payload.type === 'video') return refreshVideo(payload.url)
|
2019-03-19 09:13:53 -04:00
|
|
|
if (payload.type === 'video-playlist') return refreshVideoPlaylist(payload.url)
|
2019-01-14 05:30:15 -05:00
|
|
|
if (payload.type === 'actor') return refreshActor(payload.url)
|
2018-11-20 04:05:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
refreshAPObject
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2019-01-14 05:30:15 -05:00
|
|
|
async function refreshVideo (videoUrl: string) {
|
2018-11-20 04:05:51 -05:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
2019-01-14 05:30:15 -05:00
|
|
|
|
|
|
|
async function refreshActor (actorUrl: string) {
|
|
|
|
const fetchType = 'all' as 'all'
|
|
|
|
const actor = await ActorModel.loadByUrlAndPopulateAccountAndChannel(actorUrl)
|
|
|
|
|
|
|
|
if (actor) {
|
|
|
|
await refreshActorIfNeeded(actor, fetchType)
|
|
|
|
}
|
2019-03-19 09:13:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
async function refreshVideoPlaylist (playlistUrl: string) {
|
|
|
|
const playlist = await VideoPlaylistModel.loadByUrlAndPopulateAccount(playlistUrl)
|
2019-01-14 05:30:15 -05:00
|
|
|
|
2019-03-19 09:13:53 -04:00
|
|
|
if (playlist) {
|
|
|
|
await refreshVideoPlaylistIfNeeded(playlist)
|
|
|
|
}
|
2019-01-14 05:30:15 -05:00
|
|
|
}
|