diff options
author | Chocobozzz <me@florianbigard.com> | 2022-03-22 16:58:49 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-03-22 17:24:32 +0100 |
commit | 92e66e04f7f51d37b465cff442ce47f6d6d7cadd (patch) | |
tree | 4475c5c601c0f6673ca56afba5b7f70a4fae4ec3 /server/helpers/custom-validators/video-studio.ts | |
parent | 1808a1f8e4b7b102823492a2007a46929aebf189 (diff) | |
download | PeerTube-92e66e04f7f51d37b465cff442ce47f6d6d7cadd.tar.gz PeerTube-92e66e04f7f51d37b465cff442ce47f6d6d7cadd.tar.zst PeerTube-92e66e04f7f51d37b465cff442ce47f6d6d7cadd.zip |
Rename studio to editor
Diffstat (limited to 'server/helpers/custom-validators/video-studio.ts')
-rw-r--r-- | server/helpers/custom-validators/video-studio.ts | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/server/helpers/custom-validators/video-studio.ts b/server/helpers/custom-validators/video-studio.ts new file mode 100644 index 000000000..19e7906d5 --- /dev/null +++ b/server/helpers/custom-validators/video-studio.ts | |||
@@ -0,0 +1,52 @@ | |||
1 | import validator from 'validator' | ||
2 | import { CONSTRAINTS_FIELDS } from '@server/initializers/constants' | ||
3 | import { buildTaskFileFieldname } from '@server/lib/video-studio' | ||
4 | import { VideoStudioTask } from '@shared/models' | ||
5 | import { isArray } from './misc' | ||
6 | import { isVideoFileMimeTypeValid, isVideoImageValid } from './videos' | ||
7 | |||
8 | function isValidStudioTasksArray (tasks: any) { | ||
9 | if (!isArray(tasks)) return false | ||
10 | |||
11 | return tasks.length >= CONSTRAINTS_FIELDS.VIDEO_STUDIO.TASKS.min && | ||
12 | tasks.length <= CONSTRAINTS_FIELDS.VIDEO_STUDIO.TASKS.max | ||
13 | } | ||
14 | |||
15 | function isStudioCutTaskValid (task: VideoStudioTask) { | ||
16 | if (task.name !== 'cut') return false | ||
17 | if (!task.options) return false | ||
18 | |||
19 | const { start, end } = task.options | ||
20 | if (!start && !end) return false | ||
21 | |||
22 | if (start && !validator.isInt(start + '', CONSTRAINTS_FIELDS.VIDEO_STUDIO.CUT_TIME)) return false | ||
23 | if (end && !validator.isInt(end + '', CONSTRAINTS_FIELDS.VIDEO_STUDIO.CUT_TIME)) return false | ||
24 | |||
25 | if (!start || !end) return true | ||
26 | |||
27 | return parseInt(start + '') < parseInt(end + '') | ||
28 | } | ||
29 | |||
30 | function isStudioTaskAddIntroOutroValid (task: VideoStudioTask, indice: number, files: Express.Multer.File[]) { | ||
31 | const file = files.find(f => f.fieldname === buildTaskFileFieldname(indice, 'file')) | ||
32 | |||
33 | return (task.name === 'add-intro' || task.name === 'add-outro') && | ||
34 | file && isVideoFileMimeTypeValid([ file ], null) | ||
35 | } | ||
36 | |||
37 | function isStudioTaskAddWatermarkValid (task: VideoStudioTask, indice: number, files: Express.Multer.File[]) { | ||
38 | const file = files.find(f => f.fieldname === buildTaskFileFieldname(indice, 'file')) | ||
39 | |||
40 | return task.name === 'add-watermark' && | ||
41 | file && isVideoImageValid([ file ], null, true) | ||
42 | } | ||
43 | |||
44 | // --------------------------------------------------------------------------- | ||
45 | |||
46 | export { | ||
47 | isValidStudioTasksArray, | ||
48 | |||
49 | isStudioCutTaskValid, | ||
50 | isStudioTaskAddIntroOutroValid, | ||
51 | isStudioTaskAddWatermarkValid | ||
52 | } | ||