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 { 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: { id: string, label: 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,
35 label: this.i18n('240p')
39 label: this.i18n('360p')
43 label: this.i18n('480p')
47 label: this.i18n('720p')
51 label: this.i18n('1080p')
55 label: this.i18n('2160p')
59 this.transcodingThreadOptions = [
60 { value: 0, label: this.i18n('Auto (via ffmpeg)') },
61 { value: 1, label: '1' },
62 { value: 2, label: '2' },
63 { value: 4, label: '4' },
64 { value: 8, label: '8' }
68 get videoQuotaOptions () {
69 return this.configService.videoQuotaOptions
72 get videoQuotaDailyOptions () {
73 return this.configService.videoQuotaDailyOptions
76 get availableThemes () {
77 return this.serverService.getConfig().theme.registered
81 getResolutionKey (resolution: string) {
82 return 'transcoding.resolutions.' + resolution
86 const formGroupData: { [key in keyof CustomConfig ]: any } = {
88 name: this.customConfigValidatorsService.INSTANCE_NAME,
89 shortDescription: this.customConfigValidatorsService.INSTANCE_SHORT_DESCRIPTION,
92 defaultClientRoute: null,
94 defaultNSFWPolicy: null,
105 username: this.customConfigValidatorsService.SERVICES_TWITTER_USERNAME,
111 size: this.customConfigValidatorsService.CACHE_PREVIEWS_SIZE
114 size: this.customConfigValidatorsService.CACHE_CAPTIONS_SIZE
119 limit: this.customConfigValidatorsService.SIGNUP_LIMIT,
120 requiresEmailVerification: null
133 email: this.customConfigValidatorsService.ADMIN_EMAIL
139 videoQuota: this.userValidatorsService.USER_VIDEO_QUOTA,
140 videoQuotaDaily: this.userValidatorsService.USER_VIDEO_QUOTA_DAILY
144 threads: this.customConfigValidatorsService.TRANSCODING_THREADS,
145 allowAdditionalExtensions: null,
146 allowAudioFiles: null,
164 const defaultValues = {
169 for (const resolution of this.resolutions) {
170 defaultValues.transcoding.resolutions[resolution.id] = 'false'
171 formGroupData.transcoding.resolutions[resolution.id] = null
174 this.buildForm(formGroupData)
176 this.configService.getCustomConfig()
179 this.customConfig = res
182 // Force form validation
186 err => this.notifier.error(err.message)
190 isTranscodingEnabled () {
191 return this.form.value['transcoding']['enabled'] === true
195 return this.form.value['signup']['enabled'] === true
198 async formValidated () {
199 this.configService.updateCustomConfig(this.form.value)
202 this.customConfig = res
204 // Reload general configuration
205 this.serverService.loadConfig()
209 this.notifier.success(this.i18n('Configuration updated.'))
212 err => this.notifier.error(err.message)
216 private updateForm () {
217 this.form.patchValue(this.customConfig)