aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/image-utils.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-06-27 11:53:12 +0200
committerChocobozzz <me@florianbigard.com>2022-06-27 11:53:12 +0200
commit3a54605d4e7ec5b4f47131e8d23255be35b7beac (patch)
treefce9d34812a7638d4a0253b076f05aabd15a2ce9 /server/helpers/image-utils.ts
parent88edc66edadcab1b0372679e23bf2a7a6ff50131 (diff)
downloadPeerTube-3a54605d4e7ec5b4f47131e8d23255be35b7beac.tar.gz
PeerTube-3a54605d4e7ec5b4f47131e8d23255be35b7beac.tar.zst
PeerTube-3a54605d4e7ec5b4f47131e8d23255be35b7beac.zip
Process images in a dedicated worker
Diffstat (limited to 'server/helpers/image-utils.ts')
-rw-r--r--server/helpers/image-utils.ts25
1 files changed, 17 insertions, 8 deletions
diff --git a/server/helpers/image-utils.ts b/server/helpers/image-utils.ts
index ebb102a0d..bbd4692ef 100644
--- a/server/helpers/image-utils.ts
+++ b/server/helpers/image-utils.ts
@@ -12,12 +12,14 @@ function generateImageFilename (extension = '.jpg') {
12 return buildUUID() + extension 12 return buildUUID() + extension
13} 13}
14 14
15async function processImage ( 15async function processImage (options: {
16 path: string, 16 path: string
17 destination: string, 17 destination: string
18 newSize: { width: number, height: number }, 18 newSize: { width: number, height: number }
19 keepOriginal = false 19 keepOriginal?: boolean // default false
20) { 20}) {
21 const { path, destination, newSize, keepOriginal = false } = options
22
21 const extension = getLowercaseExtension(path) 23 const extension = getLowercaseExtension(path)
22 24
23 if (path === destination) { 25 if (path === destination) {
@@ -36,7 +38,14 @@ async function processImage (
36 if (keepOriginal !== true) await remove(path) 38 if (keepOriginal !== true) await remove(path)
37} 39}
38 40
39async function generateImageFromVideoFile (fromPath: string, folder: string, imageName: string, size: { width: number, height: number }) { 41async function generateImageFromVideoFile (options: {
42 fromPath: string
43 folder: string
44 imageName: string
45 size: { width: number, height: number }
46}) {
47 const { fromPath, folder, imageName, size } = options
48
40 const pendingImageName = 'pending-' + imageName 49 const pendingImageName = 'pending-' + imageName
41 const pendingImagePath = join(folder, pendingImageName) 50 const pendingImagePath = join(folder, pendingImageName)
42 51
@@ -44,7 +53,7 @@ async function generateImageFromVideoFile (fromPath: string, folder: string, ima
44 await generateThumbnailFromVideo(fromPath, folder, imageName) 53 await generateThumbnailFromVideo(fromPath, folder, imageName)
45 54
46 const destination = join(folder, imageName) 55 const destination = join(folder, imageName)
47 await processImage(pendingImagePath, destination, size) 56 await processImage({ path: pendingImagePath, destination, newSize: size })
48 } catch (err) { 57 } catch (err) {
49 logger.error('Cannot generate image from video %s.', fromPath, { err, ...lTags() }) 58 logger.error('Cannot generate image from video %s.', fromPath, { err, ...lTags() })
50 59