aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-02-16 09:42:22 +0100
committerChocobozzz <chocobozzz@cpy.re>2021-02-16 10:36:44 +0100
commit374b725df52d941af1cf37cf211593340c05206c (patch)
treeec5a7805ece31b3424ea2d8e08d204074baee02d /server/lib
parenta35a22797c99f17924347da9a226068c3dbe4787 (diff)
downloadPeerTube-374b725df52d941af1cf37cf211593340c05206c.tar.gz
PeerTube-374b725df52d941af1cf37cf211593340c05206c.tar.zst
PeerTube-374b725df52d941af1cf37cf211593340c05206c.zip
Optimize remote thumbnail processing
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/thumbnail.ts17
1 files changed, 15 insertions, 2 deletions
diff --git a/server/lib/thumbnail.ts b/server/lib/thumbnail.ts
index 55478299c..5d0c9f742 100644
--- a/server/lib/thumbnail.ts
+++ b/server/lib/thumbnail.ts
@@ -1,5 +1,6 @@
1import chaiJsonSchema = require('chai-json-schema')
2import { copy, move } from 'fs-extra'
1import { join } from 'path' 3import { join } from 'path'
2
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'
@@ -69,7 +70,19 @@ function createVideoMiniatureFromUrl (options: {
69 ? null 70 ? null
70 : downloadUrl 71 : downloadUrl
71 72
72 const thumbnailCreator = () => downloadImage(downloadUrl, basePath, filename, { width, height }) 73 // If the thumbnail URL did not change
74 const existingUrl = existingThumbnail
75 ? existingThumbnail.fileUrl
76 : null
77
78 // If the thumbnail URL did not change and has a unique filename (introduced in 3.2), avoid thumbnail processing
79 const thumbnailUrlChanged = !existingUrl || existingUrl !== downloadUrl || downloadUrl.endsWith(`${video.uuid}.jpg`)
80 const thumbnailCreator = () => {
81 if (thumbnailUrlChanged) return downloadImage(downloadUrl, basePath, filename, { width, height })
82
83 return copy(existingThumbnail.getPath(), ThumbnailModel.buildPath(type, filename))
84 }
85
73 return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl }) 86 return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl })
74} 87}
75 88