From a35a22797c99f17924347da9a226068c3dbe4787 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 16 Feb 2021 08:50:40 +0100 Subject: Remove previous thumbnail if needed --- server/controllers/api/video-playlist.ts | 19 ++++++++++++++++--- server/controllers/api/videos/import.ts | 10 ++++++---- server/controllers/api/videos/index.ts | 2 +- 3 files changed, 23 insertions(+), 8 deletions(-) (limited to 'server/controllers/api') diff --git a/server/controllers/api/video-playlist.ts b/server/controllers/api/video-playlist.ts index f3dc8b2a9..aab16533d 100644 --- a/server/controllers/api/video-playlist.ts +++ b/server/controllers/api/video-playlist.ts @@ -173,7 +173,11 @@ async function addVideoPlaylist (req: express.Request, res: express.Response) { const thumbnailField = req.files['thumbnailfile'] const thumbnailModel = thumbnailField - ? await createPlaylistMiniatureFromExisting(thumbnailField[0].path, videoPlaylist, false) + ? await createPlaylistMiniatureFromExisting({ + inputPath: thumbnailField[0].path, + playlist: videoPlaylist, + automaticallyGenerated: false + }) : undefined const videoPlaylistCreated = await sequelizeTypescript.transaction(async t => { @@ -211,7 +215,11 @@ async function updateVideoPlaylist (req: express.Request, res: express.Response) const thumbnailField = req.files['thumbnailfile'] const thumbnailModel = thumbnailField - ? await createPlaylistMiniatureFromExisting(thumbnailField[0].path, videoPlaylistInstance, false) + ? await createPlaylistMiniatureFromExisting({ + inputPath: thumbnailField[0].path, + playlist: videoPlaylistInstance, + automaticallyGenerated: false + }) : undefined try { @@ -474,7 +482,12 @@ async function generateThumbnailForPlaylist (videoPlaylist: MVideoPlaylistThumbn } const inputPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, videoMiniature.filename) - const thumbnailModel = await createPlaylistMiniatureFromExisting(inputPath, videoPlaylist, true, true) + const thumbnailModel = await createPlaylistMiniatureFromExisting({ + inputPath, + playlist: videoPlaylist, + automaticallyGenerated: true, + keepOriginal: true + }) thumbnailModel.videoPlaylistId = videoPlaylist.id diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts index c689cb6f9..3b9b887e2 100644 --- a/server/controllers/api/videos/import.ts +++ b/server/controllers/api/videos/import.ts @@ -282,7 +282,7 @@ async function processPreview (req: express.Request, video: MVideoThumbnail): Pr async function processThumbnailFromUrl (url: string, video: MVideoThumbnail) { try { - return createVideoMiniatureFromUrl(url, video, ThumbnailType.MINIATURE) + return createVideoMiniatureFromUrl({ downloadUrl: url, video, type: ThumbnailType.MINIATURE }) } catch (err) { logger.warn('Cannot generate video thumbnail %s for %s.', url, video.url, { err }) return undefined @@ -291,14 +291,14 @@ async function processThumbnailFromUrl (url: string, video: MVideoThumbnail) { async function processPreviewFromUrl (url: string, video: MVideoThumbnail) { try { - return createVideoMiniatureFromUrl(url, video, ThumbnailType.PREVIEW) + return createVideoMiniatureFromUrl({ downloadUrl: url, video, type: ThumbnailType.PREVIEW }) } catch (err) { logger.warn('Cannot generate video preview %s for %s.', url, video.url, { err }) return undefined } } -function insertIntoDB (parameters: { +async function insertIntoDB (parameters: { video: MVideoThumbnail thumbnailModel: MThumbnail previewModel: MThumbnail @@ -309,7 +309,7 @@ function insertIntoDB (parameters: { }): Promise { const { video, thumbnailModel, previewModel, videoChannel, tags, videoImportAttributes, user } = parameters - return sequelizeTypescript.transaction(async t => { + const videoImport = await sequelizeTypescript.transaction(async t => { const sequelizeOptions = { transaction: t } // Save video object in database @@ -339,4 +339,6 @@ function insertIntoDB (parameters: { return videoImport }) + + return videoImport } diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index c2c5eb640..9504c40a4 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -215,7 +215,7 @@ async function addVideo (req: express.Request, res: express.Response) { const [ thumbnailModel, previewModel ] = await buildVideoThumbnailsFromReq({ video, files: req.files, - fallback: type => generateVideoMiniature(video, videoFile, type) + fallback: type => generateVideoMiniature({ video, videoFile, type }) }) // Create the torrent file -- cgit v1.2.3