aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/thumbnail.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-02-18 10:15:11 +0100
committerChocobozzz <chocobozzz@cpy.re>2021-02-18 13:38:09 +0100
commitd9a2a03196275065c28f4a0b7d4d7bc9992d77a1 (patch)
tree14579db95cd07506bf3d8e5c0af3ef1630e8700c /server/lib/thumbnail.ts
parent2451916e45420fedf556913ce121f3964c4b57d6 (diff)
downloadPeerTube-d9a2a03196275065c28f4a0b7d4d7bc9992d77a1.tar.gz
PeerTube-d9a2a03196275065c28f4a0b7d4d7bc9992d77a1.tar.zst
PeerTube-d9a2a03196275065c28f4a0b7d4d7bc9992d77a1.zip
Don't guess remote tracker URL
Diffstat (limited to 'server/lib/thumbnail.ts')
-rw-r--r--server/lib/thumbnail.ts16
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 @@
1import { copy } from 'fs-extra' 1import { copy } from 'fs-extra'
2import { join } from 'path' 2import { join } from 'path'
3import { logger } from '@server/helpers/logger'
3import { ThumbnailType } from '../../shared/models/videos/thumbnail.type' 4import { ThumbnailType } from '../../shared/models/videos/thumbnail.type'
4import { generateImageFromVideoFile } from '../helpers/ffmpeg-utils' 5import { generateImageFromVideoFile } from '../helpers/ffmpeg-utils'
5import { processImage } from '../helpers/image-utils' 6import { 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