2 import { Component, OnInit } from '@angular/core'
3 import { ActivatedRoute, Router } from '@angular/router'
4 import { ConfigService } from '@app/+admin/config/shared/config.service'
5 import { Notifier } from '@app/core'
6 import { ServerService } from '@app/core/server/server.service'
9 CACHE_CAPTIONS_SIZE_VALIDATOR,
10 CACHE_PREVIEWS_SIZE_VALIDATOR,
11 CONCURRENCY_VALIDATOR,
13 INSTANCE_NAME_VALIDATOR,
14 INSTANCE_SHORT_DESCRIPTION_VALIDATOR,
15 SEARCH_INDEX_URL_VALIDATOR,
16 SERVICES_TWITTER_USERNAME_VALIDATOR,
17 SIGNUP_LIMIT_VALIDATOR,
18 TRANSCODING_THREADS_VALIDATOR
19 } from '@app/shared/form-validators/custom-config-validators'
20 import { USER_VIDEO_QUOTA_DAILY_VALIDATOR, USER_VIDEO_QUOTA_VALIDATOR } from '@app/shared/form-validators/user-validators'
21 import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
22 import { CustomConfig, ServerConfig } from '@shared/models'
23 import { forkJoin } from 'rxjs'
24 import { SelectOptionsItem } from 'src/types/select-options-item.model'
25 import { EditConfigurationService } from './edit-configuration.service'
28 selector: 'my-edit-custom-config',
29 templateUrl: './edit-custom-config.component.html',
30 styleUrls: [ './edit-custom-config.component.scss' ]
32 export class EditCustomConfigComponent extends FormReactive implements OnInit {
35 customConfig: CustomConfig
36 serverConfig: ServerConfig
38 languageItems: SelectOptionsItem[] = []
39 categoryItems: SelectOptionsItem[] = []
42 private router: Router,
43 private route: ActivatedRoute,
44 protected formValidatorService: FormValidatorService,
45 private notifier: Notifier,
46 private configService: ConfigService,
47 private serverService: ServerService,
48 private editConfigurationService: EditConfigurationService
54 this.serverConfig = this.serverService.getTmpConfig()
55 this.serverService.getConfig()
56 .subscribe(config => {
57 this.serverConfig = config
60 const formGroupData: { [key in keyof CustomConfig ]: any } = {
62 name: INSTANCE_NAME_VALIDATOR,
63 shortDescription: INSTANCE_SHORT_DESCRIPTION_VALIDATOR,
67 defaultNSFWPolicy: null,
73 moderationInformation: null,
75 maintenanceLifetime: null,
78 hardwareInformation: null,
83 defaultClientRoute: null,
95 username: SERVICES_TWITTER_USERNAME_VALIDATOR,
101 size: CACHE_PREVIEWS_SIZE_VALIDATOR
104 size: CACHE_CAPTIONS_SIZE_VALIDATOR
109 limit: SIGNUP_LIMIT_VALIDATOR,
110 requiresEmailVerification: null
114 concurrency: CONCURRENCY_VALIDATOR,
132 email: ADMIN_EMAIL_VALIDATOR
138 videoQuota: USER_VIDEO_QUOTA_VALIDATOR,
139 videoQuotaDaily: USER_VIDEO_QUOTA_DAILY_VALIDATOR
143 threads: TRANSCODING_THREADS_VALIDATOR,
144 allowAdditionalExtensions: null,
145 allowAudioFiles: null,
147 concurrency: CONCURRENCY_VALIDATOR,
160 maxInstanceLives: null,
166 threads: TRANSCODING_THREADS_VALIDATOR,
191 indexUrl: INDEX_URL_VALIDATOR
208 url: SEARCH_INDEX_URL_VALIDATOR,
209 disableLocalSearch: null,
210 isDefaultSearch: null
215 const defaultValues = {
226 for (const resolution of this.editConfigurationService.getVODResolutions()) {
227 defaultValues.transcoding.resolutions[resolution.id] = 'false'
228 formGroupData.transcoding.resolutions[resolution.id] = null
231 for (const resolution of this.editConfigurationService.getLiveResolutions()) {
232 defaultValues.live.transcoding.resolutions[resolution.id] = 'false'
233 formGroupData.live.transcoding.resolutions[resolution.id] = null
236 this.buildForm(formGroupData)
238 if (this.route.snapshot.fragment) {
239 this.onNavChange(this.route.snapshot.fragment)
242 this.loadConfigAndUpdateForm()
243 this.loadCategoriesAndLanguages()
246 async formValidated () {
247 const value: CustomConfig = this.form.getRawValue()
249 this.configService.updateCustomConfig(value)
252 this.customConfig = res
254 // Reload general configuration
255 this.serverService.resetConfig()
259 this.notifier.success($localize`Configuration updated.`)
262 err => this.notifier.error(err.message)
266 hasConsistentOptions () {
267 if (this.hasLiveAllowReplayConsistentOptions()) return true
272 hasLiveAllowReplayConsistentOptions () {
274 this.editConfigurationService.isTranscodingEnabled(this.form) === false &&
275 this.editConfigurationService.isLiveEnabled(this.form) &&
276 this.form.value['live']['allowReplay'] === true
284 onNavChange (newActiveNav: string) {
285 this.activeNav = newActiveNav
287 this.router.navigate([], { fragment: this.activeNav })
290 private updateForm () {
291 this.form.patchValue(this.customConfig)
294 private loadConfigAndUpdateForm () {
295 this.configService.getCustomConfig()
296 .subscribe(config => {
297 this.customConfig = config
300 // Force form validation
304 err => this.notifier.error(err.message)
308 private loadCategoriesAndLanguages () {
310 this.serverService.getVideoLanguages(),
311 this.serverService.getVideoCategories()
313 ([ languages, categories ]) => {
314 this.languageItems = languages.map(l => ({ label: l.label, id: l.id }))
315 this.categoryItems = categories.map(l => ({ label: l.label, id: l.id + '' }))
318 err => this.notifier.error(err.message)