diff options
Diffstat (limited to 'server/lib/thumbnail.ts')
-rw-r--r-- | server/lib/thumbnail.ts | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/server/lib/thumbnail.ts b/server/lib/thumbnail.ts index 4bad8d6ca..49317df28 100644 --- a/server/lib/thumbnail.ts +++ b/server/lib/thumbnail.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import { copy } from 'fs-extra' | 1 | import { copy } from 'fs-extra' |
2 | import { join } from 'path' | 2 | import { join } from 'path' |
3 | import { logger } from '@server/helpers/logger' | ||
3 | import { ThumbnailType } from '../../shared/models/videos/thumbnail.type' | 4 | import { ThumbnailType } from '../../shared/models/videos/thumbnail.type' |
4 | import { generateImageFromVideoFile } from '../helpers/ffmpeg-utils' | 5 | import { generateImageFromVideoFile } from '../helpers/ffmpeg-utils' |
5 | import { processImage } from '../helpers/image-utils' | 6 | import { processImage } from '../helpers/image-utils' |
@@ -62,7 +63,7 @@ function createVideoMiniatureFromUrl (options: { | |||
62 | size?: ImageSize | 63 | size?: ImageSize |
63 | }) { | 64 | }) { |
64 | const { downloadUrl, video, type, size } = options | 65 | const { downloadUrl, video, type, size } = options |
65 | const { filename, basePath, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size) | 66 | const { filename: updatedFilename, basePath, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size) |
66 | 67 | ||
67 | // Only save the file URL if it is a remote video | 68 | // Only save the file URL if it is a remote video |
68 | const fileUrl = video.isOwned() | 69 | const fileUrl = video.isOwned() |
@@ -76,10 +77,16 @@ function createVideoMiniatureFromUrl (options: { | |||
76 | 77 | ||
77 | // If the thumbnail URL did not change and has a unique filename (introduced in 3.2), avoid thumbnail processing | 78 | // If the thumbnail URL did not change and has a unique filename (introduced in 3.2), avoid thumbnail processing |
78 | const thumbnailUrlChanged = !existingUrl || existingUrl !== downloadUrl || downloadUrl.endsWith(`${video.uuid}.jpg`) | 79 | const thumbnailUrlChanged = !existingUrl || existingUrl !== downloadUrl || downloadUrl.endsWith(`${video.uuid}.jpg`) |
80 | |||
81 | // Do not change the thumbnail filename if the file did not change | ||
82 | const filename = thumbnailUrlChanged | ||
83 | ? updatedFilename | ||
84 | : existingThumbnail.filename | ||
85 | |||
79 | const thumbnailCreator = () => { | 86 | const thumbnailCreator = () => { |
80 | if (thumbnailUrlChanged) return downloadImage(downloadUrl, basePath, filename, { width, height }) | 87 | if (thumbnailUrlChanged) return downloadImage(downloadUrl, basePath, filename, { width, height }) |
81 | 88 | ||
82 | return copy(existingThumbnail.getPath(), ThumbnailModel.buildPath(type, filename)) | 89 | return Promise.resolve() |
83 | } | 90 | } |
84 | 91 | ||
85 | return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl }) | 92 | return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl }) |
@@ -236,7 +243,7 @@ async function createThumbnailFromFunction (parameters: { | |||
236 | fileUrl = null | 243 | fileUrl = null |
237 | } = parameters | 244 | } = parameters |
238 | 245 | ||
239 | const oldFilename = existingThumbnail | 246 | const oldFilename = existingThumbnail && existingThumbnail.filename !== filename |
240 | ? existingThumbnail.filename | 247 | ? existingThumbnail.filename |
241 | : undefined | 248 | : undefined |
242 | 249 | ||
@@ -248,7 +255,8 @@ async function createThumbnailFromFunction (parameters: { | |||
248 | thumbnail.type = type | 255 | thumbnail.type = type |
249 | thumbnail.fileUrl = fileUrl | 256 | thumbnail.fileUrl = fileUrl |
250 | thumbnail.automaticallyGenerated = automaticallyGenerated | 257 | thumbnail.automaticallyGenerated = automaticallyGenerated |
251 | thumbnail.previousThumbnailFilename = oldFilename | 258 | |
259 | if (oldFilename) thumbnail.previousThumbnailFilename = oldFilename | ||
252 | 260 | ||
253 | await thumbnailCreator() | 261 | await thumbnailCreator() |
254 | 262 | ||