2 import omit from 'lodash-es/omit'
3 import { forkJoin } from 'rxjs'
4 import { SelectOptionsItem } from 'src/types/select-options-item.model'
5 import { Component, OnInit } from '@angular/core'
6 import { ActivatedRoute, Router } from '@angular/router'
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'
11 ADMIN_EMAIL_VALIDATOR,
12 CACHE_CAPTIONS_SIZE_VALIDATOR,
13 CACHE_PREVIEWS_SIZE_VALIDATOR,
14 CONCURRENCY_VALIDATOR,
16 INSTANCE_NAME_VALIDATOR,
17 INSTANCE_SHORT_DESCRIPTION_VALIDATOR,
18 MAX_INSTANCE_LIVES_VALIDATOR,
19 MAX_LIVE_DURATION_VALIDATOR,
20 MAX_USER_LIVES_VALIDATOR,
21 MAX_VIDEO_CHANNELS_PER_USER_VALIDATOR,
22 SEARCH_INDEX_URL_VALIDATOR,
23 SERVICES_TWITTER_USERNAME_VALIDATOR,
24 SIGNUP_LIMIT_VALIDATOR,
25 SIGNUP_MINIMUM_AGE_VALIDATOR,
26 TRANSCODING_THREADS_VALIDATOR
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'
29 import { FormReactive, FormReactiveService } from '@app/shared/shared-forms'
30 import { CustomPageService } from '@app/shared/shared-main/custom-page'
31 import { CustomConfig, CustomPage, HTMLServerConfig } from '@shared/models'
32 import { EditConfigurationService } from './edit-configuration.service'
34 type ComponentCustomConfig = CustomConfig & {
35 instanceCustomHomepage: CustomPage
39 selector: 'my-edit-custom-config',
40 templateUrl: './edit-custom-config.component.html',
41 styleUrls: [ './edit-custom-config.component.scss' ]
43 export class EditCustomConfigComponent extends FormReactive implements OnInit {
46 customConfig: ComponentCustomConfig
47 serverConfig: HTMLServerConfig
51 languageItems: SelectOptionsItem[] = []
52 categoryItems: SelectOptionsItem[] = []
55 protected formReactiveService: FormReactiveService,
56 private router: Router,
57 private route: ActivatedRoute,
58 private notifier: Notifier,
59 private configService: ConfigService,
60 private customPage: CustomPageService,
61 private serverService: ServerService,
62 private editConfigurationService: EditConfigurationService
68 this.serverConfig = this.serverService.getHTMLConfig()
70 const formGroupData: { [key in keyof ComponentCustomConfig ]: any } = {
72 name: INSTANCE_NAME_VALIDATOR,
73 shortDescription: INSTANCE_SHORT_DESCRIPTION_VALIDATOR,
77 defaultNSFWPolicy: null,
83 moderationInformation: null,
85 maintenanceLifetime: null,
88 hardwareInformation: null,
93 defaultClientRoute: null,
105 username: SERVICES_TWITTER_USERNAME_VALIDATOR,
112 preferAuthorDisplayName: null
117 redirectOnSingleExternalAuth: null
123 size: CACHE_PREVIEWS_SIZE_VALIDATOR
126 size: CACHE_CAPTIONS_SIZE_VALIDATOR
129 size: CACHE_CAPTIONS_SIZE_VALIDATOR
134 limit: SIGNUP_LIMIT_VALIDATOR,
135 requiresApproval: null,
136 requiresEmailVerification: null,
137 minimumAge: SIGNUP_MINIMUM_AGE_VALIDATOR
141 concurrency: CONCURRENCY_VALIDATOR,
149 videoChannelSynchronization: {
162 email: ADMIN_EMAIL_VALIDATOR
168 videoQuota: USER_VIDEO_QUOTA_VALIDATOR,
169 videoQuotaDaily: USER_VIDEO_QUOTA_DAILY_VALIDATOR
172 maxPerUser: MAX_VIDEO_CHANNELS_PER_USER_VALIDATOR
176 threads: TRANSCODING_THREADS_VALIDATOR,
177 allowAdditionalExtensions: null,
178 allowAudioFiles: null,
180 concurrency: CONCURRENCY_VALIDATOR,
182 alwaysTranscodeOriginalResolution: null,
193 maxDuration: MAX_LIVE_DURATION_VALIDATOR,
194 maxInstanceLives: MAX_INSTANCE_LIVES_VALIDATOR,
195 maxUserLives: MAX_USER_LIVES_VALIDATOR,
203 threads: TRANSCODING_THREADS_VALIDATOR,
206 alwaysTranscodeOriginalResolution: null
232 indexUrl: INDEX_URL_VALIDATOR
249 url: SEARCH_INDEX_URL_VALIDATOR,
250 disableLocalSearch: null,
251 isDefaultSearch: null
255 instanceCustomHomepage: {
260 const defaultValues = {
271 for (const resolution of this.editConfigurationService.getVODResolutions()) {
272 defaultValues.transcoding.resolutions[resolution.id] = 'false'
273 formGroupData.transcoding.resolutions[resolution.id] = null
276 for (const resolution of this.editConfigurationService.getLiveResolutions()) {
277 defaultValues.live.transcoding.resolutions[resolution.id] = 'false'
278 formGroupData.live.transcoding.resolutions[resolution.id] = null
281 this.buildForm(formGroupData)
283 if (this.route.snapshot.fragment) {
284 this.onNavChange(this.route.snapshot.fragment)
287 this.loadConfigAndUpdateForm()
288 this.loadCategoriesAndLanguages()
290 if (!this.isUpdateAllowed()) {
297 if (!this.form.valid) return
299 const value: ComponentCustomConfig = this.form.getRawValue()
302 this.configService.updateCustomConfig(omit(value, 'instanceCustomHomepage')),
303 this.customPage.updateInstanceHomepage(value.instanceCustomHomepage.content)
306 next: ([ resConfig ]) => {
307 const instanceCustomHomepage = {
308 content: value.instanceCustomHomepage.content
311 this.customConfig = { ...resConfig, instanceCustomHomepage }
313 // Reload general configuration
314 this.serverService.resetConfig()
315 .subscribe(config => {
316 this.serverConfig = config
321 this.notifier.success($localize`Configuration updated.`)
324 error: err => this.notifier.error(err.message)
329 return this.serverConfig.webadmin.configuration.edition.allowed === true
332 hasConsistentOptions () {
333 if (this.hasLiveAllowReplayConsistentOptions()) return true
338 hasLiveAllowReplayConsistentOptions () {
340 this.editConfigurationService.isTranscodingEnabled(this.form) === false &&
341 this.editConfigurationService.isLiveEnabled(this.form) &&
342 this.form.value['live']['allowReplay'] === true
350 onNavChange (newActiveNav: string) {
351 this.activeNav = newActiveNav
353 this.router.navigate([], { fragment: this.activeNav })
356 grabAllErrors (errorObjectArg?: any) {
357 const errorObject = errorObjectArg || this.formErrors
359 let acc: string[] = []
361 for (const key of Object.keys(errorObject)) {
362 const value = errorObject[key]
365 if (typeof value === 'string') {
368 acc = acc.concat(this.grabAllErrors(value))
375 private updateForm () {
376 this.form.patchValue(this.customConfig)
379 private loadConfigAndUpdateForm () {
381 this.configService.getCustomConfig(),
382 this.customPage.getInstanceHomepage()
384 next: ([ config, homepage ]) => {
385 this.customConfig = { ...config, instanceCustomHomepage: homepage }
388 this.markAllAsDirty()
391 error: err => this.notifier.error(err.message)
395 private loadCategoriesAndLanguages () {
397 this.serverService.getVideoLanguages(),
398 this.serverService.getVideoCategories()
400 next: ([ languages, categories ]) => {
401 this.languageItems = languages.map(l => ({ label: l.label, id: l.id }))
402 this.categoryItems = categories.map(l => ({ label: l.label, id: l.id + '' }))
405 error: err => this.notifier.error(err.message)