Relax videos list thumbnail api join
This commit is contained in:
parent
b876eaf11a
commit
2fb5b3a55a
6 changed files with 16 additions and 11 deletions
|
@ -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 })
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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 => {
|
||||
|
|
|
@ -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 })
|
||||
}
|
||||
|
|
|
@ -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 ] })
|
||||
|
|
Loading…
Reference in a new issue