X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fjob-queue%2Fhandlers%2Factivitypub-refresher.ts;h=4d6c38cfa0136ee122af6dc839c49fb6e4861362;hb=a3b7421abb4192e215aa280418b62e96958c5e42;hp=7752b3b4002d962dd55cb51ef47f9cac48fb33e0;hpb=04b8c3fba614efc3827f583096c78b08cb668470;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/job-queue/handlers/activitypub-refresher.ts b/server/lib/job-queue/handlers/activitypub-refresher.ts index 7752b3b40..4d6c38cfa 100644 --- a/server/lib/job-queue/handlers/activitypub-refresher.ts +++ b/server/lib/job-queue/handlers/activitypub-refresher.ts @@ -1,18 +1,23 @@ import * as Bull from 'bull' import { logger } from '../../../helpers/logger' import { fetchVideoByUrl } from '../../../helpers/video' -import { refreshVideoIfNeeded } from '../../activitypub' +import { refreshActorIfNeeded, refreshVideoIfNeeded, refreshVideoPlaylistIfNeeded } from '../../activitypub' +import { ActorModel } from '../../../models/activitypub/actor' +import { VideoPlaylistModel } from '../../../models/video/video-playlist' export type RefreshPayload = { - videoUrl: string - type: 'video' + type: 'video' | 'video-playlist' | 'actor' + url: string } async function refreshAPObject (job: Bull.Job) { const payload = job.data as RefreshPayload - logger.info('Processing AP refresher in job %d.', job.id) - if (payload.type === 'video') return refreshAPVideo(payload.videoUrl) + logger.info('Processing AP refresher in job %d for %s.', job.id, payload.url) + + if (payload.type === 'video') return refreshVideo(payload.url) + if (payload.type === 'video-playlist') return refreshVideoPlaylist(payload.url) + if (payload.type === 'actor') return refreshActor(payload.url) } // --------------------------------------------------------------------------- @@ -23,7 +28,7 @@ export { // --------------------------------------------------------------------------- -async function refreshAPVideo (videoUrl: string) { +async function refreshVideo (videoUrl: string) { const fetchType = 'all' as 'all' const syncParam = { likes: true, dislikes: true, shares: true, comments: true, thumbnail: true } @@ -38,3 +43,20 @@ async function refreshAPVideo (videoUrl: string) { await refreshVideoIfNeeded(refreshOptions) } } + +async function refreshActor (actorUrl: string) { + const fetchType = 'all' as 'all' + const actor = await ActorModel.loadByUrlAndPopulateAccountAndChannel(actorUrl) + + if (actor) { + await refreshActorIfNeeded(actor, fetchType) + } +} + +async function refreshVideoPlaylist (playlistUrl: string) { + const playlist = await VideoPlaylistModel.loadByUrlAndPopulateAccount(playlistUrl) + + if (playlist) { + await refreshVideoPlaylistIfNeeded(playlist) + } +}