aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/form-validators
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-08-28 10:55:04 +0200
committerChocobozzz <me@florianbigard.com>2023-08-28 16:17:31 +0200
commit77b70702d2193d78bf6fbd07f0fc7335e34957f8 (patch)
tree1a0aed540054286c9a8b10c4890cc0f718e00458 /client/src/app/shared/form-validators
parent7113f32a87bd6b2868154fed20bde1a1633c190e (diff)
downloadPeerTube-77b70702d2193d78bf6fbd07f0fc7335e34957f8.tar.gz
PeerTube-77b70702d2193d78bf6fbd07f0fc7335e34957f8.tar.zst
PeerTube-77b70702d2193d78bf6fbd07f0fc7335e34957f8.zip
Add video chapters support
Diffstat (limited to 'client/src/app/shared/form-validators')
-rw-r--r--client/src/app/shared/form-validators/video-chapter-validators.ts32
-rw-r--r--client/src/app/shared/form-validators/video-validators.ts8
2 files changed, 32 insertions, 8 deletions
diff --git a/client/src/app/shared/form-validators/video-chapter-validators.ts b/client/src/app/shared/form-validators/video-chapter-validators.ts
new file mode 100644
index 000000000..cbbd9291e
--- /dev/null
+++ b/client/src/app/shared/form-validators/video-chapter-validators.ts
@@ -0,0 +1,32 @@
1import { AbstractControl, ValidationErrors, ValidatorFn, Validators } from '@angular/forms'
2import { BuildFormValidator } from './form-validator.model'
3
4export const VIDEO_CHAPTER_TITLE_VALIDATOR: BuildFormValidator = {
5 VALIDATORS: [ Validators.minLength(2), Validators.maxLength(100) ], // Required is set dynamically
6 MESSAGES: {
7 required: $localize`A chapter title is required.`,
8 minlength: $localize`A chapter title should be more than 2 characters long.`,
9 maxlength: $localize`A chapter title should be less than 100 characters long.`
10 }
11}
12
13export const VIDEO_CHAPTERS_ARRAY_VALIDATOR: BuildFormValidator = {
14 VALIDATORS: [ uniqueTimecodeValidator() ],
15 MESSAGES: {}
16}
17
18function uniqueTimecodeValidator (): ValidatorFn {
19 return (control: AbstractControl): ValidationErrors => {
20 const array = control.value as { timecode: number, title: string }[]
21
22 for (const chapter of array) {
23 if (!chapter.title) continue
24
25 if (array.filter(c => c.title && c.timecode === chapter.timecode).length > 1) {
26 return { uniqueTimecode: $localize`Multiple chapters have the same timecode ${chapter.timecode}` }
27 }
28 }
29
30 return null
31 }
32}
diff --git a/client/src/app/shared/form-validators/video-validators.ts b/client/src/app/shared/form-validators/video-validators.ts
index 090a76e43..a434c777f 100644
--- a/client/src/app/shared/form-validators/video-validators.ts
+++ b/client/src/app/shared/form-validators/video-validators.ts
@@ -70,14 +70,6 @@ export const VIDEO_DESCRIPTION_VALIDATOR: BuildFormValidator = {
70 } 70 }
71} 71}
72 72
73export const VIDEO_TAG_VALIDATOR: BuildFormValidator = {
74 VALIDATORS: [ Validators.minLength(2), Validators.maxLength(30) ],
75 MESSAGES: {
76 minlength: $localize`A tag should be more than 2 characters long.`,
77 maxlength: $localize`A tag should be less than 30 characters long.`
78 }
79}
80
81export const VIDEO_TAGS_ARRAY_VALIDATOR: BuildFormValidator = { 73export const VIDEO_TAGS_ARRAY_VALIDATOR: BuildFormValidator = {
82 VALIDATORS: [ Validators.maxLength(5), arrayTagLengthValidator() ], 74 VALIDATORS: [ Validators.maxLength(5), arrayTagLengthValidator() ],
83 MESSAGES: { 75 MESSAGES: {