]>
Commit | Line | Data |
---|---|---|
5f46d28c | 1 | |
2539932e | 2 | import omit from 'lodash-es/omit' |
4e55c132 C |
3 | import { forkJoin } from 'rxjs' |
4 | import { SelectOptionsItem } from 'src/types/select-options-item.model' | |
5f46d28c | 5 | import { Component, OnInit } from '@angular/core' |
53e4e201 | 6 | import { ActivatedRoute, Router } from '@angular/router' |
67ed6552 C |
7 | import { ConfigService } from '@app/+admin/config/shared/config.service' |
8 | import { Notifier } from '@app/core' | |
9 | import { ServerService } from '@app/core/server/server.service' | |
52c4976f | 10 | import { |
7ed1edbb C |
11 | ADMIN_EMAIL_VALIDATOR, |
12 | CACHE_CAPTIONS_SIZE_VALIDATOR, | |
13 | CACHE_PREVIEWS_SIZE_VALIDATOR, | |
9129b769 | 14 | CONCURRENCY_VALIDATOR, |
7ed1edbb C |
15 | INDEX_URL_VALIDATOR, |
16 | INSTANCE_NAME_VALIDATOR, | |
17 | INSTANCE_SHORT_DESCRIPTION_VALIDATOR, | |
4e55c132 C |
18 | MAX_INSTANCE_LIVES_VALIDATOR, |
19 | MAX_LIVE_DURATION_VALIDATOR, | |
20 | MAX_USER_LIVES_VALIDATOR, | |
5c5bcea2 | 21 | MAX_VIDEO_CHANNELS_PER_USER_VALIDATOR, |
7ed1edbb C |
22 | SEARCH_INDEX_URL_VALIDATOR, |
23 | SERVICES_TWITTER_USERNAME_VALIDATOR, | |
24 | SIGNUP_LIMIT_VALIDATOR, | |
1f256e7d | 25 | SIGNUP_MINIMUM_AGE_VALIDATOR, |
5c5bcea2 | 26 | TRANSCODING_THREADS_VALIDATOR |
7ed1edbb C |
27 | } from '@app/shared/form-validators/custom-config-validators' |
28 | import { USER_VIDEO_QUOTA_DAILY_VALIDATOR, USER_VIDEO_QUOTA_VALIDATOR } from '@app/shared/form-validators/user-validators' | |
5c5bcea2 | 29 | import { FormReactive, FormReactiveService } from '@app/shared/shared-forms' |
2539932e | 30 | import { CustomPageService } from '@app/shared/shared-main/custom-page' |
2989628b | 31 | import { CustomConfig, CustomPage, HTMLServerConfig } from '@shared/models' |
5f46d28c | 32 | import { EditConfigurationService } from './edit-configuration.service' |
fd206f0b | 33 | |
2539932e C |
34 | type ComponentCustomConfig = CustomConfig & { |
35 | instanceCustomHomepage: CustomPage | |
36 | } | |
37 | ||
fd206f0b C |
38 | @Component({ |
39 | selector: 'my-edit-custom-config', | |
40 | templateUrl: './edit-custom-config.component.html', | |
41 | styleUrls: [ './edit-custom-config.component.scss' ] | |
42 | }) | |
5f46d28c C |
43 | export class EditCustomConfigComponent extends FormReactive implements OnInit { |
44 | activeNav: string | |
45e0d669 | 45 | |
2539932e | 46 | customConfig: ComponentCustomConfig |
2989628b | 47 | serverConfig: HTMLServerConfig |
80ac2e55 | 48 | |
2539932e C |
49 | homepage: CustomPage |
50 | ||
52c4976f C |
51 | languageItems: SelectOptionsItem[] = [] |
52 | categoryItems: SelectOptionsItem[] = [] | |
ccc00cb2 | 53 | |
fd206f0b | 54 | constructor ( |
5c5bcea2 | 55 | protected formReactiveService: FormReactiveService, |
53e4e201 C |
56 | private router: Router, |
57 | private route: ActivatedRoute, | |
f8b2c1b4 | 58 | private notifier: Notifier, |
fd206f0b | 59 | private configService: ConfigService, |
2539932e | 60 | private customPage: CustomPageService, |
5f46d28c C |
61 | private serverService: ServerService, |
62 | private editConfigurationService: EditConfigurationService | |
fd206f0b C |
63 | ) { |
64 | super() | |
fd206f0b C |
65 | } |
66 | ||
d18d6478 | 67 | ngOnInit () { |
2989628b | 68 | this.serverConfig = this.serverService.getHTMLConfig() |
ba430d75 | 69 | |
2539932e | 70 | const formGroupData: { [key in keyof ComponentCustomConfig ]: any } = { |
3866f1a0 | 71 | instance: { |
7ed1edbb C |
72 | name: INSTANCE_NAME_VALIDATOR, |
73 | shortDescription: INSTANCE_SHORT_DESCRIPTION_VALIDATOR, | |
3866f1a0 | 74 | description: null, |
ccc00cb2 | 75 | |
f8802489 | 76 | isNSFW: false, |
3866f1a0 | 77 | defaultNSFWPolicy: null, |
ccc00cb2 C |
78 | |
79 | terms: null, | |
80 | codeOfConduct: null, | |
8ae03c37 C |
81 | |
82 | creationReason: null, | |
ccc00cb2 C |
83 | moderationInformation: null, |
84 | administrator: null, | |
85 | maintenanceLifetime: null, | |
86 | businessModel: null, | |
87 | ||
be04c6fd C |
88 | hardwareInformation: null, |
89 | ||
ccc00cb2 C |
90 | categories: null, |
91 | languages: null, | |
92 | ||
93 | defaultClientRoute: null, | |
94 | ||
3866f1a0 C |
95 | customizations: { |
96 | javascript: null, | |
97 | css: null | |
98 | } | |
99 | }, | |
7cd4d2ba C |
100 | theme: { |
101 | default: null | |
102 | }, | |
3866f1a0 C |
103 | services: { |
104 | twitter: { | |
7ed1edbb | 105 | username: SERVICES_TWITTER_USERNAME_VALIDATOR, |
3866f1a0 C |
106 | whitelisted: null |
107 | } | |
108 | }, | |
0bc53e20 C |
109 | client: { |
110 | videos: { | |
111 | miniature: { | |
112 | preferAuthorDisplayName: null | |
113 | } | |
114 | }, | |
115 | menu: { | |
116 | login: { | |
117 | redirectOnSingleExternalAuth: null | |
118 | } | |
119 | } | |
120 | }, | |
3866f1a0 C |
121 | cache: { |
122 | previews: { | |
7ed1edbb | 123 | size: CACHE_PREVIEWS_SIZE_VALIDATOR |
3866f1a0 C |
124 | }, |
125 | captions: { | |
7ed1edbb | 126 | size: CACHE_CAPTIONS_SIZE_VALIDATOR |
b3d5cb92 C |
127 | }, |
128 | torrents: { | |
129 | size: CACHE_CAPTIONS_SIZE_VALIDATOR | |
3866f1a0 C |
130 | } |
131 | }, | |
132 | signup: { | |
133 | enabled: null, | |
7ed1edbb | 134 | limit: SIGNUP_LIMIT_VALIDATOR, |
9589907c | 135 | requiresApproval: null, |
1f256e7d P |
136 | requiresEmailVerification: null, |
137 | minimumAge: SIGNUP_MINIMUM_AGE_VALIDATOR | |
3866f1a0 C |
138 | }, |
139 | import: { | |
140 | videos: { | |
9129b769 | 141 | concurrency: CONCURRENCY_VALIDATOR, |
3866f1a0 C |
142 | http: { |
143 | enabled: null | |
144 | }, | |
145 | torrent: { | |
146 | enabled: null | |
147 | } | |
2a491182 F |
148 | }, |
149 | videoChannelSynchronization: { | |
150 | enabled: null | |
3866f1a0 C |
151 | } |
152 | }, | |
ba5d4a84 RK |
153 | trending: { |
154 | videos: { | |
155 | algorithms: { | |
156 | enabled: null, | |
157 | default: null | |
158 | } | |
159 | } | |
160 | }, | |
3866f1a0 | 161 | admin: { |
7ed1edbb | 162 | email: ADMIN_EMAIL_VALIDATOR |
3866f1a0 C |
163 | }, |
164 | contactForm: { | |
165 | enabled: null | |
166 | }, | |
167 | user: { | |
b302c80d W |
168 | history: { |
169 | videos: { | |
170 | enabled: null | |
171 | } | |
172 | }, | |
7ed1edbb C |
173 | videoQuota: USER_VIDEO_QUOTA_VALIDATOR, |
174 | videoQuotaDaily: USER_VIDEO_QUOTA_DAILY_VALIDATOR | |
3866f1a0 | 175 | }, |
754b6f5f FC |
176 | videoChannels: { |
177 | maxPerUser: MAX_VIDEO_CHANNELS_PER_USER_VALIDATOR | |
178 | }, | |
3866f1a0 C |
179 | transcoding: { |
180 | enabled: null, | |
7ed1edbb | 181 | threads: TRANSCODING_THREADS_VALIDATOR, |
3866f1a0 | 182 | allowAdditionalExtensions: null, |
536598cf | 183 | allowAudioFiles: null, |
80ac2e55 | 184 | profile: null, |
9129b769 | 185 | concurrency: CONCURRENCY_VALIDATOR, |
5d9e4eaa | 186 | resolutions: {}, |
84cae54e | 187 | alwaysTranscodeOriginalResolution: null, |
5d9e4eaa C |
188 | hls: { |
189 | enabled: null | |
5a71acd2 C |
190 | }, |
191 | webtorrent: { | |
192 | enabled: null | |
118626c8 C |
193 | }, |
194 | remoteRunners: { | |
195 | enabled: null | |
5d9e4eaa | 196 | } |
7ccddd7b | 197 | }, |
c6c0fa6c C |
198 | live: { |
199 | enabled: null, | |
200 | ||
4e55c132 C |
201 | maxDuration: MAX_LIVE_DURATION_VALIDATOR, |
202 | maxInstanceLives: MAX_INSTANCE_LIVES_VALIDATOR, | |
203 | maxUserLives: MAX_USER_LIVES_VALIDATOR, | |
fb719404 | 204 | allowReplay: null, |
f443a746 C |
205 | latencySetting: { |
206 | enabled: null | |
207 | }, | |
fb719404 | 208 | |
c6c0fa6c C |
209 | transcoding: { |
210 | enabled: null, | |
211 | threads: TRANSCODING_THREADS_VALIDATOR, | |
80ac2e55 | 212 | profile: null, |
84cae54e | 213 | resolutions: {}, |
118626c8 C |
214 | alwaysTranscodeOriginalResolution: null, |
215 | remoteRunners: { | |
216 | enabled: null | |
217 | } | |
c6c0fa6c C |
218 | } |
219 | }, | |
92e66e04 | 220 | videoStudio: { |
c729caf6 C |
221 | enabled: null |
222 | }, | |
7ccddd7b JM |
223 | autoBlacklist: { |
224 | videos: { | |
225 | ofUsers: { | |
226 | enabled: null | |
227 | } | |
228 | } | |
0dc64777 C |
229 | }, |
230 | followers: { | |
231 | instance: { | |
232 | enabled: null, | |
233 | manualApproval: null | |
234 | } | |
e1b49ee5 C |
235 | }, |
236 | followings: { | |
237 | instance: { | |
238 | autoFollowBack: { | |
239 | enabled: null | |
240 | }, | |
241 | autoFollowIndex: { | |
242 | enabled: null, | |
7ed1edbb | 243 | indexUrl: INDEX_URL_VALIDATOR |
e1b49ee5 C |
244 | } |
245 | } | |
72c33e71 C |
246 | }, |
247 | broadcastMessage: { | |
248 | enabled: null, | |
249 | level: null, | |
250 | dismissable: null, | |
251 | message: null | |
5fb2e288 C |
252 | }, |
253 | search: { | |
254 | remoteUri: { | |
255 | users: null, | |
256 | anonymous: null | |
257 | }, | |
258 | searchIndex: { | |
259 | enabled: null, | |
7ed1edbb | 260 | url: SEARCH_INDEX_URL_VALIDATOR, |
5fb2e288 C |
261 | disableLocalSearch: null, |
262 | isDefaultSearch: null | |
263 | } | |
2539932e C |
264 | }, |
265 | ||
266 | instanceCustomHomepage: { | |
267 | content: null | |
3866f1a0 | 268 | } |
fd206f0b C |
269 | } |
270 | ||
3866f1a0 C |
271 | const defaultValues = { |
272 | transcoding: { | |
273 | resolutions: {} | |
c6c0fa6c C |
274 | }, |
275 | live: { | |
276 | transcoding: { | |
277 | resolutions: {} | |
278 | } | |
3866f1a0 C |
279 | } |
280 | } | |
c6c0fa6c | 281 | |
5f46d28c | 282 | for (const resolution of this.editConfigurationService.getVODResolutions()) { |
00aa1f0d C |
283 | defaultValues.transcoding.resolutions[resolution.id] = 'false' |
284 | formGroupData.transcoding.resolutions[resolution.id] = null | |
fd206f0b C |
285 | } |
286 | ||
5f46d28c | 287 | for (const resolution of this.editConfigurationService.getLiveResolutions()) { |
c6c0fa6c C |
288 | defaultValues.live.transcoding.resolutions[resolution.id] = 'false' |
289 | formGroupData.live.transcoding.resolutions[resolution.id] = null | |
290 | } | |
291 | ||
d18d6478 | 292 | this.buildForm(formGroupData) |
16a173bb | 293 | |
5f46d28c C |
294 | if (this.route.snapshot.fragment) { |
295 | this.onNavChange(this.route.snapshot.fragment) | |
45e0d669 | 296 | } |
5fb2e288 | 297 | |
5f46d28c C |
298 | this.loadConfigAndUpdateForm() |
299 | this.loadCategoriesAndLanguages() | |
cf0c8ee5 C |
300 | |
301 | if (!this.isUpdateAllowed()) { | |
8d8a037e JB |
302 | this.form.disable() |
303 | } | |
3da68f0a RK |
304 | } |
305 | ||
98ab5dc8 | 306 | formValidated () { |
8b69f9f0 C |
307 | this.forceCheck() |
308 | if (!this.form.valid) return | |
309 | ||
2539932e | 310 | const value: ComponentCustomConfig = this.form.getRawValue() |
210856a7 | 311 | |
2539932e C |
312 | forkJoin([ |
313 | this.configService.updateCustomConfig(omit(value, 'instanceCustomHomepage')), | |
314 | this.customPage.updateInstanceHomepage(value.instanceCustomHomepage.content) | |
315 | ]) | |
1378c0d3 C |
316 | .subscribe({ |
317 | next: ([ resConfig ]) => { | |
2539932e C |
318 | const instanceCustomHomepage = { |
319 | content: value.instanceCustomHomepage.content | |
320 | } | |
321 | ||
322 | this.customConfig = { ...resConfig, instanceCustomHomepage } | |
fd206f0b C |
323 | |
324 | // Reload general configuration | |
ba430d75 | 325 | this.serverService.resetConfig() |
9df52d66 C |
326 | .subscribe(config => { |
327 | this.serverConfig = config | |
328 | }) | |
fd206f0b C |
329 | |
330 | this.updateForm() | |
66b16caf | 331 | |
66357162 | 332 | this.notifier.success($localize`Configuration updated.`) |
fd206f0b C |
333 | }, |
334 | ||
1378c0d3 C |
335 | error: err => this.notifier.error(err.message) |
336 | }) | |
fd206f0b C |
337 | } |
338 | ||
cf0c8ee5 C |
339 | isUpdateAllowed () { |
340 | return this.serverConfig.webadmin.configuration.edition.allowed === true | |
341 | } | |
342 | ||
fb719404 C |
343 | hasConsistentOptions () { |
344 | if (this.hasLiveAllowReplayConsistentOptions()) return true | |
345 | ||
346 | return false | |
347 | } | |
348 | ||
349 | hasLiveAllowReplayConsistentOptions () { | |
5f46d28c C |
350 | if ( |
351 | this.editConfigurationService.isTranscodingEnabled(this.form) === false && | |
352 | this.editConfigurationService.isLiveEnabled(this.form) && | |
353 | this.form.value['live']['allowReplay'] === true | |
354 | ) { | |
fb719404 C |
355 | return false |
356 | } | |
357 | ||
358 | return true | |
359 | } | |
360 | ||
53e4e201 C |
361 | onNavChange (newActiveNav: string) { |
362 | this.activeNav = newActiveNav | |
363 | ||
364 | this.router.navigate([], { fragment: this.activeNav }) | |
365 | } | |
366 | ||
45ba09fe C |
367 | grabAllErrors (errorObjectArg?: any) { |
368 | const errorObject = errorObjectArg || this.formErrors | |
369 | ||
370 | let acc: string[] = [] | |
371 | ||
372 | for (const key of Object.keys(errorObject)) { | |
373 | const value = errorObject[key] | |
374 | if (!value) continue | |
375 | ||
376 | if (typeof value === 'string') { | |
377 | acc.push(value) | |
378 | } else { | |
379 | acc = acc.concat(this.grabAllErrors(value)) | |
380 | } | |
381 | } | |
382 | ||
383 | return acc | |
384 | } | |
385 | ||
fd206f0b | 386 | private updateForm () { |
3866f1a0 | 387 | this.form.patchValue(this.customConfig) |
fd206f0b | 388 | } |
04cda1d7 | 389 | |
5f46d28c | 390 | private loadConfigAndUpdateForm () { |
2539932e C |
391 | forkJoin([ |
392 | this.configService.getCustomConfig(), | |
393 | this.customPage.getInstanceHomepage() | |
1378c0d3 C |
394 | ]).subscribe({ |
395 | next: ([ config, homepage ]) => { | |
2539932e | 396 | this.customConfig = { ...config, instanceCustomHomepage: homepage } |
04cda1d7 | 397 | |
04cda1d7 | 398 | this.updateForm() |
8b69f9f0 | 399 | this.markAllAsDirty() |
04cda1d7 C |
400 | }, |
401 | ||
1378c0d3 C |
402 | error: err => this.notifier.error(err.message) |
403 | }) | |
04cda1d7 C |
404 | } |
405 | ||
5f46d28c C |
406 | private loadCategoriesAndLanguages () { |
407 | forkJoin([ | |
408 | this.serverService.getVideoLanguages(), | |
409 | this.serverService.getVideoCategories() | |
1378c0d3 C |
410 | ]).subscribe({ |
411 | next: ([ languages, categories ]) => { | |
5f46d28c C |
412 | this.languageItems = languages.map(l => ({ label: l.label, id: l.id })) |
413 | this.categoryItems = categories.map(l => ({ label: l.label, id: l.id + '' })) | |
414 | }, | |
16a173bb | 415 | |
1378c0d3 C |
416 | error: err => this.notifier.error(err.message) |
417 | }) | |
16a173bb | 418 | } |
fd206f0b | 419 | } |