]>
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 | |
1f30a185 C |
21 | private oldCustomJavascript: string |
22 | private oldCustomCSS: string | |
23 | ||
fd206f0b | 24 | constructor ( |
d18d6478 | 25 | protected formValidatorService: FormValidatorService, |
e309822b C |
26 | private customConfigValidatorsService: CustomConfigValidatorsService, |
27 | private userValidatorsService: UserValidatorsService, | |
f8b2c1b4 | 28 | private notifier: Notifier, |
fd206f0b | 29 | private configService: ConfigService, |
1f30a185 | 30 | private serverService: ServerService, |
b1d40cff | 31 | private i18n: I18n |
fd206f0b C |
32 | ) { |
33 | super() | |
3827c3b3 C |
34 | |
35 | this.resolutions = [ | |
36 | this.i18n('240p'), | |
37 | this.i18n('360p'), | |
38 | this.i18n('480p'), | |
39 | this.i18n('720p'), | |
40 | this.i18n('1080p') | |
41 | ] | |
42 | ||
43 | this.transcodingThreadOptions = [ | |
44 | { value: 0, label: this.i18n('Auto (via ffmpeg)') }, | |
45 | { value: 1, label: '1' }, | |
46 | { value: 2, label: '2' }, | |
47 | { value: 4, label: '4' }, | |
48 | { value: 8, label: '8' } | |
49 | ] | |
fd206f0b C |
50 | } |
51 | ||
41a676db | 52 | get videoQuotaOptions () { |
3827c3b3 | 53 | return this.configService.videoQuotaOptions |
41a676db C |
54 | } |
55 | ||
56 | get videoQuotaDailyOptions () { | |
3827c3b3 | 57 | return this.configService.videoQuotaDailyOptions |
41a676db C |
58 | } |
59 | ||
fd206f0b C |
60 | getResolutionKey (resolution: string) { |
61 | return 'transcodingResolution' + resolution | |
62 | } | |
63 | ||
d18d6478 | 64 | ngOnInit () { |
c199c427 | 65 | const formGroupData: { [key: string]: any } = { |
e309822b C |
66 | instanceName: this.customConfigValidatorsService.INSTANCE_NAME, |
67 | instanceShortDescription: this.customConfigValidatorsService.INSTANCE_SHORT_DESCRIPTION, | |
d18d6478 C |
68 | instanceDescription: null, |
69 | instanceTerms: null, | |
70 | instanceDefaultClientRoute: null, | |
71 | instanceDefaultNSFWPolicy: null, | |
e309822b | 72 | servicesTwitterUsername: this.customConfigValidatorsService.SERVICES_TWITTER_USERNAME, |
d18d6478 | 73 | servicesTwitterWhitelisted: null, |
e309822b | 74 | cachePreviewsSize: this.customConfigValidatorsService.CACHE_PREVIEWS_SIZE, |
40e87e9e | 75 | cacheCaptionsSize: this.customConfigValidatorsService.CACHE_CAPTIONS_SIZE, |
d18d6478 | 76 | signupEnabled: null, |
e309822b | 77 | signupLimit: this.customConfigValidatorsService.SIGNUP_LIMIT, |
d9eaee39 | 78 | signupRequiresEmailVerification: null, |
5d08a6a7 | 79 | importVideosHttpEnabled: null, |
a84b8fa5 | 80 | importVideosTorrentEnabled: null, |
e309822b C |
81 | adminEmail: this.customConfigValidatorsService.ADMIN_EMAIL, |
82 | userVideoQuota: this.userValidatorsService.USER_VIDEO_QUOTA, | |
bee0abff | 83 | userVideoQuotaDaily: this.userValidatorsService.USER_VIDEO_QUOTA_DAILY, |
e309822b | 84 | transcodingThreads: this.customConfigValidatorsService.TRANSCODING_THREADS, |
14e2014a | 85 | transcodingAllowAdditionalExtensions: null, |
d18d6478 C |
86 | transcodingEnabled: null, |
87 | customizationJavascript: null, | |
88 | customizationCSS: null | |
fd206f0b C |
89 | } |
90 | ||
d18d6478 | 91 | const defaultValues: BuildFormDefaultValues = {} |
fd206f0b C |
92 | for (const resolution of this.resolutions) { |
93 | const key = this.getResolutionKey(resolution) | |
d18d6478 C |
94 | defaultValues[key] = 'false' |
95 | formGroupData[key] = null | |
fd206f0b C |
96 | } |
97 | ||
d18d6478 | 98 | this.buildForm(formGroupData) |
fd206f0b C |
99 | |
100 | this.configService.getCustomConfig() | |
101 | .subscribe( | |
102 | res => { | |
103 | this.customConfig = res | |
104 | ||
1f30a185 C |
105 | this.oldCustomCSS = this.customConfig.instance.customizations.css |
106 | this.oldCustomJavascript = this.customConfig.instance.customizations.javascript | |
107 | ||
fd206f0b | 108 | this.updateForm() |
d63fd4f7 C |
109 | // Force form validation |
110 | this.forceCheck() | |
fd206f0b C |
111 | }, |
112 | ||
f8b2c1b4 | 113 | err => this.notifier.error(err.message) |
fd206f0b C |
114 | ) |
115 | } | |
116 | ||
117 | isTranscodingEnabled () { | |
118 | return this.form.value['transcodingEnabled'] === true | |
119 | } | |
120 | ||
121 | isSignupEnabled () { | |
122 | return this.form.value['signupEnabled'] === true | |
123 | } | |
124 | ||
1f30a185 | 125 | async formValidated () { |
901637bb | 126 | const data: CustomConfig = { |
66b16caf C |
127 | instance: { |
128 | name: this.form.value['instanceName'], | |
2e3a0215 | 129 | shortDescription: this.form.value['instanceShortDescription'], |
66b16caf | 130 | description: this.form.value['instanceDescription'], |
00b5556c | 131 | terms: this.form.value['instanceTerms'], |
901637bb | 132 | defaultClientRoute: this.form.value['instanceDefaultClientRoute'], |
0883b324 | 133 | defaultNSFWPolicy: this.form.value['instanceDefaultNSFWPolicy'], |
00b5556c C |
134 | customizations: { |
135 | javascript: this.form.value['customizationJavascript'], | |
136 | css: this.form.value['customizationCSS'] | |
137 | } | |
66b16caf | 138 | }, |
8be1afa1 C |
139 | services: { |
140 | twitter: { | |
141 | username: this.form.value['servicesTwitterUsername'], | |
142 | whitelisted: this.form.value['servicesTwitterWhitelisted'] | |
143 | } | |
144 | }, | |
fd206f0b C |
145 | cache: { |
146 | previews: { | |
147 | size: this.form.value['cachePreviewsSize'] | |
40e87e9e C |
148 | }, |
149 | captions: { | |
150 | size: this.form.value['cacheCaptionsSize'] | |
fd206f0b C |
151 | } |
152 | }, | |
153 | signup: { | |
154 | enabled: this.form.value['signupEnabled'], | |
d9eaee39 JM |
155 | limit: this.form.value['signupLimit'], |
156 | requiresEmailVerification: this.form.value['signupRequiresEmailVerification'] | |
fd206f0b C |
157 | }, |
158 | admin: { | |
159 | email: this.form.value['adminEmail'] | |
160 | }, | |
161 | user: { | |
bee0abff FA |
162 | videoQuota: this.form.value['userVideoQuota'], |
163 | videoQuotaDaily: this.form.value['userVideoQuotaDaily'] | |
fd206f0b C |
164 | }, |
165 | transcoding: { | |
166 | enabled: this.form.value['transcodingEnabled'], | |
14e2014a | 167 | allowAdditionalExtensions: this.form.value['transcodingAllowAdditionalExtensions'], |
fd206f0b C |
168 | threads: this.form.value['transcodingThreads'], |
169 | resolutions: { | |
170 | '240p': this.form.value[this.getResolutionKey('240p')], | |
171 | '360p': this.form.value[this.getResolutionKey('360p')], | |
172 | '480p': this.form.value[this.getResolutionKey('480p')], | |
173 | '720p': this.form.value[this.getResolutionKey('720p')], | |
174 | '1080p': this.form.value[this.getResolutionKey('1080p')] | |
175 | } | |
5d08a6a7 C |
176 | }, |
177 | import: { | |
178 | videos: { | |
179 | http: { | |
180 | enabled: this.form.value['importVideosHttpEnabled'] | |
a84b8fa5 C |
181 | }, |
182 | torrent: { | |
183 | enabled: this.form.value['importVideosTorrentEnabled'] | |
5d08a6a7 C |
184 | } |
185 | } | |
fd206f0b C |
186 | } |
187 | } | |
188 | ||
189 | this.configService.updateCustomConfig(data) | |
190 | .subscribe( | |
191 | res => { | |
192 | this.customConfig = res | |
193 | ||
194 | // Reload general configuration | |
195 | this.serverService.loadConfig() | |
196 | ||
197 | this.updateForm() | |
66b16caf | 198 | |
f8b2c1b4 | 199 | this.notifier.success(this.i18n('Configuration updated.')) |
fd206f0b C |
200 | }, |
201 | ||
f8b2c1b4 | 202 | err => this.notifier.error(err.message) |
fd206f0b C |
203 | ) |
204 | } | |
205 | ||
206 | private updateForm () { | |
c199c427 | 207 | const data: { [key: string]: any } = { |
66b16caf | 208 | instanceName: this.customConfig.instance.name, |
2e3a0215 | 209 | instanceShortDescription: this.customConfig.instance.shortDescription, |
66b16caf C |
210 | instanceDescription: this.customConfig.instance.description, |
211 | instanceTerms: this.customConfig.instance.terms, | |
901637bb | 212 | instanceDefaultClientRoute: this.customConfig.instance.defaultClientRoute, |
0883b324 | 213 | instanceDefaultNSFWPolicy: this.customConfig.instance.defaultNSFWPolicy, |
8be1afa1 C |
214 | servicesTwitterUsername: this.customConfig.services.twitter.username, |
215 | servicesTwitterWhitelisted: this.customConfig.services.twitter.whitelisted, | |
fd206f0b | 216 | cachePreviewsSize: this.customConfig.cache.previews.size, |
16f7022b | 217 | cacheCaptionsSize: this.customConfig.cache.captions.size, |
fd206f0b C |
218 | signupEnabled: this.customConfig.signup.enabled, |
219 | signupLimit: this.customConfig.signup.limit, | |
d9eaee39 | 220 | signupRequiresEmailVerification: this.customConfig.signup.requiresEmailVerification, |
fd206f0b C |
221 | adminEmail: this.customConfig.admin.email, |
222 | userVideoQuota: this.customConfig.user.videoQuota, | |
bee0abff | 223 | userVideoQuotaDaily: this.customConfig.user.videoQuotaDaily, |
fd206f0b | 224 | transcodingThreads: this.customConfig.transcoding.threads, |
00b5556c | 225 | transcodingEnabled: this.customConfig.transcoding.enabled, |
14e2014a | 226 | transcodingAllowAdditionalExtensions: this.customConfig.transcoding.allowAdditionalExtensions, |
00b5556c | 227 | customizationJavascript: this.customConfig.instance.customizations.javascript, |
5d08a6a7 | 228 | customizationCSS: this.customConfig.instance.customizations.css, |
a84b8fa5 C |
229 | importVideosHttpEnabled: this.customConfig.import.videos.http.enabled, |
230 | importVideosTorrentEnabled: this.customConfig.import.videos.torrent.enabled | |
fd206f0b C |
231 | } |
232 | ||
233 | for (const resolution of this.resolutions) { | |
234 | const key = this.getResolutionKey(resolution) | |
235 | data[key] = this.customConfig.transcoding.resolutions[resolution] | |
236 | } | |
237 | ||
238 | this.form.patchValue(data) | |
239 | } | |
240 | ||
241 | } |