diff options
Diffstat (limited to 'server/helpers/image-utils.ts')
-rw-r--r-- | server/helpers/image-utils.ts | 25 |
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 | ||
15 | async function processImage ( | 15 | async 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 | ||
39 | async function generateImageFromVideoFile (fromPath: string, folder: string, imageName: string, size: { width: number, height: number }) { | 41 | async 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 | ||