]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/thumbnail.ts
Translated using Weblate (German)
[github/Chocobozzz/PeerTube.git] / server / lib / thumbnail.ts
index 55478299c86c942e2e5562145b38328e1505b3ac..06066f9106cf7e0f5e764bb527a947d5a5e87b03 100644 (file)
@@ -62,14 +62,32 @@ function createVideoMiniatureFromUrl (options: {
   size?: ImageSize
 }) {
   const { downloadUrl, video, type, size } = options
-  const { filename, basePath, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size)
+  const { filename: updatedFilename, basePath, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size)
 
   // Only save the file URL if it is a remote video
   const fileUrl = video.isOwned()
     ? null
     : downloadUrl
 
-  const thumbnailCreator = () => downloadImage(downloadUrl, basePath, filename, { width, height })
+  // If the thumbnail URL did not change
+  const existingUrl = existingThumbnail
+    ? existingThumbnail.fileUrl
+    : null
+
+  // If the thumbnail URL did not change and has a unique filename (introduced in 3.1), avoid thumbnail processing
+  const thumbnailUrlChanged = !existingUrl || existingUrl !== downloadUrl || downloadUrl.endsWith(`${video.uuid}.jpg`)
+
+  // Do not change the thumbnail filename if the file did not change
+  const filename = thumbnailUrlChanged
+    ? updatedFilename
+    : existingThumbnail.filename
+
+  const thumbnailCreator = () => {
+    if (thumbnailUrlChanged) return downloadImage(downloadUrl, basePath, filename, { width, height })
+
+    return Promise.resolve()
+  }
+
   return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl })
 }
 
@@ -224,7 +242,7 @@ async function createThumbnailFromFunction (parameters: {
     fileUrl = null
   } = parameters
 
-  const oldFilename = existingThumbnail
+  const oldFilename = existingThumbnail && existingThumbnail.filename !== filename
     ? existingThumbnail.filename
     : undefined
 
@@ -236,7 +254,8 @@ async function createThumbnailFromFunction (parameters: {
   thumbnail.type = type
   thumbnail.fileUrl = fileUrl
   thumbnail.automaticallyGenerated = automaticallyGenerated
-  thumbnail.previousThumbnailFilename = oldFilename
+
+  if (oldFilename) thumbnail.previousThumbnailFilename = oldFilename
 
   await thumbnailCreator()