diff options
author | Chocobozzz <me@florianbigard.com> | 2021-02-16 09:42:22 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2021-02-16 10:36:44 +0100 |
commit | 374b725df52d941af1cf37cf211593340c05206c (patch) | |
tree | ec5a7805ece31b3424ea2d8e08d204074baee02d /server/lib/thumbnail.ts | |
parent | a35a22797c99f17924347da9a226068c3dbe4787 (diff) | |
download | PeerTube-374b725df52d941af1cf37cf211593340c05206c.tar.gz PeerTube-374b725df52d941af1cf37cf211593340c05206c.tar.zst PeerTube-374b725df52d941af1cf37cf211593340c05206c.zip |
Optimize remote thumbnail processing
Diffstat (limited to 'server/lib/thumbnail.ts')
-rw-r--r-- | server/lib/thumbnail.ts | 17 |
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 @@ | |||
1 | import chaiJsonSchema = require('chai-json-schema') | ||
2 | import { copy, move } from 'fs-extra' | ||
1 | import { join } from 'path' | 3 | import { join } from 'path' |
2 | |||
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' |
@@ -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 | ||