2021-08-27 07:32:44 -05:00
|
|
|
import { Job } from 'bull'
|
2021-06-03 07:30:09 -05:00
|
|
|
import { refreshVideoPlaylistIfNeeded } from '@server/lib/activitypub/playlists'
|
2021-06-02 02:35:01 -05:00
|
|
|
import { refreshVideoIfNeeded } from '@server/lib/activitypub/videos'
|
2021-06-03 11:10:56 -05:00
|
|
|
import { loadVideoByUrl } from '@server/lib/model-loaders'
|
2021-05-11 04:15:29 -05:00
|
|
|
import { RefreshPayload } from '@shared/models'
|
2018-11-20 03:05:51 -06:00
|
|
|
import { logger } from '../../../helpers/logger'
|
2021-05-11 04:15:29 -05:00
|
|
|
import { ActorModel } from '../../../models/actor/actor'
|
|
|
|
import { VideoPlaylistModel } from '../../../models/video/video-playlist'
|
2021-06-03 09:02:29 -05:00
|
|
|
import { refreshActorIfNeeded } from '../../activitypub/actors'
|
2018-11-20 03:05:51 -06:00
|
|
|
|
2021-08-27 07:32:44 -05:00
|
|
|
async function refreshAPObject (job: Job) {
|
2018-11-20 03:05:51 -06:00
|
|
|
const payload = job.data as RefreshPayload
|
2018-12-04 08:12:54 -06:00
|
|
|
|
2019-01-14 04:30:15 -06:00
|
|
|
logger.info('Processing AP refresher in job %d for %s.', job.id, payload.url)
|
2018-11-20 03:05:51 -06:00
|
|
|
|
2019-01-14 04:30:15 -06:00
|
|
|
if (payload.type === 'video') return refreshVideo(payload.url)
|
2019-03-19 08:13:53 -05:00
|
|
|
if (payload.type === 'video-playlist') return refreshVideoPlaylist(payload.url)
|
2019-01-14 04:30:15 -06:00
|
|
|
if (payload.type === 'actor') return refreshActor(payload.url)
|
2018-11-20 03:05:51 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
refreshAPObject
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2019-01-14 04:30:15 -06:00
|
|
|
async function refreshVideo (videoUrl: string) {
|
2018-11-20 03:05:51 -06:00
|
|
|
const fetchType = 'all' as 'all'
|
2022-03-18 05:17:35 -05:00
|
|
|
const syncParam = { rates: true, shares: true, comments: true, thumbnail: true }
|
2018-11-20 03:05:51 -06:00
|
|
|
|
2021-06-03 11:10:56 -05:00
|
|
|
const videoFromDatabase = await loadVideoByUrl(videoUrl, fetchType)
|
2018-11-20 03:05:51 -06:00
|
|
|
if (videoFromDatabase) {
|
|
|
|
const refreshOptions = {
|
|
|
|
video: videoFromDatabase,
|
|
|
|
fetchedType: fetchType,
|
|
|
|
syncParam
|
|
|
|
}
|
|
|
|
|
|
|
|
await refreshVideoIfNeeded(refreshOptions)
|
|
|
|
}
|
|
|
|
}
|
2019-01-14 04:30:15 -06:00
|
|
|
|
|
|
|
async function refreshActor (actorUrl: string) {
|
|
|
|
const fetchType = 'all' as 'all'
|
|
|
|
const actor = await ActorModel.loadByUrlAndPopulateAccountAndChannel(actorUrl)
|
|
|
|
|
|
|
|
if (actor) {
|
2021-06-09 06:34:40 -05:00
|
|
|
await refreshActorIfNeeded({ actor, fetchedType: fetchType })
|
2019-01-14 04:30:15 -06:00
|
|
|
}
|
2019-03-19 08:13:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
async function refreshVideoPlaylist (playlistUrl: string) {
|
|
|
|
const playlist = await VideoPlaylistModel.loadByUrlAndPopulateAccount(playlistUrl)
|
2019-01-14 04:30:15 -06:00
|
|
|
|
2019-03-19 08:13:53 -05:00
|
|
|
if (playlist) {
|
|
|
|
await refreshVideoPlaylistIfNeeded(playlist)
|
|
|
|
}
|
2019-01-14 04:30:15 -06:00
|
|
|
}
|