})
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 })
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)
.resize(newSize.width, newSize.height)
.toFile(destination)
- if (keepOriginal !== true) await remove(physicalFile.path)
+ if (keepOriginal !== true) await remove(path)
}
// ---------------------------------------------------------------------------
const destPath = join(destDir, destName)
try {
- await processImage({ path: tmpPath }, destPath, size)
+ await processImage(tmpPath, destPath, size)
} catch (err) {
await remove(tmpPath)
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 => {
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 })
}
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 })
}
{
model: VideoChannelModel.scope({ method: [ VideoChannelScopeNames.SUMMARY, true ] }),
required: true
+ },
+ {
+ attributes: [ 'type', 'filename' ],
+ model: ThumbnailModel,
+ required: false
}
]
}
]
}
- const apiScope: (string | ScopeOptions)[] = [ ScopeNames.WITH_THUMBNAILS ]
+ const apiScope: (string | ScopeOptions)[] = []
if (options.user) {
apiScope.push({ method: [ ScopeNames.WITH_USER_HISTORY, options.user.id ] })