-function createVideoMiniatureFromUrl (fileUrl: string, video: MVideoThumbnail, type: ThumbnailType, size?: ImageSize) {
- const { filename, basePath, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size)
- const thumbnailCreator = () => downloadImage(fileUrl, basePath, filename, { width, height })
+function createVideoMiniatureFromUrl (options: {
+ downloadUrl: string
+ video: MVideoThumbnail
+ type: ThumbnailType
+ size?: ImageSize
+}) {
+ const { downloadUrl, video, type, size } = options
+ const { filename: updatedFilename, basePath, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size)
+
+ // Only save the file URL if it is a remote video
+ const fileUrl = video.isOwned()
+ ? null
+ : downloadUrl
+
+ const thumbnailUrlChanged = hasThumbnailUrlChanged(existingThumbnail, downloadUrl, video)
+
+ // Do not change the thumbnail filename if the file did not change
+ const filename = thumbnailUrlChanged
+ ? updatedFilename
+ : existingThumbnail.filename
+
+ const thumbnailCreator = () => {
+ if (thumbnailUrlChanged) return downloadImage(downloadUrl, basePath, filename, { width, height })
+
+ return Promise.resolve()
+ }