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'
9 import { SelectItem } from 'primeng/api'
10 import { forkJoin } from 'rxjs'
11 import { ServerConfig } from '@shared/models'
14 selector: 'my-edit-custom-config',
15 templateUrl: './edit-custom-config.component.html',
16 styleUrls: [ './edit-custom-config.component.scss' ]
18 export class EditCustomConfigComponent extends FormReactive implements OnInit {
19 customConfig: CustomConfig
21 resolutions: { id: string, label: string }[] = []
22 transcodingThreadOptions: { label: string, value: number }[] = []
24 languageItems: SelectItem[] = []
25 categoryItems: SelectItem[] = []
27 private serverConfig: ServerConfig
30 protected formValidatorService: FormValidatorService,
31 private customConfigValidatorsService: CustomConfigValidatorsService,
32 private userValidatorsService: UserValidatorsService,
33 private notifier: Notifier,
34 private configService: ConfigService,
35 private serverService: ServerService,
43 label: this.i18n('Audio-only')
47 label: this.i18n('240p')
51 label: this.i18n('360p')
55 label: this.i18n('480p')
59 label: this.i18n('720p')
63 label: this.i18n('1080p')
67 label: this.i18n('2160p')
71 this.transcodingThreadOptions = [
72 { value: 0, label: this.i18n('Auto (via ffmpeg)') },
73 { value: 1, label: '1' },
74 { value: 2, label: '2' },
75 { value: 4, label: '4' },
76 { value: 8, label: '8' }
80 get videoQuotaOptions () {
81 return this.configService.videoQuotaOptions
84 get videoQuotaDailyOptions () {
85 return this.configService.videoQuotaDailyOptions
88 get availableThemes () {
89 return this.serverConfig.theme.registered
93 getResolutionKey (resolution: string) {
94 return 'transcoding.resolutions.' + resolution
98 this.serverConfig = this.serverService.getTmpConfig()
99 this.serverService.getConfig()
100 .subscribe(config => this.serverConfig = config)
102 const formGroupData: { [key in keyof CustomConfig ]: any } = {
104 name: this.customConfigValidatorsService.INSTANCE_NAME,
105 shortDescription: this.customConfigValidatorsService.INSTANCE_SHORT_DESCRIPTION,
109 defaultNSFWPolicy: null,
114 creationReason: null,
115 moderationInformation: null,
117 maintenanceLifetime: null,
120 hardwareInformation: null,
125 defaultClientRoute: null,
137 username: this.customConfigValidatorsService.SERVICES_TWITTER_USERNAME,
143 size: this.customConfigValidatorsService.CACHE_PREVIEWS_SIZE
146 size: this.customConfigValidatorsService.CACHE_CAPTIONS_SIZE
151 limit: this.customConfigValidatorsService.SIGNUP_LIMIT,
152 requiresEmailVerification: null
165 email: this.customConfigValidatorsService.ADMIN_EMAIL
171 videoQuota: this.userValidatorsService.USER_VIDEO_QUOTA,
172 videoQuotaDaily: this.userValidatorsService.USER_VIDEO_QUOTA_DAILY
176 threads: this.customConfigValidatorsService.TRANSCODING_THREADS,
177 allowAdditionalExtensions: null,
178 allowAudioFiles: null,
207 indexUrl: this.customConfigValidatorsService.INDEX_URL
213 const defaultValues = {
218 for (const resolution of this.resolutions) {
219 defaultValues.transcoding.resolutions[resolution.id] = 'false'
220 formGroupData.transcoding.resolutions[resolution.id] = null
223 this.buildForm(formGroupData)
226 this.configService.getCustomConfig(),
227 this.serverService.getVideoLanguages(),
228 this.serverService.getVideoCategories()
230 ([ config, languages, categories ]) => {
231 this.customConfig = config
233 this.languageItems = languages.map(l => ({ label: l.label, value: l.id }))
234 this.categoryItems = categories.map(l => ({ label: l.label, value: l.id }))
237 // Force form validation
241 err => this.notifier.error(err.message)
245 isTranscodingEnabled () {
246 return this.form.value['transcoding']['enabled'] === true
250 return this.form.value['signup']['enabled'] === true
253 async formValidated () {
254 this.configService.updateCustomConfig(this.form.value)
259 this.customConfig = res
261 // Reload general configuration
262 this.serverService.resetConfig()
266 this.notifier.success(this.i18n('Configuration updated.'))
269 err => this.notifier.error(err.message)
273 getSelectedLanguageLabel () {
274 return this.i18n('{{\'{0} languages selected')
277 getDefaultLanguageLabel () {
278 return this.i18n('No language')
281 getSelectedCategoryLabel () {
282 return this.i18n('{{\'{0} categories selected')
285 getDefaultCategoryLabel () {
286 return this.i18n('No category')
289 private updateForm () {
290 this.form.patchValue(this.customConfig)