From: Chocobozzz Date: Tue, 27 Feb 2018 12:46:56 +0000 (+0100) Subject: Don't fail on upload if we cannot generate thumbnail X-Git-Tag: v0.0.29-alpha~11 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=6fdc553adb23db216b44e425a85ea76bdf0a2a40;p=github%2FChocobozzz%2FPeerTube.git Don't fail on upload if we cannot generate thumbnail --- 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() }