diff options
-rw-r--r-- | server/lib/thumbnail.ts | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/server/lib/thumbnail.ts b/server/lib/thumbnail.ts index 06066f910..106f5fdaa 100644 --- a/server/lib/thumbnail.ts +++ b/server/lib/thumbnail.ts | |||
@@ -1,5 +1,4 @@ | |||
1 | import { join } from 'path' | 1 | import { join } from 'path' |
2 | |||
3 | import { ThumbnailType } from '../../shared/models/videos/thumbnail.type' | 2 | import { ThumbnailType } from '../../shared/models/videos/thumbnail.type' |
4 | import { generateImageFromVideoFile } from '../helpers/ffmpeg-utils' | 3 | import { generateImageFromVideoFile } from '../helpers/ffmpeg-utils' |
5 | import { processImage } from '../helpers/image-utils' | 4 | import { processImage } from '../helpers/image-utils' |
@@ -7,7 +6,7 @@ import { downloadImage } from '../helpers/requests' | |||
7 | import { CONFIG } from '../initializers/config' | 6 | import { CONFIG } from '../initializers/config' |
8 | import { ASSETS_PATH, PREVIEWS_SIZE, THUMBNAILS_SIZE } from '../initializers/constants' | 7 | import { ASSETS_PATH, PREVIEWS_SIZE, THUMBNAILS_SIZE } from '../initializers/constants' |
9 | import { ThumbnailModel } from '../models/video/thumbnail' | 8 | import { ThumbnailModel } from '../models/video/thumbnail' |
10 | import { MVideoFile, MVideoThumbnail } from '../types/models' | 9 | import { MVideoFile, MVideoThumbnail, MVideoUUID } from '../types/models' |
11 | import { MThumbnail } from '../types/models/video/thumbnail' | 10 | import { MThumbnail } from '../types/models/video/thumbnail' |
12 | import { MVideoPlaylistThumbnail } from '../types/models/video/video-playlist' | 11 | import { MVideoPlaylistThumbnail } from '../types/models/video/video-playlist' |
13 | import { getVideoFilePath } from './video-paths' | 12 | import { getVideoFilePath } from './video-paths' |
@@ -69,13 +68,7 @@ function createVideoMiniatureFromUrl (options: { | |||
69 | ? null | 68 | ? null |
70 | : downloadUrl | 69 | : downloadUrl |
71 | 70 | ||
72 | // If the thumbnail URL did not change | 71 | const thumbnailUrlChanged = hasThumbnailUrlChanged(existingThumbnail, downloadUrl, video) |
73 | const existingUrl = existingThumbnail | ||
74 | ? existingThumbnail.fileUrl | ||
75 | : null | ||
76 | |||
77 | // If the thumbnail URL did not change and has a unique filename (introduced in 3.1), avoid thumbnail processing | ||
78 | const thumbnailUrlChanged = !existingUrl || existingUrl !== downloadUrl || downloadUrl.endsWith(`${video.uuid}.jpg`) | ||
79 | 72 | ||
80 | // Do not change the thumbnail filename if the file did not change | 73 | // Do not change the thumbnail filename if the file did not change |
81 | const filename = thumbnailUrlChanged | 74 | const filename = thumbnailUrlChanged |
@@ -147,10 +140,17 @@ function createPlaceholderThumbnail (options: { | |||
147 | size: ImageSize | 140 | size: ImageSize |
148 | }) { | 141 | }) { |
149 | const { fileUrl, video, type, size } = options | 142 | const { fileUrl, video, type, size } = options |
150 | const { filename, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size) | 143 | const { filename: updatedFilename, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size) |
144 | |||
145 | const thumbnailUrlChanged = hasThumbnailUrlChanged(existingThumbnail, fileUrl, video) | ||
151 | 146 | ||
152 | const thumbnail = existingThumbnail || new ThumbnailModel() | 147 | const thumbnail = existingThumbnail || new ThumbnailModel() |
153 | 148 | ||
149 | // Do not change the thumbnail filename if the file did not change | ||
150 | const filename = thumbnailUrlChanged | ||
151 | ? updatedFilename | ||
152 | : existingThumbnail.filename | ||
153 | |||
154 | thumbnail.filename = filename | 154 | thumbnail.filename = filename |
155 | thumbnail.height = height | 155 | thumbnail.height = height |
156 | thumbnail.width = width | 156 | thumbnail.width = width |
@@ -171,6 +171,15 @@ export { | |||
171 | createPlaylistMiniatureFromExisting | 171 | createPlaylistMiniatureFromExisting |
172 | } | 172 | } |
173 | 173 | ||
174 | function hasThumbnailUrlChanged (existingThumbnail: MThumbnail, downloadUrl: string, video: MVideoUUID) { | ||
175 | const existingUrl = existingThumbnail | ||
176 | ? existingThumbnail.fileUrl | ||
177 | : null | ||
178 | |||
179 | // If the thumbnail URL did not change and has a unique filename (introduced in 3.1), avoid thumbnail processing | ||
180 | return !existingUrl || existingUrl !== downloadUrl || downloadUrl.endsWith(`${video.uuid}.jpg`) | ||
181 | } | ||
182 | |||
174 | function buildMetadataFromPlaylist (playlist: MVideoPlaylistThumbnail, size: ImageSize) { | 183 | function buildMetadataFromPlaylist (playlist: MVideoPlaylistThumbnail, size: ImageSize) { |
175 | const filename = playlist.generateThumbnailName() | 184 | const filename = playlist.generateThumbnailName() |
176 | const basePath = CONFIG.STORAGE.THUMBNAILS_DIR | 185 | const basePath = CONFIG.STORAGE.THUMBNAILS_DIR |