diff options
Diffstat (limited to 'server/lib/video-studio.ts')
-rw-r--r-- | server/lib/video-studio.ts | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/server/lib/video-studio.ts b/server/lib/video-studio.ts index b392bdb00..beda326a0 100644 --- a/server/lib/video-studio.ts +++ b/server/lib/video-studio.ts | |||
@@ -1,15 +1,31 @@ | |||
1 | import { logger } from '@server/helpers/logger' | ||
1 | import { MVideoFullLight } from '@server/types/models' | 2 | import { MVideoFullLight } from '@server/types/models' |
2 | import { getVideoStreamDuration } from '@shared/ffmpeg' | 3 | import { getVideoStreamDuration } from '@shared/ffmpeg' |
3 | import { VideoStudioTask } from '@shared/models' | 4 | import { VideoStudioEditionPayload, VideoStudioTask } from '@shared/models' |
5 | import { remove } from 'fs-extra' | ||
4 | 6 | ||
5 | function buildTaskFileFieldname (indice: number, fieldName = 'file') { | 7 | function buildTaskFileFieldname (indice: number, fieldName = 'file') { |
6 | return `tasks[${indice}][options][${fieldName}]` | 8 | return `tasks[${indice}][options][${fieldName}]` |
7 | } | 9 | } |
8 | 10 | ||
9 | function getTaskFile (files: Express.Multer.File[], indice: number, fieldName = 'file') { | 11 | function getTaskFileFromReq (files: Express.Multer.File[], indice: number, fieldName = 'file') { |
10 | return files.find(f => f.fieldname === buildTaskFileFieldname(indice, fieldName)) | 12 | return files.find(f => f.fieldname === buildTaskFileFieldname(indice, fieldName)) |
11 | } | 13 | } |
12 | 14 | ||
15 | async function safeCleanupStudioTMPFiles (payload: VideoStudioEditionPayload) { | ||
16 | for (const task of payload.tasks) { | ||
17 | try { | ||
18 | if (task.name === 'add-intro' || task.name === 'add-outro') { | ||
19 | await remove(task.options.file) | ||
20 | } else if (task.name === 'add-watermark') { | ||
21 | await remove(task.options.file) | ||
22 | } | ||
23 | } catch (err) { | ||
24 | logger.error('Cannot remove studio file', { err }) | ||
25 | } | ||
26 | } | ||
27 | } | ||
28 | |||
13 | async function approximateIntroOutroAdditionalSize (video: MVideoFullLight, tasks: VideoStudioTask[], fileFinder: (i: number) => string) { | 29 | async function approximateIntroOutroAdditionalSize (video: MVideoFullLight, tasks: VideoStudioTask[], fileFinder: (i: number) => string) { |
14 | let additionalDuration = 0 | 30 | let additionalDuration = 0 |
15 | 31 | ||
@@ -28,5 +44,6 @@ async function approximateIntroOutroAdditionalSize (video: MVideoFullLight, task | |||
28 | export { | 44 | export { |
29 | approximateIntroOutroAdditionalSize, | 45 | approximateIntroOutroAdditionalSize, |
30 | buildTaskFileFieldname, | 46 | buildTaskFileFieldname, |
31 | getTaskFile | 47 | getTaskFileFromReq, |
48 | safeCleanupStudioTMPFiles | ||
32 | } | 49 | } |