aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/video-studio.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/video-studio.ts')
-rw-r--r--server/lib/video-studio.ts23
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 @@
1import { logger } from '@server/helpers/logger'
1import { MVideoFullLight } from '@server/types/models' 2import { MVideoFullLight } from '@server/types/models'
2import { getVideoStreamDuration } from '@shared/ffmpeg' 3import { getVideoStreamDuration } from '@shared/ffmpeg'
3import { VideoStudioTask } from '@shared/models' 4import { VideoStudioEditionPayload, VideoStudioTask } from '@shared/models'
5import { remove } from 'fs-extra'
4 6
5function buildTaskFileFieldname (indice: number, fieldName = 'file') { 7function buildTaskFileFieldname (indice: number, fieldName = 'file') {
6 return `tasks[${indice}][options][${fieldName}]` 8 return `tasks[${indice}][options][${fieldName}]`
7} 9}
8 10
9function getTaskFile (files: Express.Multer.File[], indice: number, fieldName = 'file') { 11function 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
15async 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
13async function approximateIntroOutroAdditionalSize (video: MVideoFullLight, tasks: VideoStudioTask[], fileFinder: (i: number) => string) { 29async 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
28export { 44export {
29 approximateIntroOutroAdditionalSize, 45 approximateIntroOutroAdditionalSize,
30 buildTaskFileFieldname, 46 buildTaskFileFieldname,
31 getTaskFile 47 getTaskFileFromReq,
48 safeCleanupStudioTMPFiles
32} 49}