diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.ts index d818c459c..76b744de8 100644 --- a/server/helpers/ffmpeg-utils.ts +++ b/server/helpers/ffmpeg-utils.ts @@ -105,7 +105,7 @@ async function generateImageFromVideoFile (fromPath: string, folder: string, ima }) const destination = join(folder, imageName) - await processImage({ path: pendingImagePath }, destination, size) + await processImage(pendingImagePath, destination, size) } catch (err) { logger.error('Cannot generate image from video %s.', fromPath, { err }) diff --git a/server/helpers/image-utils.ts b/server/helpers/image-utils.ts index eeaef0f5d..bd81aa3ba 100644 --- a/server/helpers/image-utils.ts +++ b/server/helpers/image-utils.ts @@ -4,19 +4,19 @@ import { readFile, remove } from 'fs-extra' import { logger } from './logger' async function processImage ( - physicalFile: { path: string }, + path: string, destination: string, newSize: { width: number, height: number }, keepOriginal = false ) { - if (physicalFile.path === destination) { + if (path === destination) { throw new Error('Sharp needs an input path different that the output path.') } - logger.debug('Processing image %s to %s.', physicalFile.path, destination) + logger.debug('Processing image %s to %s.', path, destination) // Avoid sharp cache - const buf = await readFile(physicalFile.path) + const buf = await readFile(path) const sharpInstance = sharp(buf) await remove(destination) @@ -25,7 +25,7 @@ async function processImage ( .resize(newSize.width, newSize.height) .toFile(destination) - if (keepOriginal !== true) await remove(physicalFile.path) + if (keepOriginal !== true) await remove(path) } // --------------------------------------------------------------------------- diff --git a/server/helpers/requests.ts b/server/helpers/requests.ts index 8dda6c039..2e30c94a1 100644 --- a/server/helpers/requests.ts +++ b/server/helpers/requests.ts @@ -52,7 +52,7 @@ async function downloadImage (url: string, destDir: string, destName: string, si const destPath = join(destDir, destName) try { - await processImage({ path: tmpPath }, destPath, size) + await processImage(tmpPath, destPath, size) } catch (err) { await remove(tmpPath) diff --git a/server/lib/avatar.ts b/server/lib/avatar.ts index dca543d0b..09b4e38ca 100644 --- a/server/lib/avatar.ts +++ b/server/lib/avatar.ts @@ -15,7 +15,7 @@ async function updateActorAvatarFile (avatarPhysicalFile: Express.Multer.File, a const extension = extname(avatarPhysicalFile.filename) const avatarName = uuidv4() + extension const destination = join(CONFIG.STORAGE.AVATARS_DIR, avatarName) - await processImage(avatarPhysicalFile, destination, AVATARS_SIZE) + await processImage(avatarPhysicalFile.path, destination, AVATARS_SIZE) return retryTransactionWrapper(() => { return sequelizeTypescript.transaction(async t => { diff --git a/server/lib/thumbnail.ts b/server/lib/thumbnail.ts index 8ad82ee80..4ba521b97 100644 --- a/server/lib/thumbnail.ts +++ b/server/lib/thumbnail.ts @@ -16,7 +16,7 @@ function createPlaylistMiniatureFromExisting (inputPath: string, playlist: Video const { filename, outputPath, height, width, existingThumbnail } = buildMetadataFromPlaylist(playlist, size) const type = ThumbnailType.MINIATURE - const thumbnailCreator = () => processImage({ path: inputPath }, outputPath, { width, height }, keepOriginal) + const thumbnailCreator = () => processImage(inputPath, outputPath, { width, height }, keepOriginal) return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail }) } @@ -37,7 +37,7 @@ function createVideoMiniatureFromUrl (url: string, video: VideoModel, type: Thum function createVideoMiniatureFromExisting (inputPath: string, video: VideoModel, type: ThumbnailType, size?: ImageSize) { const { filename, outputPath, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size) - const thumbnailCreator = () => processImage({ path: inputPath }, outputPath, { width, height }) + const thumbnailCreator = () => processImage(inputPath, outputPath, { width, height }) return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail }) } diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 18f18795e..5fb529e8d 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -239,6 +239,11 @@ type AvailableForListIDsOptions = { { model: VideoChannelModel.scope({ method: [ VideoChannelScopeNames.SUMMARY, true ] }), required: true + }, + { + attributes: [ 'type', 'filename' ], + model: ThumbnailModel, + required: false } ] } @@ -1599,7 +1604,7 @@ export class VideoModel extends Model { ] } - const apiScope: (string | ScopeOptions)[] = [ ScopeNames.WITH_THUMBNAILS ] + const apiScope: (string | ScopeOptions)[] = [] if (options.user) { apiScope.push({ method: [ ScopeNames.WITH_USER_HISTORY, options.user.id ] })