diff options
author | Chocobozzz <me@florianbigard.com> | 2018-02-27 13:46:56 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-02-27 13:46:56 +0100 |
commit | 6fdc553adb23db216b44e425a85ea76bdf0a2a40 (patch) | |
tree | 997cf166c2ef977ce0390a9c7a892040bbe26f64 | |
parent | 266707202c2ffcb8a1b7649ec29106dd444f4a77 (diff) | |
download | PeerTube-6fdc553adb23db216b44e425a85ea76bdf0a2a40.tar.gz PeerTube-6fdc553adb23db216b44e425a85ea76bdf0a2a40.tar.zst PeerTube-6fdc553adb23db216b44e425a85ea76bdf0a2a40.zip |
Don't fail on upload if we cannot generate thumbnail
-rw-r--r-- | server/helpers/ffmpeg-utils.ts | 33 | ||||
-rw-r--r-- | server/lib/schedulers/bad-actor-follow-scheduler.ts | 3 | ||||
-rw-r--r-- | server/lib/schedulers/remove-old-jobs-scheduler.ts | 3 |
3 files changed, 27 insertions, 12 deletions
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 @@ | |||
1 | import * as ffmpeg from 'fluent-ffmpeg' | 1 | import * as ffmpeg from 'fluent-ffmpeg' |
2 | import { join } from 'path' | ||
2 | import { VideoResolution } from '../../shared/models/videos' | 3 | import { VideoResolution } from '../../shared/models/videos' |
3 | import { CONFIG, MAX_VIDEO_TRANSCODING_FPS } from '../initializers' | 4 | import { CONFIG, MAX_VIDEO_TRANSCODING_FPS } from '../initializers' |
5 | import { unlinkPromise } from './core-utils' | ||
4 | import { processImage } from './image-utils' | 6 | import { processImage } from './image-utils' |
5 | import { join } from 'path' | 7 | import { logger } from './logger' |
6 | 8 | ||
7 | async function getVideoFileHeight (path: string) { | 9 | async function getVideoFileHeight (path: string) { |
8 | const videoStream = await getVideoFileStream(path) | 10 | const videoStream = await getVideoFileStream(path) |
@@ -45,16 +47,27 @@ async function generateImageFromVideoFile (fromPath: string, folder: string, ima | |||
45 | folder | 47 | folder |
46 | } | 48 | } |
47 | 49 | ||
48 | await new Promise<string>((res, rej) => { | ||
49 | ffmpeg(fromPath) | ||
50 | .on('error', rej) | ||
51 | .on('end', () => res(imageName)) | ||
52 | .thumbnail(options) | ||
53 | }) | ||
54 | |||
55 | const pendingImagePath = join(folder, pendingImageName) | 50 | const pendingImagePath = join(folder, pendingImageName) |
56 | const destination = join(folder, imageName) | 51 | |
57 | await processImage({ path: pendingImagePath }, destination, size) | 52 | try { |
53 | await new Promise<string>((res, rej) => { | ||
54 | ffmpeg(fromPath) | ||
55 | .on('error', rej) | ||
56 | .on('end', () => res(imageName)) | ||
57 | .thumbnail(options) | ||
58 | }) | ||
59 | |||
60 | const destination = join(folder, imageName) | ||
61 | await processImage({ path: pendingImagePath }, destination, size) | ||
62 | } catch (err) { | ||
63 | logger.error('Cannot generate image from video %s.', fromPath, err) | ||
64 | |||
65 | try { | ||
66 | await unlinkPromise(pendingImagePath) | ||
67 | } catch (err) { | ||
68 | logger.debug('Cannot remove pending image path after generation error.', err) | ||
69 | } | ||
70 | } | ||
58 | } | 71 | } |
59 | 72 | ||
60 | type TranscodeOptions = { | 73 | 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 @@ | |||
1 | import { isTestInstance } from '../../helpers/core-utils' | ||
1 | import { logger } from '../../helpers/logger' | 2 | import { logger } from '../../helpers/logger' |
2 | import { ActorFollowModel } from '../../models/activitypub/actor-follow' | 3 | import { ActorFollowModel } from '../../models/activitypub/actor-follow' |
3 | import { AbstractScheduler } from './abstract-scheduler' | 4 | import { AbstractScheduler } from './abstract-scheduler' |
@@ -11,7 +12,7 @@ export class BadActorFollowScheduler extends AbstractScheduler { | |||
11 | } | 12 | } |
12 | 13 | ||
13 | async execute () { | 14 | async execute () { |
14 | logger.info('Removing bad actor follows (scheduler).') | 15 | if (!isTestInstance()) logger.info('Removing bad actor follows (scheduler).') |
15 | 16 | ||
16 | try { | 17 | try { |
17 | await ActorFollowModel.removeBadActorFollows() | 18 | 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 @@ | |||
1 | import { isTestInstance } from '../../helpers/core-utils' | ||
1 | import { logger } from '../../helpers/logger' | 2 | import { logger } from '../../helpers/logger' |
2 | import { JobQueue } from '../job-queue' | 3 | import { JobQueue } from '../job-queue' |
3 | import { AbstractScheduler } from './abstract-scheduler' | 4 | import { AbstractScheduler } from './abstract-scheduler' |
@@ -11,7 +12,7 @@ export class RemoveOldJobsScheduler extends AbstractScheduler { | |||
11 | } | 12 | } |
12 | 13 | ||
13 | async execute () { | 14 | async execute () { |
14 | logger.info('Removing old jobs (scheduler).') | 15 | if (!isTestInstance()) logger.info('Removing old jobs (scheduler).') |
15 | 16 | ||
16 | JobQueue.Instance.removeOldJobs() | 17 | JobQueue.Instance.removeOldJobs() |
17 | } | 18 | } |