diff options
Diffstat (limited to 'client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts')
-rw-r--r-- | client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts | 234 |
1 files changed, 75 insertions, 159 deletions
diff --git a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts index 4983b0425..654a076b0 100644 --- a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts +++ b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts | |||
@@ -1,9 +1,8 @@ | |||
1 | import { Component, OnInit } from '@angular/core' | 1 | import { Component, OnInit } from '@angular/core' |
2 | import { ConfigService } from '@app/+admin/config/shared/config.service' | 2 | import { ConfigService } from '@app/+admin/config/shared/config.service' |
3 | import { ConfirmService } from '@app/core' | ||
4 | import { ServerService } from '@app/core/server/server.service' | 3 | import { ServerService } from '@app/core/server/server.service' |
5 | import { CustomConfigValidatorsService, FormReactive, UserValidatorsService } from '@app/shared' | 4 | import { CustomConfigValidatorsService, FormReactive, UserValidatorsService } from '@app/shared' |
6 | import { NotificationsService } from 'angular2-notifications' | 5 | import { Notifier } from '@app/core' |
7 | import { CustomConfig } from '../../../../../../shared/models/server/custom-config.model' | 6 | import { CustomConfig } from '../../../../../../shared/models/server/custom-config.model' |
8 | import { I18n } from '@ngx-translate/i18n-polyfill' | 7 | import { I18n } from '@ngx-translate/i18n-polyfill' |
9 | import { BuildFormDefaultValues, FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' | 8 | import { BuildFormDefaultValues, FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' |
@@ -19,17 +18,13 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit { | |||
19 | resolutions: string[] = [] | 18 | resolutions: string[] = [] |
20 | transcodingThreadOptions: { label: string, value: number }[] = [] | 19 | transcodingThreadOptions: { label: string, value: number }[] = [] |
21 | 20 | ||
22 | private oldCustomJavascript: string | ||
23 | private oldCustomCSS: string | ||
24 | |||
25 | constructor ( | 21 | constructor ( |
26 | protected formValidatorService: FormValidatorService, | 22 | protected formValidatorService: FormValidatorService, |
27 | private customConfigValidatorsService: CustomConfigValidatorsService, | 23 | private customConfigValidatorsService: CustomConfigValidatorsService, |
28 | private userValidatorsService: UserValidatorsService, | 24 | private userValidatorsService: UserValidatorsService, |
29 | private notificationsService: NotificationsService, | 25 | private notifier: Notifier, |
30 | private configService: ConfigService, | 26 | private configService: ConfigService, |
31 | private serverService: ServerService, | 27 | private serverService: ServerService, |
32 | private confirmService: ConfirmService, | ||
33 | private i18n: I18n | 28 | private i18n: I18n |
34 | ) { | 29 | ) { |
35 | super() | 30 | super() |
@@ -60,40 +55,78 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit { | |||
60 | } | 55 | } |
61 | 56 | ||
62 | getResolutionKey (resolution: string) { | 57 | getResolutionKey (resolution: string) { |
63 | return 'transcodingResolution' + resolution | 58 | return 'transcoding.resolutions.' + resolution |
64 | } | 59 | } |
65 | 60 | ||
66 | ngOnInit () { | 61 | ngOnInit () { |
67 | const formGroupData = { | 62 | const formGroupData: { [key in keyof CustomConfig ]: any } = { |
68 | instanceName: this.customConfigValidatorsService.INSTANCE_NAME, | 63 | instance: { |
69 | instanceShortDescription: this.customConfigValidatorsService.INSTANCE_SHORT_DESCRIPTION, | 64 | name: this.customConfigValidatorsService.INSTANCE_NAME, |
70 | instanceDescription: null, | 65 | shortDescription: this.customConfigValidatorsService.INSTANCE_SHORT_DESCRIPTION, |
71 | instanceTerms: null, | 66 | description: null, |
72 | instanceDefaultClientRoute: null, | 67 | terms: null, |
73 | instanceDefaultNSFWPolicy: null, | 68 | defaultClientRoute: null, |
74 | servicesTwitterUsername: this.customConfigValidatorsService.SERVICES_TWITTER_USERNAME, | 69 | defaultNSFWPolicy: null, |
75 | servicesTwitterWhitelisted: null, | 70 | customizations: { |
76 | cachePreviewsSize: this.customConfigValidatorsService.CACHE_PREVIEWS_SIZE, | 71 | javascript: null, |
77 | cacheCaptionsSize: this.customConfigValidatorsService.CACHE_CAPTIONS_SIZE, | 72 | css: null |
78 | signupEnabled: null, | 73 | } |
79 | signupLimit: this.customConfigValidatorsService.SIGNUP_LIMIT, | 74 | }, |
80 | signupRequiresEmailVerification: null, | 75 | services: { |
81 | importVideosHttpEnabled: null, | 76 | twitter: { |
82 | importVideosTorrentEnabled: null, | 77 | username: this.customConfigValidatorsService.SERVICES_TWITTER_USERNAME, |
83 | adminEmail: this.customConfigValidatorsService.ADMIN_EMAIL, | 78 | whitelisted: null |
84 | userVideoQuota: this.userValidatorsService.USER_VIDEO_QUOTA, | 79 | } |
85 | userVideoQuotaDaily: this.userValidatorsService.USER_VIDEO_QUOTA_DAILY, | 80 | }, |
86 | transcodingThreads: this.customConfigValidatorsService.TRANSCODING_THREADS, | 81 | cache: { |
87 | transcodingEnabled: null, | 82 | previews: { |
88 | customizationJavascript: null, | 83 | size: this.customConfigValidatorsService.CACHE_PREVIEWS_SIZE |
89 | customizationCSS: null | 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 | } | ||
90 | } | 120 | } |
91 | 121 | ||
92 | const defaultValues: BuildFormDefaultValues = {} | 122 | const defaultValues = { |
123 | transcoding: { | ||
124 | resolutions: {} | ||
125 | } | ||
126 | } | ||
93 | for (const resolution of this.resolutions) { | 127 | for (const resolution of this.resolutions) { |
94 | const key = this.getResolutionKey(resolution) | 128 | defaultValues.transcoding.resolutions[resolution] = 'false' |
95 | defaultValues[key] = 'false' | 129 | formGroupData.transcoding.resolutions[resolution] = null |
96 | formGroupData[key] = null | ||
97 | } | 130 | } |
98 | 131 | ||
99 | this.buildForm(formGroupData) | 132 | this.buildForm(formGroupData) |
@@ -103,112 +136,25 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit { | |||
103 | res => { | 136 | res => { |
104 | this.customConfig = res | 137 | this.customConfig = res |
105 | 138 | ||
106 | this.oldCustomCSS = this.customConfig.instance.customizations.css | ||
107 | this.oldCustomJavascript = this.customConfig.instance.customizations.javascript | ||
108 | |||
109 | this.updateForm() | 139 | this.updateForm() |
110 | // Force form validation | 140 | // Force form validation |
111 | this.forceCheck() | 141 | this.forceCheck() |
112 | }, | 142 | }, |
113 | 143 | ||
114 | err => this.notificationsService.error(this.i18n('Error'), err.message) | 144 | err => this.notifier.error(err.message) |
115 | ) | 145 | ) |
116 | } | 146 | } |
117 | 147 | ||
118 | isTranscodingEnabled () { | 148 | isTranscodingEnabled () { |
119 | return this.form.value['transcodingEnabled'] === true | 149 | return this.form.value['transcoding']['enabled'] === true |
120 | } | 150 | } |
121 | 151 | ||
122 | isSignupEnabled () { | 152 | isSignupEnabled () { |
123 | return this.form.value['signupEnabled'] === true | 153 | return this.form.value['signup']['enabled'] === true |
124 | } | 154 | } |
125 | 155 | ||
126 | async formValidated () { | 156 | async formValidated () { |
127 | const newCustomizationJavascript = this.form.value['customizationJavascript'] | 157 | this.configService.updateCustomConfig(this.form.value) |
128 | const newCustomizationCSS = this.form.value['customizationCSS'] | ||
129 | |||
130 | const customizations = [] | ||
131 | if (newCustomizationJavascript && newCustomizationJavascript !== this.oldCustomJavascript) customizations.push('JavaScript') | ||
132 | if (newCustomizationCSS && newCustomizationCSS !== this.oldCustomCSS) customizations.push('CSS') | ||
133 | |||
134 | if (customizations.length !== 0) { | ||
135 | const customizationsText = customizations.join('/') | ||
136 | |||
137 | // FIXME: i18n service does not support string concatenation | ||
138 | const message = this.i18n('You set custom {{customizationsText}}. ', { customizationsText }) + | ||
139 | this.i18n('This could lead to security issues or bugs if you do not understand it. ') + | ||
140 | this.i18n('Are you sure you want to update the configuration?') | ||
141 | |||
142 | const label = this.i18n('Please type') + ` "I understand the ${customizationsText} I set" ` + this.i18n('to confirm.') | ||
143 | const expectedInputValue = `I understand the ${customizationsText} I set` | ||
144 | |||
145 | const confirmRes = await this.confirmService.confirmWithInput(message, label, expectedInputValue) | ||
146 | if (confirmRes === false) return | ||
147 | } | ||
148 | |||
149 | const data: CustomConfig = { | ||
150 | instance: { | ||
151 | name: this.form.value['instanceName'], | ||
152 | shortDescription: this.form.value['instanceShortDescription'], | ||
153 | description: this.form.value['instanceDescription'], | ||
154 | terms: this.form.value['instanceTerms'], | ||
155 | defaultClientRoute: this.form.value['instanceDefaultClientRoute'], | ||
156 | defaultNSFWPolicy: this.form.value['instanceDefaultNSFWPolicy'], | ||
157 | customizations: { | ||
158 | javascript: this.form.value['customizationJavascript'], | ||
159 | css: this.form.value['customizationCSS'] | ||
160 | } | ||
161 | }, | ||
162 | services: { | ||
163 | twitter: { | ||
164 | username: this.form.value['servicesTwitterUsername'], | ||
165 | whitelisted: this.form.value['servicesTwitterWhitelisted'] | ||
166 | } | ||
167 | }, | ||
168 | cache: { | ||
169 | previews: { | ||
170 | size: this.form.value['cachePreviewsSize'] | ||
171 | }, | ||
172 | captions: { | ||
173 | size: this.form.value['cacheCaptionsSize'] | ||
174 | } | ||
175 | }, | ||
176 | signup: { | ||
177 | enabled: this.form.value['signupEnabled'], | ||
178 | limit: this.form.value['signupLimit'], | ||
179 | requiresEmailVerification: this.form.value['signupRequiresEmailVerification'] | ||
180 | }, | ||
181 | admin: { | ||
182 | email: this.form.value['adminEmail'] | ||
183 | }, | ||
184 | user: { | ||
185 | videoQuota: this.form.value['userVideoQuota'], | ||
186 | videoQuotaDaily: this.form.value['userVideoQuotaDaily'] | ||
187 | }, | ||
188 | transcoding: { | ||
189 | enabled: this.form.value['transcodingEnabled'], | ||
190 | threads: this.form.value['transcodingThreads'], | ||
191 | resolutions: { | ||
192 | '240p': this.form.value[this.getResolutionKey('240p')], | ||
193 | '360p': this.form.value[this.getResolutionKey('360p')], | ||
194 | '480p': this.form.value[this.getResolutionKey('480p')], | ||
195 | '720p': this.form.value[this.getResolutionKey('720p')], | ||
196 | '1080p': this.form.value[this.getResolutionKey('1080p')] | ||
197 | } | ||
198 | }, | ||
199 | import: { | ||
200 | videos: { | ||
201 | http: { | ||
202 | enabled: this.form.value['importVideosHttpEnabled'] | ||
203 | }, | ||
204 | torrent: { | ||
205 | enabled: this.form.value['importVideosTorrentEnabled'] | ||
206 | } | ||
207 | } | ||
208 | } | ||
209 | } | ||
210 | |||
211 | this.configService.updateCustomConfig(data) | ||
212 | .subscribe( | 158 | .subscribe( |
213 | res => { | 159 | res => { |
214 | this.customConfig = res | 160 | this.customConfig = res |
@@ -218,45 +164,15 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit { | |||
218 | 164 | ||
219 | this.updateForm() | 165 | this.updateForm() |
220 | 166 | ||
221 | this.notificationsService.success(this.i18n('Success'), this.i18n('Configuration updated.')) | 167 | this.notifier.success(this.i18n('Configuration updated.')) |
222 | }, | 168 | }, |
223 | 169 | ||
224 | err => this.notificationsService.error(this.i18n('Error'), err.message) | 170 | err => this.notifier.error(err.message) |
225 | ) | 171 | ) |
226 | } | 172 | } |
227 | 173 | ||
228 | private updateForm () { | 174 | private updateForm () { |
229 | const data = { | 175 | this.form.patchValue(this.customConfig) |
230 | instanceName: this.customConfig.instance.name, | ||
231 | instanceShortDescription: this.customConfig.instance.shortDescription, | ||
232 | instanceDescription: this.customConfig.instance.description, | ||
233 | instanceTerms: this.customConfig.instance.terms, | ||
234 | instanceDefaultClientRoute: this.customConfig.instance.defaultClientRoute, | ||
235 | instanceDefaultNSFWPolicy: this.customConfig.instance.defaultNSFWPolicy, | ||
236 | servicesTwitterUsername: this.customConfig.services.twitter.username, | ||
237 | servicesTwitterWhitelisted: this.customConfig.services.twitter.whitelisted, | ||
238 | cachePreviewsSize: this.customConfig.cache.previews.size, | ||
239 | cacheCaptionsSize: this.customConfig.cache.captions.size, | ||
240 | signupEnabled: this.customConfig.signup.enabled, | ||
241 | signupLimit: this.customConfig.signup.limit, | ||
242 | signupRequiresEmailVerification: this.customConfig.signup.requiresEmailVerification, | ||
243 | adminEmail: this.customConfig.admin.email, | ||
244 | userVideoQuota: this.customConfig.user.videoQuota, | ||
245 | userVideoQuotaDaily: this.customConfig.user.videoQuotaDaily, | ||
246 | transcodingThreads: this.customConfig.transcoding.threads, | ||
247 | transcodingEnabled: this.customConfig.transcoding.enabled, | ||
248 | customizationJavascript: this.customConfig.instance.customizations.javascript, | ||
249 | customizationCSS: this.customConfig.instance.customizations.css, | ||
250 | importVideosHttpEnabled: this.customConfig.import.videos.http.enabled, | ||
251 | importVideosTorrentEnabled: this.customConfig.import.videos.torrent.enabled | ||
252 | } | ||
253 | |||
254 | for (const resolution of this.resolutions) { | ||
255 | const key = this.getResolutionKey(resolution) | ||
256 | data[key] = this.customConfig.transcoding.resolutions[resolution] | ||
257 | } | ||
258 | |||
259 | this.form.patchValue(data) | ||
260 | } | 176 | } |
261 | 177 | ||
262 | } | 178 | } |