]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/videos/refresh.ts
Merge branch 'release/4.3.0' into develop
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / videos / refresh.ts
index 205a3ccb1226e60d96f03f9353d6e20f109bcd9c..9f952a2182770dbb053b9cb7934f6e3c197f8dda 100644 (file)
@@ -1,16 +1,16 @@
-import { logger } from '@server/helpers/logger'
+import { logger, loggerTagsFactory } from '@server/helpers/logger'
 import { PeerTubeRequestError } from '@server/helpers/requests'
-import { VideoFetchByUrlType } from '@server/helpers/video'
-import { ActorFollowScoreCache } from '@server/lib/files-cache'
+import { VideoLoadByUrlType } from '@server/lib/model-loaders'
 import { VideoModel } from '@server/models/video/video'
 import { MVideoAccountLightBlacklistAllFiles, MVideoThumbnail } from '@server/types/models'
-import { HttpStatusCode } from '@shared/core-utils'
+import { HttpStatusCode } from '@shared/models'
+import { ActorFollowHealthCache } from '../../actor-follow-health-cache'
 import { fetchRemoteVideo, SyncParam, syncVideoExternalAttributes } from './shared'
 import { APVideoUpdater } from './updater'
 
 async function refreshVideoIfNeeded (options: {
   video: MVideoThumbnail
-  fetchedType: VideoFetchByUrlType
+  fetchedType: VideoLoadByUrlType
   syncParam: SyncParam
 }): Promise<MVideoThumbnail> {
   if (!options.video.isOutdated()) return options.video
@@ -20,11 +20,15 @@ async function refreshVideoIfNeeded (options: {
     ? options.video as MVideoAccountLightBlacklistAllFiles
     : await VideoModel.loadByUrlAndPopulateAccount(options.video.url)
 
+  const lTags = loggerTagsFactory('ap', 'video', 'refresh', video.uuid, video.url)
+
+  logger.info('Refreshing video %s.', video.url, lTags())
+
   try {
     const { videoObject } = await fetchRemoteVideo(video.url)
 
     if (videoObject === undefined) {
-      logger.warn('Cannot refresh remote video %s: invalid body.', video.url)
+      logger.warn('Cannot refresh remote video %s: invalid body.', video.url, lTags())
 
       await video.setAsRefreshed()
       return video
@@ -35,21 +39,21 @@ async function refreshVideoIfNeeded (options: {
 
     await syncVideoExternalAttributes(video, videoObject, options.syncParam)
 
-    ActorFollowScoreCache.Instance.addGoodServerId(video.VideoChannel.Actor.serverId)
+    ActorFollowHealthCache.Instance.addGoodServerId(video.VideoChannel.Actor.serverId)
 
     return video
   } catch (err) {
     if ((err as PeerTubeRequestError).statusCode === HttpStatusCode.NOT_FOUND_404) {
-      logger.info('Cannot refresh remote video %s: video does not exist anymore. Deleting it.', video.url)
+      logger.info('Cannot refresh remote video %s: video does not exist anymore. Deleting it.', video.url, lTags())
 
       // Video does not exist anymore
       await video.destroy()
       return undefined
     }
 
-    logger.warn('Cannot refresh video %s.', options.video.url, { err })
+    logger.warn('Cannot refresh video %s.', options.video.url, { err, ...lTags() })
 
-    ActorFollowScoreCache.Instance.addBadServerId(video.VideoChannel.Actor.serverId)
+    ActorFollowHealthCache.Instance.addBadServerId(video.VideoChannel.Actor.serverId)
 
     // Don't refresh in loop
     await video.setAsRefreshed()