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/videos/import.ts | 10 ++++++---- server/controllers/api/videos/index.ts | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'server/controllers/api/videos') 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