diff options
Diffstat (limited to 'server/lib/thumbnail.ts')
-rw-r--r-- | server/lib/thumbnail.ts | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/server/lib/thumbnail.ts b/server/lib/thumbnail.ts index 02b867a91..e792567ff 100644 --- a/server/lib/thumbnail.ts +++ b/server/lib/thumbnail.ts | |||
@@ -7,13 +7,12 @@ import { ThumbnailModel } from '../models/video/thumbnail' | |||
7 | import { MVideoFile, MVideoThumbnail, MVideoUUID } from '../types/models' | 7 | import { MVideoFile, MVideoThumbnail, MVideoUUID } from '../types/models' |
8 | import { MThumbnail } from '../types/models/video/thumbnail' | 8 | import { MThumbnail } from '../types/models/video/thumbnail' |
9 | import { MVideoPlaylistThumbnail } from '../types/models/video/video-playlist' | 9 | import { MVideoPlaylistThumbnail } from '../types/models/video/video-playlist' |
10 | import { downloadImageFromWorker } from './local-actor' | ||
11 | import { VideoPathManager } from './video-path-manager' | 10 | import { VideoPathManager } from './video-path-manager' |
12 | import { processImageFromWorker } from './worker/parent-process' | 11 | import { downloadImageFromWorker, processImageFromWorker } from './worker/parent-process' |
13 | 12 | ||
14 | type ImageSize = { height?: number, width?: number } | 13 | type ImageSize = { height?: number, width?: number } |
15 | 14 | ||
16 | function updatePlaylistMiniatureFromExisting (options: { | 15 | function updateLocalPlaylistMiniatureFromExisting (options: { |
17 | inputPath: string | 16 | inputPath: string |
18 | playlist: MVideoPlaylistThumbnail | 17 | playlist: MVideoPlaylistThumbnail |
19 | automaticallyGenerated: boolean | 18 | automaticallyGenerated: boolean |
@@ -35,6 +34,7 @@ function updatePlaylistMiniatureFromExisting (options: { | |||
35 | width, | 34 | width, |
36 | type, | 35 | type, |
37 | automaticallyGenerated, | 36 | automaticallyGenerated, |
37 | onDisk: true, | ||
38 | existingThumbnail | 38 | existingThumbnail |
39 | }) | 39 | }) |
40 | } | 40 | } |
@@ -57,7 +57,7 @@ function updatePlaylistMiniatureFromUrl (options: { | |||
57 | return downloadImageFromWorker({ url: downloadUrl, destDir: basePath, destName: filename, size: { width, height } }) | 57 | return downloadImageFromWorker({ url: downloadUrl, destDir: basePath, destName: filename, size: { width, height } }) |
58 | } | 58 | } |
59 | 59 | ||
60 | return updateThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl }) | 60 | return updateThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl, onDisk: true }) |
61 | } | 61 | } |
62 | 62 | ||
63 | function updateVideoMiniatureFromUrl (options: { | 63 | function updateVideoMiniatureFromUrl (options: { |
@@ -89,10 +89,10 @@ function updateVideoMiniatureFromUrl (options: { | |||
89 | return Promise.resolve() | 89 | return Promise.resolve() |
90 | } | 90 | } |
91 | 91 | ||
92 | return updateThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl }) | 92 | return updateThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl, onDisk: true }) |
93 | } | 93 | } |
94 | 94 | ||
95 | function updateVideoMiniatureFromExisting (options: { | 95 | function updateLocalVideoMiniatureFromExisting (options: { |
96 | inputPath: string | 96 | inputPath: string |
97 | video: MVideoThumbnail | 97 | video: MVideoThumbnail |
98 | type: ThumbnailType | 98 | type: ThumbnailType |
@@ -115,11 +115,12 @@ function updateVideoMiniatureFromExisting (options: { | |||
115 | width, | 115 | width, |
116 | type, | 116 | type, |
117 | automaticallyGenerated, | 117 | automaticallyGenerated, |
118 | existingThumbnail | 118 | existingThumbnail, |
119 | onDisk: true | ||
119 | }) | 120 | }) |
120 | } | 121 | } |
121 | 122 | ||
122 | function generateVideoMiniature (options: { | 123 | function generateLocalVideoMiniature (options: { |
123 | video: MVideoThumbnail | 124 | video: MVideoThumbnail |
124 | videoFile: MVideoFile | 125 | videoFile: MVideoFile |
125 | type: ThumbnailType | 126 | type: ThumbnailType |
@@ -150,34 +151,36 @@ function generateVideoMiniature (options: { | |||
150 | width, | 151 | width, |
151 | type, | 152 | type, |
152 | automaticallyGenerated: true, | 153 | automaticallyGenerated: true, |
154 | onDisk: true, | ||
153 | existingThumbnail | 155 | existingThumbnail |
154 | }) | 156 | }) |
155 | }) | 157 | }) |
156 | } | 158 | } |
157 | 159 | ||
158 | function updatePlaceholderThumbnail (options: { | 160 | function updateRemoteThumbnail (options: { |
159 | fileUrl: string | 161 | fileUrl: string |
160 | video: MVideoThumbnail | 162 | video: MVideoThumbnail |
161 | type: ThumbnailType | 163 | type: ThumbnailType |
162 | size: ImageSize | 164 | size: ImageSize |
165 | onDisk: boolean | ||
163 | }) { | 166 | }) { |
164 | const { fileUrl, video, type, size } = options | 167 | const { fileUrl, video, type, size, onDisk } = options |
165 | const { filename: updatedFilename, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size) | 168 | const { filename: generatedFilename, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size) |
166 | 169 | ||
167 | const thumbnailUrlChanged = hasThumbnailUrlChanged(existingThumbnail, fileUrl, video) | 170 | const thumbnailUrlChanged = hasThumbnailUrlChanged(existingThumbnail, fileUrl, video) |
168 | 171 | ||
169 | const thumbnail = existingThumbnail || new ThumbnailModel() | 172 | const thumbnail = existingThumbnail || new ThumbnailModel() |
170 | 173 | ||
171 | // Do not change the thumbnail filename if the file did not change | 174 | // Do not change the thumbnail filename if the file did not change |
172 | const filename = thumbnailUrlChanged | 175 | if (thumbnailUrlChanged) { |
173 | ? updatedFilename | 176 | thumbnail.filename = generatedFilename |
174 | : existingThumbnail.filename | 177 | } |
175 | 178 | ||
176 | thumbnail.filename = filename | ||
177 | thumbnail.height = height | 179 | thumbnail.height = height |
178 | thumbnail.width = width | 180 | thumbnail.width = width |
179 | thumbnail.type = type | 181 | thumbnail.type = type |
180 | thumbnail.fileUrl = fileUrl | 182 | thumbnail.fileUrl = fileUrl |
183 | thumbnail.onDisk = onDisk | ||
181 | 184 | ||
182 | return thumbnail | 185 | return thumbnail |
183 | } | 186 | } |
@@ -185,14 +188,18 @@ function updatePlaceholderThumbnail (options: { | |||
185 | // --------------------------------------------------------------------------- | 188 | // --------------------------------------------------------------------------- |
186 | 189 | ||
187 | export { | 190 | export { |
188 | generateVideoMiniature, | 191 | generateLocalVideoMiniature, |
189 | updateVideoMiniatureFromUrl, | 192 | updateVideoMiniatureFromUrl, |
190 | updateVideoMiniatureFromExisting, | 193 | updateLocalVideoMiniatureFromExisting, |
191 | updatePlaceholderThumbnail, | 194 | updateRemoteThumbnail, |
192 | updatePlaylistMiniatureFromUrl, | 195 | updatePlaylistMiniatureFromUrl, |
193 | updatePlaylistMiniatureFromExisting | 196 | updateLocalPlaylistMiniatureFromExisting |
194 | } | 197 | } |
195 | 198 | ||
199 | // --------------------------------------------------------------------------- | ||
200 | // Private | ||
201 | // --------------------------------------------------------------------------- | ||
202 | |||
196 | function hasThumbnailUrlChanged (existingThumbnail: MThumbnail, downloadUrl: string, video: MVideoUUID) { | 203 | function hasThumbnailUrlChanged (existingThumbnail: MThumbnail, downloadUrl: string, video: MVideoUUID) { |
197 | const existingUrl = existingThumbnail | 204 | const existingUrl = existingThumbnail |
198 | ? existingThumbnail.fileUrl | 205 | ? existingThumbnail.fileUrl |
@@ -258,6 +265,7 @@ async function updateThumbnailFromFunction (parameters: { | |||
258 | height: number | 265 | height: number |
259 | width: number | 266 | width: number |
260 | type: ThumbnailType | 267 | type: ThumbnailType |
268 | onDisk: boolean | ||
261 | automaticallyGenerated?: boolean | 269 | automaticallyGenerated?: boolean |
262 | fileUrl?: string | 270 | fileUrl?: string |
263 | existingThumbnail?: MThumbnail | 271 | existingThumbnail?: MThumbnail |
@@ -269,6 +277,7 @@ async function updateThumbnailFromFunction (parameters: { | |||
269 | height, | 277 | height, |
270 | type, | 278 | type, |
271 | existingThumbnail, | 279 | existingThumbnail, |
280 | onDisk, | ||
272 | automaticallyGenerated = null, | 281 | automaticallyGenerated = null, |
273 | fileUrl = null | 282 | fileUrl = null |
274 | } = parameters | 283 | } = parameters |
@@ -285,6 +294,7 @@ async function updateThumbnailFromFunction (parameters: { | |||
285 | thumbnail.type = type | 294 | thumbnail.type = type |
286 | thumbnail.fileUrl = fileUrl | 295 | thumbnail.fileUrl = fileUrl |
287 | thumbnail.automaticallyGenerated = automaticallyGenerated | 296 | thumbnail.automaticallyGenerated = automaticallyGenerated |
297 | thumbnail.onDisk = onDisk | ||
288 | 298 | ||
289 | if (oldFilename) thumbnail.previousThumbnailFilename = oldFilename | 299 | if (oldFilename) thumbnail.previousThumbnailFilename = oldFilename |
290 | 300 | ||