diff options
Diffstat (limited to 'server/lib/thumbnail.ts')
-rw-r--r-- | server/lib/thumbnail.ts | 70 |
1 files changed, 35 insertions, 35 deletions
diff --git a/server/lib/thumbnail.ts b/server/lib/thumbnail.ts index e792567ff..90f5dc2c8 100644 --- a/server/lib/thumbnail.ts +++ b/server/lib/thumbnail.ts | |||
@@ -60,38 +60,6 @@ function updatePlaylistMiniatureFromUrl (options: { | |||
60 | return updateThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl, onDisk: true }) | 60 | return updateThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl, onDisk: true }) |
61 | } | 61 | } |
62 | 62 | ||
63 | function updateVideoMiniatureFromUrl (options: { | ||
64 | downloadUrl: string | ||
65 | video: MVideoThumbnail | ||
66 | type: ThumbnailType | ||
67 | size?: ImageSize | ||
68 | }) { | ||
69 | const { downloadUrl, video, type, size } = options | ||
70 | const { filename: updatedFilename, basePath, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size) | ||
71 | |||
72 | // Only save the file URL if it is a remote video | ||
73 | const fileUrl = video.isOwned() | ||
74 | ? null | ||
75 | : downloadUrl | ||
76 | |||
77 | const thumbnailUrlChanged = hasThumbnailUrlChanged(existingThumbnail, downloadUrl, video) | ||
78 | |||
79 | // Do not change the thumbnail filename if the file did not change | ||
80 | const filename = thumbnailUrlChanged | ||
81 | ? updatedFilename | ||
82 | : existingThumbnail.filename | ||
83 | |||
84 | const thumbnailCreator = () => { | ||
85 | if (thumbnailUrlChanged) { | ||
86 | return downloadImageFromWorker({ url: downloadUrl, destDir: basePath, destName: filename, size: { width, height } }) | ||
87 | } | ||
88 | |||
89 | return Promise.resolve() | ||
90 | } | ||
91 | |||
92 | return updateThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl, onDisk: true }) | ||
93 | } | ||
94 | |||
95 | function updateLocalVideoMiniatureFromExisting (options: { | 63 | function updateLocalVideoMiniatureFromExisting (options: { |
96 | inputPath: string | 64 | inputPath: string |
97 | video: MVideoThumbnail | 65 | video: MVideoThumbnail |
@@ -157,6 +125,40 @@ function generateLocalVideoMiniature (options: { | |||
157 | }) | 125 | }) |
158 | } | 126 | } |
159 | 127 | ||
128 | // --------------------------------------------------------------------------- | ||
129 | |||
130 | function updateVideoMiniatureFromUrl (options: { | ||
131 | downloadUrl: string | ||
132 | video: MVideoThumbnail | ||
133 | type: ThumbnailType | ||
134 | size?: ImageSize | ||
135 | }) { | ||
136 | const { downloadUrl, video, type, size } = options | ||
137 | const { filename: updatedFilename, basePath, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size) | ||
138 | |||
139 | // Only save the file URL if it is a remote video | ||
140 | const fileUrl = video.isOwned() | ||
141 | ? null | ||
142 | : downloadUrl | ||
143 | |||
144 | const thumbnailUrlChanged = hasThumbnailUrlChanged(existingThumbnail, downloadUrl, video) | ||
145 | |||
146 | // Do not change the thumbnail filename if the file did not change | ||
147 | const filename = thumbnailUrlChanged | ||
148 | ? updatedFilename | ||
149 | : existingThumbnail.filename | ||
150 | |||
151 | const thumbnailCreator = () => { | ||
152 | if (thumbnailUrlChanged) { | ||
153 | return downloadImageFromWorker({ url: downloadUrl, destDir: basePath, destName: filename, size: { width, height } }) | ||
154 | } | ||
155 | |||
156 | return Promise.resolve() | ||
157 | } | ||
158 | |||
159 | return updateThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl, onDisk: true }) | ||
160 | } | ||
161 | |||
160 | function updateRemoteThumbnail (options: { | 162 | function updateRemoteThumbnail (options: { |
161 | fileUrl: string | 163 | fileUrl: string |
162 | video: MVideoThumbnail | 164 | video: MVideoThumbnail |
@@ -167,12 +169,10 @@ function updateRemoteThumbnail (options: { | |||
167 | const { fileUrl, video, type, size, onDisk } = options | 169 | const { fileUrl, video, type, size, onDisk } = options |
168 | const { filename: generatedFilename, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size) | 170 | const { filename: generatedFilename, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size) |
169 | 171 | ||
170 | const thumbnailUrlChanged = hasThumbnailUrlChanged(existingThumbnail, fileUrl, video) | ||
171 | |||
172 | const thumbnail = existingThumbnail || new ThumbnailModel() | 172 | const thumbnail = existingThumbnail || new ThumbnailModel() |
173 | 173 | ||
174 | // 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 |
175 | if (thumbnailUrlChanged) { | 175 | if (hasThumbnailUrlChanged(existingThumbnail, fileUrl, video)) { |
176 | thumbnail.filename = generatedFilename | 176 | thumbnail.filename = generatedFilename |
177 | } | 177 | } |
178 | 178 | ||