]>
Commit | Line | Data |
---|---|---|
fd206f0b | 1 | import { Component, OnInit } from '@angular/core' |
fd206f0b C |
2 | import { ConfigService } from '@app/+admin/config/shared/config.service' |
3 | import { ServerService } from '@app/core/server/server.service' | |
e309822b | 4 | import { CustomConfigValidatorsService, FormReactive, UserValidatorsService } from '@app/shared' |
f8b2c1b4 | 5 | import { Notifier } from '@app/core' |
09cababd | 6 | import { CustomConfig } from '../../../../../../shared/models/server/custom-config.model' |
b1d40cff | 7 | import { I18n } from '@ngx-translate/i18n-polyfill' |
d18d6478 | 8 | import { BuildFormDefaultValues, FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' |
fd206f0b C |
9 | |
10 | @Component({ | |
11 | selector: 'my-edit-custom-config', | |
12 | templateUrl: './edit-custom-config.component.html', | |
13 | styleUrls: [ './edit-custom-config.component.scss' ] | |
14 | }) | |
15 | export class EditCustomConfigComponent extends FormReactive implements OnInit { | |
bee0abff | 16 | customConfig: CustomConfig |
bee0abff | 17 | |
3827c3b3 C |
18 | resolutions: string[] = [] |
19 | transcodingThreadOptions: { label: string, value: number }[] = [] | |
fd206f0b | 20 | |
fd206f0b | 21 | constructor ( |
d18d6478 | 22 | protected formValidatorService: FormValidatorService, |
e309822b C |
23 | private customConfigValidatorsService: CustomConfigValidatorsService, |
24 | private userValidatorsService: UserValidatorsService, | |
f8b2c1b4 | 25 | private notifier: Notifier, |
fd206f0b | 26 | private configService: ConfigService, |
1f30a185 | 27 | private serverService: ServerService, |
b1d40cff | 28 | private i18n: I18n |
fd206f0b C |
29 | ) { |
30 | super() | |
3827c3b3 C |
31 | |
32 | this.resolutions = [ | |
33 | this.i18n('240p'), | |
34 | this.i18n('360p'), | |
35 | this.i18n('480p'), | |
36 | this.i18n('720p'), | |
37 | this.i18n('1080p') | |
38 | ] | |
39 | ||
40 | this.transcodingThreadOptions = [ | |
41 | { value: 0, label: this.i18n('Auto (via ffmpeg)') }, | |
42 | { value: 1, label: '1' }, | |
43 | { value: 2, label: '2' }, | |
44 | { value: 4, label: '4' }, | |
45 | { value: 8, label: '8' } | |
46 | ] | |
fd206f0b C |
47 | } |
48 | ||
41a676db | 49 | get videoQuotaOptions () { |
3827c3b3 | 50 | return this.configService.videoQuotaOptions |
41a676db C |
51 | } |
52 | ||
53 | get videoQuotaDailyOptions () { | |
3827c3b3 | 54 | return this.configService.videoQuotaDailyOptions |
41a676db C |
55 | } |
56 | ||
fd206f0b | 57 | getResolutionKey (resolution: string) { |
3866f1a0 | 58 | return 'transcoding.resolutions.' + resolution |
fd206f0b C |
59 | } |
60 | ||
d18d6478 | 61 | ngOnInit () { |
3866f1a0 C |
62 | const formGroupData: { [key in keyof CustomConfig ]: any } = { |
63 | instance: { | |
64 | name: this.customConfigValidatorsService.INSTANCE_NAME, | |
65 | shortDescription: this.customConfigValidatorsService.INSTANCE_SHORT_DESCRIPTION, | |
66 | description: null, | |
67 | terms: null, | |
68 | defaultClientRoute: null, | |
69 | defaultNSFWPolicy: null, | |
70 | customizations: { | |
71 | javascript: null, | |
72 | css: null | |
73 | } | |
74 | }, | |
75 | services: { | |
76 | twitter: { | |
77 | username: this.customConfigValidatorsService.SERVICES_TWITTER_USERNAME, | |
78 | whitelisted: null | |
79 | } | |
80 | }, | |
81 | cache: { | |
82 | previews: { | |
83 | size: this.customConfigValidatorsService.CACHE_PREVIEWS_SIZE | |
84 | }, | |
85 | captions: { | |
86 | size: this.customConfigValidatorsService.CACHE_CAPTIONS_SIZE | |
87 | } | |
88 | }, | |
89 | signup: { | |
90 | enabled: null, | |
91 | limit: this.customConfigValidatorsService.SIGNUP_LIMIT, | |
92 | requiresEmailVerification: null | |
93 | }, | |
94 | import: { | |
95 | videos: { | |
96 | http: { | |
97 | enabled: null | |
98 | }, | |
99 | torrent: { | |
100 | enabled: null | |
101 | } | |
102 | } | |
103 | }, | |
104 | admin: { | |
105 | email: this.customConfigValidatorsService.ADMIN_EMAIL | |
106 | }, | |
107 | contactForm: { | |
108 | enabled: null | |
109 | }, | |
110 | user: { | |
111 | videoQuota: this.userValidatorsService.USER_VIDEO_QUOTA, | |
112 | videoQuotaDaily: this.userValidatorsService.USER_VIDEO_QUOTA_DAILY | |
113 | }, | |
114 | transcoding: { | |
115 | enabled: null, | |
116 | threads: this.customConfigValidatorsService.TRANSCODING_THREADS, | |
117 | allowAdditionalExtensions: null, | |
118 | resolutions: {} | |
119 | } | |
fd206f0b C |
120 | } |
121 | ||
3866f1a0 C |
122 | const defaultValues = { |
123 | transcoding: { | |
124 | resolutions: {} | |
125 | } | |
126 | } | |
fd206f0b | 127 | for (const resolution of this.resolutions) { |
3866f1a0 C |
128 | defaultValues.transcoding.resolutions[resolution] = 'false' |
129 | formGroupData.transcoding.resolutions[resolution] = null | |
fd206f0b C |
130 | } |
131 | ||
d18d6478 | 132 | this.buildForm(formGroupData) |
fd206f0b C |
133 | |
134 | this.configService.getCustomConfig() | |
135 | .subscribe( | |
136 | res => { | |
137 | this.customConfig = res | |
138 | ||
139 | this.updateForm() | |
d63fd4f7 C |
140 | // Force form validation |
141 | this.forceCheck() | |
fd206f0b C |
142 | }, |
143 | ||
f8b2c1b4 | 144 | err => this.notifier.error(err.message) |
fd206f0b C |
145 | ) |
146 | } | |
147 | ||
148 | isTranscodingEnabled () { | |
3866f1a0 | 149 | return this.form.value['transcoding']['enabled'] === true |
fd206f0b C |
150 | } |
151 | ||
152 | isSignupEnabled () { | |
3866f1a0 | 153 | return this.form.value['signup']['enabled'] === true |
fd206f0b C |
154 | } |
155 | ||
1f30a185 | 156 | async formValidated () { |
3866f1a0 | 157 | this.configService.updateCustomConfig(this.form.value) |
fd206f0b C |
158 | .subscribe( |
159 | res => { | |
160 | this.customConfig = res | |
161 | ||
162 | // Reload general configuration | |
163 | this.serverService.loadConfig() | |
164 | ||
165 | this.updateForm() | |
66b16caf | 166 | |
f8b2c1b4 | 167 | this.notifier.success(this.i18n('Configuration updated.')) |
fd206f0b C |
168 | }, |
169 | ||
f8b2c1b4 | 170 | err => this.notifier.error(err.message) |
fd206f0b C |
171 | ) |
172 | } | |
173 | ||
174 | private updateForm () { | |
3866f1a0 | 175 | this.form.patchValue(this.customConfig) |
fd206f0b C |
176 | } |
177 | ||
178 | } |