]>
Commit | Line | Data |
---|---|---|
e309822b C |
1 | import { Validators } from '@angular/forms' |
2 | import { I18n } from '@ngx-translate/i18n-polyfill' | |
3 | import { BuildFormValidator } from '@app/shared' | |
4 | import { Injectable } from '@angular/core' | |
5 | ||
6 | @Injectable() | |
7 | export class CustomConfigValidatorsService { | |
8 | readonly INSTANCE_NAME: BuildFormValidator | |
9 | readonly INSTANCE_SHORT_DESCRIPTION: BuildFormValidator | |
10 | readonly SERVICES_TWITTER_USERNAME: BuildFormValidator | |
11 | readonly CACHE_PREVIEWS_SIZE: BuildFormValidator | |
40e87e9e | 12 | readonly CACHE_CAPTIONS_SIZE: BuildFormValidator |
e309822b C |
13 | readonly SIGNUP_LIMIT: BuildFormValidator |
14 | readonly ADMIN_EMAIL: BuildFormValidator | |
15 | readonly TRANSCODING_THREADS: BuildFormValidator | |
e1b49ee5 | 16 | readonly INDEX_URL: BuildFormValidator |
e309822b C |
17 | |
18 | constructor (private i18n: I18n) { | |
19 | this.INSTANCE_NAME = { | |
20 | VALIDATORS: [ Validators.required ], | |
21 | MESSAGES: { | |
22 | 'required': this.i18n('Instance name is required.') | |
23 | } | |
24 | } | |
25 | ||
26 | this.INSTANCE_SHORT_DESCRIPTION = { | |
27 | VALIDATORS: [ Validators.max(250) ], | |
28 | MESSAGES: { | |
29 | 'max': this.i18n('Short description should not be longer than 250 characters.') | |
30 | } | |
31 | } | |
32 | ||
33 | this.SERVICES_TWITTER_USERNAME = { | |
34 | VALIDATORS: [ Validators.required ], | |
35 | MESSAGES: { | |
36 | 'required': this.i18n('Twitter username is required.') | |
37 | } | |
38 | } | |
39 | ||
40 | this.CACHE_PREVIEWS_SIZE = { | |
41 | VALIDATORS: [ Validators.required, Validators.min(1), Validators.pattern('[0-9]+') ], | |
42 | MESSAGES: { | |
43 | 'required': this.i18n('Previews cache size is required.'), | |
44 | 'min': this.i18n('Previews cache size must be greater than 1.'), | |
45 | 'pattern': this.i18n('Previews cache size must be a number.') | |
46 | } | |
47 | } | |
48 | ||
40e87e9e C |
49 | this.CACHE_CAPTIONS_SIZE = { |
50 | VALIDATORS: [ Validators.required, Validators.min(1), Validators.pattern('[0-9]+') ], | |
51 | MESSAGES: { | |
52 | 'required': this.i18n('Captions cache size is required.'), | |
53 | 'min': this.i18n('Captions cache size must be greater than 1.'), | |
54 | 'pattern': this.i18n('Captions cache size must be a number.') | |
55 | } | |
56 | } | |
57 | ||
e309822b C |
58 | this.SIGNUP_LIMIT = { |
59 | VALIDATORS: [ Validators.required, Validators.min(1), Validators.pattern('[0-9]+') ], | |
60 | MESSAGES: { | |
61 | 'required': this.i18n('Signup limit is required.'), | |
62 | 'min': this.i18n('Signup limit must be greater than 1.'), | |
63 | 'pattern': this.i18n('Signup limit must be a number.') | |
64 | } | |
65 | } | |
66 | ||
67 | this.ADMIN_EMAIL = { | |
68 | VALIDATORS: [ Validators.required, Validators.email ], | |
69 | MESSAGES: { | |
70 | 'required': this.i18n('Admin email is required.'), | |
71 | 'email': this.i18n('Admin email must be valid.') | |
72 | } | |
73 | } | |
74 | ||
75 | this.TRANSCODING_THREADS = { | |
9e912376 | 76 | VALIDATORS: [ Validators.required, Validators.min(0) ], |
e309822b C |
77 | MESSAGES: { |
78 | 'required': this.i18n('Transcoding threads is required.'), | |
9e912376 | 79 | 'min': this.i18n('Transcoding threads must be greater or equal to 0.') |
e309822b C |
80 | } |
81 | } | |
e1b49ee5 C |
82 | |
83 | this.INDEX_URL = { | |
84 | VALIDATORS: [ Validators.required, Validators.pattern(/^https:\/\//) ], | |
85 | MESSAGES: { | |
86 | 'required': this.i18n('Index URL is required.'), | |
87 | 'pattern': this.i18n('Index URL should be a URL') | |
88 | } | |
89 | } | |
e309822b C |
90 | } |
91 | } |