]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/playlists/refresh.ts
Merge branch 'release/3.3.0' into develop
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / playlists / refresh.ts
index ff9e5471a3d26af0b425ae1ccb713d1a6d993189..493e8c7ec7bd6abbf8120aa26bb5579c3face4e8 100644 (file)
@@ -1,15 +1,24 @@
 import { logger, loggerTagsFactory } from '@server/helpers/logger'
 import { PeerTubeRequestError } from '@server/helpers/requests'
-import { MVideoPlaylistOwner } from '@server/types/models'
-import { HttpStatusCode } from '@shared/core-utils'
+import { JobQueue } from '@server/lib/job-queue'
+import { MVideoPlaylist, MVideoPlaylistOwner } from '@server/types/models'
+import { HttpStatusCode } from '@shared/models'
 import { createOrUpdateVideoPlaylist } from './create-update'
 import { fetchRemoteVideoPlaylist } from './shared'
 
+function scheduleRefreshIfNeeded (playlist: MVideoPlaylist) {
+  if (!playlist.isOutdated()) return
+
+  JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video-playlist', url: playlist.url } })
+}
+
 async function refreshVideoPlaylistIfNeeded (videoPlaylist: MVideoPlaylistOwner): Promise<MVideoPlaylistOwner> {
   if (!videoPlaylist.isOutdated()) return videoPlaylist
 
   const lTags = loggerTagsFactory('ap', 'video-playlist', 'refresh', videoPlaylist.uuid, videoPlaylist.url)
 
+  logger.info('Refreshing playlist %s.', videoPlaylist.url, lTags())
+
   try {
     const { playlistObject } = await fetchRemoteVideoPlaylist(videoPlaylist.url)
 
@@ -20,8 +29,7 @@ async function refreshVideoPlaylistIfNeeded (videoPlaylist: MVideoPlaylistOwner)
       return videoPlaylist
     }
 
-    const byAccount = videoPlaylist.OwnerAccount
-    await createOrUpdateVideoPlaylist(playlistObject, byAccount, playlistObject.to)
+    await createOrUpdateVideoPlaylist(playlistObject)
 
     return videoPlaylist
   } catch (err) {
@@ -40,5 +48,6 @@ async function refreshVideoPlaylistIfNeeded (videoPlaylist: MVideoPlaylistOwner)
 }
 
 export {
+  scheduleRefreshIfNeeded,
   refreshVideoPlaylistIfNeeded
 }