aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/thumbnail.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/thumbnail.ts')
-rw-r--r--server/lib/thumbnail.ts38
1 files changed, 30 insertions, 8 deletions
diff --git a/server/lib/thumbnail.ts b/server/lib/thumbnail.ts
index aa2d7a813..02b867a91 100644
--- a/server/lib/thumbnail.ts
+++ b/server/lib/thumbnail.ts
@@ -1,14 +1,15 @@
1import { join } from 'path' 1import { join } from 'path'
2import { ThumbnailType } from '@shared/models' 2import { ThumbnailType } from '@shared/models'
3import { generateImageFilename, generateImageFromVideoFile, processImage } from '../helpers/image-utils' 3import { generateImageFilename, generateImageFromVideoFile } from '../helpers/image-utils'
4import { downloadImage } from '../helpers/requests'
5import { CONFIG } from '../initializers/config' 4import { CONFIG } from '../initializers/config'
6import { ASSETS_PATH, PREVIEWS_SIZE, THUMBNAILS_SIZE } from '../initializers/constants' 5import { ASSETS_PATH, PREVIEWS_SIZE, THUMBNAILS_SIZE } from '../initializers/constants'
7import { ThumbnailModel } from '../models/video/thumbnail' 6import { ThumbnailModel } from '../models/video/thumbnail'
8import { MVideoFile, MVideoThumbnail, MVideoUUID } from '../types/models' 7import { MVideoFile, MVideoThumbnail, MVideoUUID } from '../types/models'
9import { MThumbnail } from '../types/models/video/thumbnail' 8import { MThumbnail } from '../types/models/video/thumbnail'
10import { MVideoPlaylistThumbnail } from '../types/models/video/video-playlist' 9import { MVideoPlaylistThumbnail } from '../types/models/video/video-playlist'
10import { downloadImageFromWorker } from './local-actor'
11import { VideoPathManager } from './video-path-manager' 11import { VideoPathManager } from './video-path-manager'
12import { processImageFromWorker } from './worker/parent-process'
12 13
13type ImageSize = { height?: number, width?: number } 14type ImageSize = { height?: number, width?: number }
14 15
@@ -23,7 +24,10 @@ function updatePlaylistMiniatureFromExisting (options: {
23 const { filename, outputPath, height, width, existingThumbnail } = buildMetadataFromPlaylist(playlist, size) 24 const { filename, outputPath, height, width, existingThumbnail } = buildMetadataFromPlaylist(playlist, size)
24 const type = ThumbnailType.MINIATURE 25 const type = ThumbnailType.MINIATURE
25 26
26 const thumbnailCreator = () => processImage(inputPath, outputPath, { width, height }, keepOriginal) 27 const thumbnailCreator = () => {
28 return processImageFromWorker({ path: inputPath, destination: outputPath, newSize: { width, height }, keepOriginal })
29 }
30
27 return updateThumbnailFromFunction({ 31 return updateThumbnailFromFunction({
28 thumbnailCreator, 32 thumbnailCreator,
29 filename, 33 filename,
@@ -49,7 +53,10 @@ function updatePlaylistMiniatureFromUrl (options: {
49 ? null 53 ? null
50 : downloadUrl 54 : downloadUrl
51 55
52 const thumbnailCreator = () => downloadImage(downloadUrl, basePath, filename, { width, height }) 56 const thumbnailCreator = () => {
57 return downloadImageFromWorker({ url: downloadUrl, destDir: basePath, destName: filename, size: { width, height } })
58 }
59
53 return updateThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl }) 60 return updateThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl })
54} 61}
55 62
@@ -75,7 +82,9 @@ function updateVideoMiniatureFromUrl (options: {
75 : existingThumbnail.filename 82 : existingThumbnail.filename
76 83
77 const thumbnailCreator = () => { 84 const thumbnailCreator = () => {
78 if (thumbnailUrlChanged) return downloadImage(downloadUrl, basePath, filename, { width, height }) 85 if (thumbnailUrlChanged) {
86 return downloadImageFromWorker({ url: downloadUrl, destDir: basePath, destName: filename, size: { width, height } })
87 }
79 88
80 return Promise.resolve() 89 return Promise.resolve()
81 } 90 }
@@ -94,7 +103,10 @@ function updateVideoMiniatureFromExisting (options: {
94 const { inputPath, video, type, automaticallyGenerated, size, keepOriginal = false } = options 103 const { inputPath, video, type, automaticallyGenerated, size, keepOriginal = false } = options
95 104
96 const { filename, outputPath, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size) 105 const { filename, outputPath, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size)
97 const thumbnailCreator = () => processImage(inputPath, outputPath, { width, height }, keepOriginal) 106
107 const thumbnailCreator = () => {
108 return processImageFromWorker({ path: inputPath, destination: outputPath, newSize: { width, height }, keepOriginal })
109 }
98 110
99 return updateThumbnailFromFunction({ 111 return updateThumbnailFromFunction({
100 thumbnailCreator, 112 thumbnailCreator,
@@ -118,8 +130,18 @@ function generateVideoMiniature (options: {
118 const { filename, basePath, height, width, existingThumbnail, outputPath } = buildMetadataFromVideo(video, type) 130 const { filename, basePath, height, width, existingThumbnail, outputPath } = buildMetadataFromVideo(video, type)
119 131
120 const thumbnailCreator = videoFile.isAudio() 132 const thumbnailCreator = videoFile.isAudio()
121 ? () => processImage(ASSETS_PATH.DEFAULT_AUDIO_BACKGROUND, outputPath, { width, height }, true) 133 ? () => processImageFromWorker({
122 : () => generateImageFromVideoFile(input, basePath, filename, { height, width }) 134 path: ASSETS_PATH.DEFAULT_AUDIO_BACKGROUND,
135 destination: outputPath,
136 newSize: { width, height },
137 keepOriginal: true
138 })
139 : () => generateImageFromVideoFile({
140 fromPath: input,
141 folder: basePath,
142 imageName: filename,
143 size: { height, width }
144 })
123 145
124 return updateThumbnailFromFunction({ 146 return updateThumbnailFromFunction({
125 thumbnailCreator, 147 thumbnailCreator,