2 import { forkJoin } from 'rxjs'
3 import { SelectOptionsItem } from 'src/types/select-options-item.model'
4 import { Component, OnInit } from '@angular/core'
5 import { ActivatedRoute, Router } from '@angular/router'
6 import { ConfigService } from '@app/+admin/config/shared/config.service'
7 import { Notifier } from '@app/core'
8 import { ServerService } from '@app/core/server/server.service'
10 ADMIN_EMAIL_VALIDATOR,
11 CACHE_CAPTIONS_SIZE_VALIDATOR,
12 CACHE_PREVIEWS_SIZE_VALIDATOR,
13 CONCURRENCY_VALIDATOR,
15 INSTANCE_NAME_VALIDATOR,
16 INSTANCE_SHORT_DESCRIPTION_VALIDATOR,
17 MAX_INSTANCE_LIVES_VALIDATOR,
18 MAX_LIVE_DURATION_VALIDATOR,
19 MAX_USER_LIVES_VALIDATOR,
20 SEARCH_INDEX_URL_VALIDATOR,
21 SERVICES_TWITTER_USERNAME_VALIDATOR,
22 SIGNUP_LIMIT_VALIDATOR,
23 TRANSCODING_THREADS_VALIDATOR
24 } from '@app/shared/form-validators/custom-config-validators'
25 import { USER_VIDEO_QUOTA_DAILY_VALIDATOR, USER_VIDEO_QUOTA_VALIDATOR } from '@app/shared/form-validators/user-validators'
26 import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
27 import { CustomConfig, ServerConfig } from '@shared/models'
28 import { EditConfigurationService } from './edit-configuration.service'
31 selector: 'my-edit-custom-config',
32 templateUrl: './edit-custom-config.component.html',
33 styleUrls: [ './edit-custom-config.component.scss' ]
35 export class EditCustomConfigComponent extends FormReactive implements OnInit {
38 customConfig: CustomConfig
39 serverConfig: ServerConfig
41 languageItems: SelectOptionsItem[] = []
42 categoryItems: SelectOptionsItem[] = []
45 private router: Router,
46 private route: ActivatedRoute,
47 protected formValidatorService: FormValidatorService,
48 private notifier: Notifier,
49 private configService: ConfigService,
50 private serverService: ServerService,
51 private editConfigurationService: EditConfigurationService
57 this.serverConfig = this.serverService.getTmpConfig()
58 this.serverService.getConfig()
59 .subscribe(config => {
60 this.serverConfig = config
63 const formGroupData: { [key in keyof CustomConfig ]: any } = {
65 name: INSTANCE_NAME_VALIDATOR,
66 shortDescription: INSTANCE_SHORT_DESCRIPTION_VALIDATOR,
70 defaultNSFWPolicy: null,
76 moderationInformation: null,
78 maintenanceLifetime: null,
81 hardwareInformation: null,
86 defaultClientRoute: null,
98 username: SERVICES_TWITTER_USERNAME_VALIDATOR,
104 size: CACHE_PREVIEWS_SIZE_VALIDATOR
107 size: CACHE_CAPTIONS_SIZE_VALIDATOR
112 limit: SIGNUP_LIMIT_VALIDATOR,
113 requiresEmailVerification: null
117 concurrency: CONCURRENCY_VALIDATOR,
135 email: ADMIN_EMAIL_VALIDATOR
141 videoQuota: USER_VIDEO_QUOTA_VALIDATOR,
142 videoQuotaDaily: USER_VIDEO_QUOTA_DAILY_VALIDATOR
146 threads: TRANSCODING_THREADS_VALIDATOR,
147 allowAdditionalExtensions: null,
148 allowAudioFiles: null,
150 concurrency: CONCURRENCY_VALIDATOR,
162 maxDuration: MAX_LIVE_DURATION_VALIDATOR,
163 maxInstanceLives: MAX_INSTANCE_LIVES_VALIDATOR,
164 maxUserLives: MAX_USER_LIVES_VALIDATOR,
169 threads: TRANSCODING_THREADS_VALIDATOR,
194 indexUrl: INDEX_URL_VALIDATOR
211 url: SEARCH_INDEX_URL_VALIDATOR,
212 disableLocalSearch: null,
213 isDefaultSearch: null
218 const defaultValues = {
229 for (const resolution of this.editConfigurationService.getVODResolutions()) {
230 defaultValues.transcoding.resolutions[resolution.id] = 'false'
231 formGroupData.transcoding.resolutions[resolution.id] = null
234 for (const resolution of this.editConfigurationService.getLiveResolutions()) {
235 defaultValues.live.transcoding.resolutions[resolution.id] = 'false'
236 formGroupData.live.transcoding.resolutions[resolution.id] = null
239 this.buildForm(formGroupData)
241 if (this.route.snapshot.fragment) {
242 this.onNavChange(this.route.snapshot.fragment)
245 this.loadConfigAndUpdateForm()
246 this.loadCategoriesAndLanguages()
249 async formValidated () {
250 const value: CustomConfig = this.form.getRawValue()
252 this.configService.updateCustomConfig(value)
255 this.customConfig = res
257 // Reload general configuration
258 this.serverService.resetConfig()
262 this.notifier.success($localize`Configuration updated.`)
265 err => this.notifier.error(err.message)
269 hasConsistentOptions () {
270 if (this.hasLiveAllowReplayConsistentOptions()) return true
275 hasLiveAllowReplayConsistentOptions () {
277 this.editConfigurationService.isTranscodingEnabled(this.form) === false &&
278 this.editConfigurationService.isLiveEnabled(this.form) &&
279 this.form.value['live']['allowReplay'] === true
287 onNavChange (newActiveNav: string) {
288 this.activeNav = newActiveNav
290 this.router.navigate([], { fragment: this.activeNav })
293 private updateForm () {
294 this.form.patchValue(this.customConfig)
297 private loadConfigAndUpdateForm () {
298 this.configService.getCustomConfig()
299 .subscribe(config => {
300 this.customConfig = config
303 // Force form validation
307 err => this.notifier.error(err.message)
311 private loadCategoriesAndLanguages () {
313 this.serverService.getVideoLanguages(),
314 this.serverService.getVideoCategories()
316 ([ languages, categories ]) => {
317 this.languageItems = languages.map(l => ({ label: l.label, id: l.id }))
318 this.categoryItems = categories.map(l => ({ label: l.label, id: l.id + '' }))
321 err => this.notifier.error(err.message)