1 import { Component, OnInit } from '@angular/core'
2 import { ConfigService } from '@app/+admin/config/shared/config.service'
3 import { ServerService } from '@app/core/server/server.service'
4 import { CustomConfigValidatorsService, FormReactive, UserValidatorsService } from '@app/shared'
5 import { Notifier } from '@app/core'
6 import { CustomConfig } from '../../../../../../shared/models/server/custom-config.model'
7 import { I18n } from '@ngx-translate/i18n-polyfill'
8 import { BuildFormDefaultValues, FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
11 selector: 'my-edit-custom-config',
12 templateUrl: './edit-custom-config.component.html',
13 styleUrls: [ './edit-custom-config.component.scss' ]
15 export class EditCustomConfigComponent extends FormReactive implements OnInit {
16 customConfig: CustomConfig
18 resolutions: string[] = []
19 transcodingThreadOptions: { label: string, value: number }[] = []
22 protected formValidatorService: FormValidatorService,
23 private customConfigValidatorsService: CustomConfigValidatorsService,
24 private userValidatorsService: UserValidatorsService,
25 private notifier: Notifier,
26 private configService: ConfigService,
27 private serverService: ServerService,
40 this.transcodingThreadOptions = [
41 { value: 0, label: this.i18n('Auto (via ffmpeg)') },
42 { value: 1, label: '1' },
43 { value: 2, label: '2' },
44 { value: 4, label: '4' },
45 { value: 8, label: '8' }
49 get videoQuotaOptions () {
50 return this.configService.videoQuotaOptions
53 get videoQuotaDailyOptions () {
54 return this.configService.videoQuotaDailyOptions
57 getResolutionKey (resolution: string) {
58 return 'transcoding.resolutions.' + resolution
62 const formGroupData: { [key in keyof CustomConfig ]: any } = {
64 name: this.customConfigValidatorsService.INSTANCE_NAME,
65 shortDescription: this.customConfigValidatorsService.INSTANCE_SHORT_DESCRIPTION,
68 defaultClientRoute: null,
69 defaultNSFWPolicy: null,
77 username: this.customConfigValidatorsService.SERVICES_TWITTER_USERNAME,
83 size: this.customConfigValidatorsService.CACHE_PREVIEWS_SIZE
86 size: this.customConfigValidatorsService.CACHE_CAPTIONS_SIZE
91 limit: this.customConfigValidatorsService.SIGNUP_LIMIT,
92 requiresEmailVerification: null
105 email: this.customConfigValidatorsService.ADMIN_EMAIL
111 videoQuota: this.userValidatorsService.USER_VIDEO_QUOTA,
112 videoQuotaDaily: this.userValidatorsService.USER_VIDEO_QUOTA_DAILY
116 threads: this.customConfigValidatorsService.TRANSCODING_THREADS,
117 allowAdditionalExtensions: null,
122 const defaultValues = {
127 for (const resolution of this.resolutions) {
128 defaultValues.transcoding.resolutions[resolution] = 'false'
129 formGroupData.transcoding.resolutions[resolution] = null
132 this.buildForm(formGroupData)
134 this.configService.getCustomConfig()
137 this.customConfig = res
140 // Force form validation
144 err => this.notifier.error(err.message)
148 isTranscodingEnabled () {
149 return this.form.value['transcoding']['enabled'] === true
153 return this.form.value['signup']['enabled'] === true
156 async formValidated () {
157 this.configService.updateCustomConfig(this.form.value)
160 this.customConfig = res
162 // Reload general configuration
163 this.serverService.loadConfig()
167 this.notifier.success(this.i18n('Configuration updated.'))
170 err => this.notifier.error(err.message)
174 private updateForm () {
175 this.form.patchValue(this.customConfig)