aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/video-studio.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-03-22 16:58:49 +0100
committerChocobozzz <me@florianbigard.com>2022-03-22 17:24:32 +0100
commit92e66e04f7f51d37b465cff442ce47f6d6d7cadd (patch)
tree4475c5c601c0f6673ca56afba5b7f70a4fae4ec3 /server/helpers/custom-validators/video-studio.ts
parent1808a1f8e4b7b102823492a2007a46929aebf189 (diff)
downloadPeerTube-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.ts52
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 @@
1import validator from 'validator'
2import { CONSTRAINTS_FIELDS } from '@server/initializers/constants'
3import { buildTaskFileFieldname } from '@server/lib/video-studio'
4import { VideoStudioTask } from '@shared/models'
5import { isArray } from './misc'
6import { isVideoFileMimeTypeValid, isVideoImageValid } from './videos'
7
8function 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
15function 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
30function 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
37function 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
46export {
47 isValidStudioTasksArray,
48
49 isStudioCutTaskValid,
50 isStudioTaskAddIntroOutroValid,
51 isStudioTaskAddWatermarkValid
52}