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