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
80 getResolutionKey (resolution: string) {
81 return 'transcoding.resolutions.' + resolution
85 const formGroupData: { [key in keyof CustomConfig ]: any } = {
87 name: this.customConfigValidatorsService.INSTANCE_NAME,
88 shortDescription: this.customConfigValidatorsService.INSTANCE_SHORT_DESCRIPTION,
91 defaultClientRoute: null,
93 defaultNSFWPolicy: null,
104 username: this.customConfigValidatorsService.SERVICES_TWITTER_USERNAME,
110 size: this.customConfigValidatorsService.CACHE_PREVIEWS_SIZE
113 size: this.customConfigValidatorsService.CACHE_CAPTIONS_SIZE
118 limit: this.customConfigValidatorsService.SIGNUP_LIMIT,
119 requiresEmailVerification: null
132 email: this.customConfigValidatorsService.ADMIN_EMAIL
138 videoQuota: this.userValidatorsService.USER_VIDEO_QUOTA,
139 videoQuotaDaily: this.userValidatorsService.USER_VIDEO_QUOTA_DAILY
143 threads: this.customConfigValidatorsService.TRANSCODING_THREADS,
144 allowAdditionalExtensions: null,
145 allowAudioFiles: null,
163 const defaultValues = {
168 for (const resolution of this.resolutions) {
169 defaultValues.transcoding.resolutions[resolution.id] = 'false'
170 formGroupData.transcoding.resolutions[resolution.id] = null
173 this.buildForm(formGroupData)
175 this.configService.getCustomConfig()
178 this.customConfig = res
181 // Force form validation
185 err => this.notifier.error(err.message)
189 isTranscodingEnabled () {
190 return this.form.value['transcoding']['enabled'] === true
194 return this.form.value['signup']['enabled'] === true
197 async formValidated () {
198 this.configService.updateCustomConfig(this.form.value)
201 this.customConfig = res
203 // Reload general configuration
204 this.serverService.loadConfig()
208 this.notifier.success(this.i18n('Configuration updated.'))
211 err => this.notifier.error(err.message)
215 private updateForm () {
216 this.form.patchValue(this.customConfig)