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 getResolutionKey (resolution: string) {
77 return 'transcoding.resolutions.' + resolution
81 const formGroupData: { [key in keyof CustomConfig ]: any } = {
83 name: this.customConfigValidatorsService.INSTANCE_NAME,
84 shortDescription: this.customConfigValidatorsService.INSTANCE_SHORT_DESCRIPTION,
87 defaultClientRoute: null,
89 defaultNSFWPolicy: null,
97 username: this.customConfigValidatorsService.SERVICES_TWITTER_USERNAME,
103 size: this.customConfigValidatorsService.CACHE_PREVIEWS_SIZE
106 size: this.customConfigValidatorsService.CACHE_CAPTIONS_SIZE
111 limit: this.customConfigValidatorsService.SIGNUP_LIMIT,
112 requiresEmailVerification: null
125 email: this.customConfigValidatorsService.ADMIN_EMAIL
131 videoQuota: this.userValidatorsService.USER_VIDEO_QUOTA,
132 videoQuotaDaily: this.userValidatorsService.USER_VIDEO_QUOTA_DAILY
136 threads: this.customConfigValidatorsService.TRANSCODING_THREADS,
137 allowAdditionalExtensions: null,
138 allowAudioFiles: null,
156 const defaultValues = {
161 for (const resolution of this.resolutions) {
162 defaultValues.transcoding.resolutions[resolution.id] = 'false'
163 formGroupData.transcoding.resolutions[resolution.id] = null
166 this.buildForm(formGroupData)
168 this.configService.getCustomConfig()
171 this.customConfig = res
174 // Force form validation
178 err => this.notifier.error(err.message)
182 isTranscodingEnabled () {
183 return this.form.value['transcoding']['enabled'] === true
187 return this.form.value['signup']['enabled'] === true
190 async formValidated () {
191 this.configService.updateCustomConfig(this.form.value)
194 this.customConfig = res
196 // Reload general configuration
197 this.serverService.loadConfig()
201 this.notifier.success(this.i18n('Configuration updated.'))
204 err => this.notifier.error(err.message)
208 private updateForm () {
209 this.form.patchValue(this.customConfig)