]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/job-queue/handlers/activitypub-refresher.ts
Cleanup
[github/Chocobozzz/PeerTube.git] / server / lib / job-queue / handlers / activitypub-refresher.ts
index 671b0f48743ebf35627541cd1735f6f45ea3bc8b..666e568684edbf3d3d80c17724c5adfa46949d8f 100644 (file)
@@ -1,19 +1,21 @@
 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'
-}
+import { refreshActorIfNeeded } from '../../activitypub/actor'
+import { refreshVideoIfNeeded } from '../../activitypub/videos'
+import { ActorModel } from '../../../models/activitypub/actor'
+import { VideoPlaylistModel } from '../../../models/video/video-playlist'
+import { RefreshPayload } from '@shared/models'
+import { refreshVideoPlaylistIfNeeded } from '@server/lib/activitypub/playlist'
 
 async function refreshAPObject (job: Bull.Job) {
   const payload = job.data as RefreshPayload
 
-  logger.info('Processing AP refresher in job %d for video %s.', job.id, payload.videoUrl)
+  logger.info('Processing AP refresher in job %d for %s.', job.id, payload.url)
 
-  if (payload.type === 'video') return refreshAPVideo(payload.videoUrl)
+  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)
 }
 
 // ---------------------------------------------------------------------------
@@ -24,7 +26,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 }
 
@@ -39,3 +41,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)
+  }
+}