]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/form-validators/video-validators.ts
Add live info in watch page
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / form-validators / video-validators.ts
CommitLineData
7ed1edbb
C
1import { AbstractControl, ValidationErrors, ValidatorFn, Validators } from '@angular/forms'
2import { BuildFormValidator } from './form-validator.model'
3
4export const VIDEO_NAME_VALIDATOR: BuildFormValidator = {
5 VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(120) ],
6 MESSAGES: {
7 'required': $localize`Video name is required.`,
8 'minlength': $localize`Video name must be at least 3 characters long.`,
9 'maxlength': $localize`Video name cannot be more than 120 characters long.`
10 }
11}
12
13export const VIDEO_PRIVACY_VALIDATOR: BuildFormValidator = {
14 VALIDATORS: [ Validators.required ],
15 MESSAGES: {
16 'required': $localize`Video privacy is required.`
17 }
18}
19
20export const VIDEO_CATEGORY_VALIDATOR: BuildFormValidator = {
21 VALIDATORS: [ ],
22 MESSAGES: {}
23}
24
25export const VIDEO_LICENCE_VALIDATOR: BuildFormValidator = {
26 VALIDATORS: [ ],
27 MESSAGES: {}
28}
29
30export const VIDEO_LANGUAGE_VALIDATOR: BuildFormValidator = {
31 VALIDATORS: [ ],
32 MESSAGES: {}
33}
34
35export const VIDEO_IMAGE_VALIDATOR: BuildFormValidator = {
36 VALIDATORS: [ ],
37 MESSAGES: {}
38}
39
40export const VIDEO_CHANNEL_VALIDATOR: BuildFormValidator = {
41 VALIDATORS: [ Validators.required ],
42 MESSAGES: {
43 'required': $localize`Video channel is required.`
44 }
45}
46
47export const VIDEO_DESCRIPTION_VALIDATOR: BuildFormValidator = {
48 VALIDATORS: [ Validators.minLength(3), Validators.maxLength(10000) ],
49 MESSAGES: {
50 'minlength': $localize`Video description must be at least 3 characters long.`,
51 'maxlength': $localize`Video description cannot be more than 10000 characters long.`
52 }
53}
54
55export const VIDEO_TAG_VALIDATOR: BuildFormValidator = {
56 VALIDATORS: [ Validators.minLength(2), Validators.maxLength(30) ],
57 MESSAGES: {
58 'minlength': $localize`A tag should be more than 2 characters long.`,
59 'maxlength': $localize`A tag should be less than 30 characters long.`
60 }
61}
62
63export const VIDEO_TAGS_ARRAY_VALIDATOR: BuildFormValidator = {
64 VALIDATORS: [ Validators.maxLength(5), arrayTagLengthValidator() ],
65 MESSAGES: {
66 'maxlength': $localize`A maximum of 5 tags can be used on a video.`,
67 'arrayTagLength': $localize`A tag should be more than 2, and less than 30 characters long.`
68 }
69}
70
71export const VIDEO_SUPPORT_VALIDATOR: BuildFormValidator = {
72 VALIDATORS: [ Validators.minLength(3), Validators.maxLength(1000) ],
73 MESSAGES: {
74 'minlength': $localize`Video support must be at least 3 characters long.`,
75 'maxlength': $localize`Video support cannot be more than 1000 characters long.`
76 }
77}
78
79export const VIDEO_SCHEDULE_PUBLICATION_AT_VALIDATOR: BuildFormValidator = {
80 VALIDATORS: [ ],
81 MESSAGES: {
82 'required': $localize`A date is required to schedule video update.`
83 }
84}
85
86export const VIDEO_ORIGINALLY_PUBLISHED_AT_VALIDATOR: BuildFormValidator = {
87 VALIDATORS: [ ],
88 MESSAGES: {}
89}
90
91function arrayTagLengthValidator (min = 2, max = 30): ValidatorFn {
92 return (control: AbstractControl): ValidationErrors => {
93 const array = control.value as Array<string>
94
95 if (array.every(e => e.length > min && e.length < max)) {
96 return null
97 }
98
99 return { 'arrayTagLength': true }
100 }
101}