]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/job-queue/handlers/activitypub-refresher.ts
Merge branch 'release/4.0.0' into develop
[github/Chocobozzz/PeerTube.git] / server / lib / job-queue / handlers / activitypub-refresher.ts
index 7752b3b4002d962dd55cb51ef47f9cac48fb33e0..5037992d2271f5091789942c06eaec8520fe2e4b 100644 (file)
@@ -1,18 +1,21 @@
-import * as Bull from 'bull'
+import { Job } from 'bull'
+import { refreshVideoPlaylistIfNeeded } from '@server/lib/activitypub/playlists'
+import { refreshVideoIfNeeded } from '@server/lib/activitypub/videos'
+import { loadVideoByUrl } from '@server/lib/model-loaders'
+import { RefreshPayload } from '@shared/models'
 import { logger } from '../../../helpers/logger'
-import { fetchVideoByUrl } from '../../../helpers/video'
-import { refreshVideoIfNeeded } from '../../activitypub'
+import { ActorModel } from '../../../models/actor/actor'
+import { VideoPlaylistModel } from '../../../models/video/video-playlist'
+import { refreshActorIfNeeded } from '../../activitypub/actors'
 
-export type RefreshPayload = {
-  videoUrl: string
-  type: 'video'
-}
-
-async function refreshAPObject (job: Bull.Job) {
+async function refreshAPObject (job: 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,11 +26,11 @@ 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 }
 
-  const videoFromDatabase = await fetchVideoByUrl(videoUrl, fetchType)
+  const videoFromDatabase = await loadVideoByUrl(videoUrl, fetchType)
   if (videoFromDatabase) {
     const refreshOptions = {
       video: videoFromDatabase,
@@ -38,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, fetchedType: fetchType })
+  }
+}
+
+async function refreshVideoPlaylist (playlistUrl: string) {
+  const playlist = await VideoPlaylistModel.loadByUrlAndPopulateAccount(playlistUrl)
+
+  if (playlist) {
+    await refreshVideoPlaylistIfNeeded(playlist)
+  }
+}