Relax videos list thumbnail api join
authorChocobozzz <me@florianbigard.com>
Wed, 24 Apr 2019 07:56:25 +0000 (09:56 +0200)
committerChocobozzz <me@florianbigard.com>
Wed, 24 Apr 2019 14:26:22 +0000 (16:26 +0200)
server/helpers/ffmpeg-utils.ts
server/helpers/image-utils.ts
server/helpers/requests.ts
server/lib/avatar.ts
server/lib/thumbnail.ts
server/models/video/video.ts

index d818c459c66d5752d0da68fbb1d7709cdcca0da2..76b744de8543c7bd6e35a0d0a941e933143dea3d 100644 (file)
@@ -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 })
 
index eeaef0f5d3dc9a0e736538f5744d8498dd6622d1..bd81aa3bad774d134df064c70c899cafd4a7b9f6 100644 (file)
@@ -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)
 }
 
 // ---------------------------------------------------------------------------
index 8dda6c039c4705e032340f7d0cab88e1cb6f0329..2e30c94a1e8ed2e53846bebb0e92c2fad9fc976f 100644 (file)
@@ -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)
 
index dca543d0b9de6c7ed8c645f088a8bad9dc54c7f9..09b4e38ca10210016cfb212d47a4968c5fb3135a 100644 (file)
@@ -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 => {
index 8ad82ee8000556fdb354eb78f86d8e7262a05481..4ba521b973f5133c0a9d305838fc98d84ad29c5a 100644 (file)
@@ -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 })
 }
index 18f18795ed653802d5cb9d82dde5ba067bf5b7b0..5fb529e8d113455c54c60b4413bb2802ca2bc252 100644 (file)
@@ -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<VideoModel> {
       ]
     }
 
-    const apiScope: (string | ScopeOptions)[] = [ ScopeNames.WITH_THUMBNAILS ]
+    const apiScope: (string | ScopeOptions)[] = []
 
     if (options.user) {
       apiScope.push({ method: [ ScopeNames.WITH_USER_HISTORY, options.user.id ] })