aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-03-03 11:02:34 +0100
committerChocobozzz <me@florianbigard.com>2021-03-03 11:02:34 +0100
commit1ef447bd8397792dc7d1db93dfe87749f0532c72 (patch)
tree69b3c390b52802313510d8064d494fc5c04fe92b
parentcd2c3dcdc4a626a8a185b359cc40b53c8e8e0e7e (diff)
downloadPeerTube-1ef447bd8397792dc7d1db93dfe87749f0532c72.tar.gz
PeerTube-1ef447bd8397792dc7d1db93dfe87749f0532c72.tar.zst
PeerTube-1ef447bd8397792dc7d1db93dfe87749f0532c72.zip
Don't create another uneeded preview placeholder
-rw-r--r--server/lib/thumbnail.ts29
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 @@
1import { join } from 'path' 1import { join } from 'path'
2
3import { ThumbnailType } from '../../shared/models/videos/thumbnail.type' 2import { ThumbnailType } from '../../shared/models/videos/thumbnail.type'
4import { generateImageFromVideoFile } from '../helpers/ffmpeg-utils' 3import { generateImageFromVideoFile } from '../helpers/ffmpeg-utils'
5import { processImage } from '../helpers/image-utils' 4import { processImage } from '../helpers/image-utils'
@@ -7,7 +6,7 @@ import { downloadImage } from '../helpers/requests'
7import { CONFIG } from '../initializers/config' 6import { CONFIG } from '../initializers/config'
8import { ASSETS_PATH, PREVIEWS_SIZE, THUMBNAILS_SIZE } from '../initializers/constants' 7import { ASSETS_PATH, PREVIEWS_SIZE, THUMBNAILS_SIZE } from '../initializers/constants'
9import { ThumbnailModel } from '../models/video/thumbnail' 8import { ThumbnailModel } from '../models/video/thumbnail'
10import { MVideoFile, MVideoThumbnail } from '../types/models' 9import { MVideoFile, MVideoThumbnail, MVideoUUID } from '../types/models'
11import { MThumbnail } from '../types/models/video/thumbnail' 10import { MThumbnail } from '../types/models/video/thumbnail'
12import { MVideoPlaylistThumbnail } from '../types/models/video/video-playlist' 11import { MVideoPlaylistThumbnail } from '../types/models/video/video-playlist'
13import { getVideoFilePath } from './video-paths' 12import { 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
174function 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
174function buildMetadataFromPlaylist (playlist: MVideoPlaylistThumbnail, size: ImageSize) { 183function 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