Don't fail on upload if we cannot generate thumbnail

This commit is contained in:
Chocobozzz 2018-02-27 13:46:56 +01:00
parent 266707202c
commit 6fdc553adb
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
3 changed files with 27 additions and 12 deletions

View File

@ -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<string>((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<string>((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 = {

View File

@ -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()

View File

@ -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()
}