From 6fdc553adb23db216b44e425a85ea76bdf0a2a40 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 27 Feb 2018 13:46:56 +0100 Subject: Don't fail on upload if we cannot generate thumbnail --- server/helpers/ffmpeg-utils.ts | 33 +++++++++++++++------- .../lib/schedulers/bad-actor-follow-scheduler.ts | 3 +- server/lib/schedulers/remove-old-jobs-scheduler.ts | 3 +- 3 files changed, 27 insertions(+), 12 deletions(-) (limited to 'server') diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.ts index 57911bc73..b0f95797c 100644 --- a/server/helpers/ffmpeg-utils.ts +++ b/server/helpers/ffmpeg-utils.ts @@ -1,8 +1,10 @@ import * as ffmpeg from 'fluent-ffmpeg' +import { join } from 'path' import { VideoResolution } from '../../shared/models/videos' import { CONFIG, MAX_VIDEO_TRANSCODING_FPS } from '../initializers' +import { unlinkPromise } from './core-utils' import { processImage } from './image-utils' -import { join } from 'path' +import { logger } from './logger' async function getVideoFileHeight (path: string) { const videoStream = await getVideoFileStream(path) @@ -45,16 +47,27 @@ async function generateImageFromVideoFile (fromPath: string, folder: string, ima folder } - await new Promise((res, rej) => { - ffmpeg(fromPath) - .on('error', rej) - .on('end', () => res(imageName)) - .thumbnail(options) - }) - const pendingImagePath = join(folder, pendingImageName) - const destination = join(folder, imageName) - await processImage({ path: pendingImagePath }, destination, size) + + try { + await new Promise((res, rej) => { + ffmpeg(fromPath) + .on('error', rej) + .on('end', () => res(imageName)) + .thumbnail(options) + }) + + const destination = join(folder, imageName) + await processImage({ path: pendingImagePath }, destination, size) + } catch (err) { + logger.error('Cannot generate image from video %s.', fromPath, err) + + try { + await unlinkPromise(pendingImagePath) + } catch (err) { + logger.debug('Cannot remove pending image path after generation error.', err) + } + } } type TranscodeOptions = { diff --git a/server/lib/schedulers/bad-actor-follow-scheduler.ts b/server/lib/schedulers/bad-actor-follow-scheduler.ts index 397eb470e..9b9f9e17d 100644 --- a/server/lib/schedulers/bad-actor-follow-scheduler.ts +++ b/server/lib/schedulers/bad-actor-follow-scheduler.ts @@ -1,3 +1,4 @@ +import { isTestInstance } from '../../helpers/core-utils' import { logger } from '../../helpers/logger' import { ActorFollowModel } from '../../models/activitypub/actor-follow' import { AbstractScheduler } from './abstract-scheduler' @@ -11,7 +12,7 @@ export class BadActorFollowScheduler extends AbstractScheduler { } async execute () { - logger.info('Removing bad actor follows (scheduler).') + if (!isTestInstance()) logger.info('Removing bad actor follows (scheduler).') try { await ActorFollowModel.removeBadActorFollows() diff --git a/server/lib/schedulers/remove-old-jobs-scheduler.ts b/server/lib/schedulers/remove-old-jobs-scheduler.ts index 51fcf711e..0e8ad1554 100644 --- a/server/lib/schedulers/remove-old-jobs-scheduler.ts +++ b/server/lib/schedulers/remove-old-jobs-scheduler.ts @@ -1,3 +1,4 @@ +import { isTestInstance } from '../../helpers/core-utils' import { logger } from '../../helpers/logger' import { JobQueue } from '../job-queue' import { AbstractScheduler } from './abstract-scheduler' @@ -11,7 +12,7 @@ export class RemoveOldJobsScheduler extends AbstractScheduler { } async execute () { - logger.info('Removing old jobs (scheduler).') + if (!isTestInstance()) logger.info('Removing old jobs (scheduler).') JobQueue.Instance.removeOldJobs() } -- cgit v1.2.3