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 { first } from 'rxjs/operators'
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[] = []
28 protected formValidatorService: FormValidatorService,
29 private customConfigValidatorsService: CustomConfigValidatorsService,
30 private userValidatorsService: UserValidatorsService,
31 private notifier: Notifier,
32 private configService: ConfigService,
33 private serverService: ServerService,
41 label: this.i18n('Audio-only')
45 label: this.i18n('240p')
49 label: this.i18n('360p')
53 label: this.i18n('480p')
57 label: this.i18n('720p')
61 label: this.i18n('1080p')
65 label: this.i18n('2160p')
69 this.transcodingThreadOptions = [
70 { value: 0, label: this.i18n('Auto (via ffmpeg)') },
71 { value: 1, label: '1' },
72 { value: 2, label: '2' },
73 { value: 4, label: '4' },
74 { value: 8, label: '8' }
78 get videoQuotaOptions () {
79 return this.configService.videoQuotaOptions
82 get videoQuotaDailyOptions () {
83 return this.configService.videoQuotaDailyOptions
86 get availableThemes () {
87 return this.serverService.getConfig().theme.registered
91 getResolutionKey (resolution: string) {
92 return 'transcoding.resolutions.' + resolution
96 const formGroupData: { [key in keyof CustomConfig ]: any } = {
98 name: this.customConfigValidatorsService.INSTANCE_NAME,
99 shortDescription: this.customConfigValidatorsService.INSTANCE_SHORT_DESCRIPTION,
103 defaultNSFWPolicy: null,
108 creationReason: null,
109 moderationInformation: null,
111 maintenanceLifetime: null,
114 hardwareInformation: null,
119 defaultClientRoute: null,
131 username: this.customConfigValidatorsService.SERVICES_TWITTER_USERNAME,
137 size: this.customConfigValidatorsService.CACHE_PREVIEWS_SIZE
140 size: this.customConfigValidatorsService.CACHE_CAPTIONS_SIZE
145 limit: this.customConfigValidatorsService.SIGNUP_LIMIT,
146 requiresEmailVerification: null
159 email: this.customConfigValidatorsService.ADMIN_EMAIL
165 videoQuota: this.userValidatorsService.USER_VIDEO_QUOTA,
166 videoQuotaDaily: this.userValidatorsService.USER_VIDEO_QUOTA_DAILY
170 threads: this.customConfigValidatorsService.TRANSCODING_THREADS,
171 allowAdditionalExtensions: null,
172 allowAudioFiles: null,
201 indexUrl: this.customConfigValidatorsService.INDEX_URL
207 const defaultValues = {
212 for (const resolution of this.resolutions) {
213 defaultValues.transcoding.resolutions[resolution.id] = 'false'
214 formGroupData.transcoding.resolutions[resolution.id] = null
217 this.buildForm(formGroupData)
220 this.configService.getCustomConfig(),
221 this.serverService.videoLanguagesLoaded.pipe(first()), // First so the observable completes
222 this.serverService.videoCategoriesLoaded.pipe(first())
225 this.customConfig = config
227 const languages = this.serverService.getVideoLanguages()
228 this.languageItems = languages.map(l => ({ label: l.label, value: l.id }))
230 const categories = this.serverService.getVideoCategories()
231 this.categoryItems = categories.map(l => ({ label: l.label, value: l.id }))
234 // Force form validation
238 err => this.notifier.error(err.message)
242 isTranscodingEnabled () {
243 return this.form.value['transcoding']['enabled'] === true
247 return this.form.value['signup']['enabled'] === true
250 async formValidated () {
251 this.configService.updateCustomConfig(this.form.value)
254 this.customConfig = res
256 // Reload general configuration
257 this.serverService.loadConfig()
261 this.notifier.success(this.i18n('Configuration updated.'))
264 err => this.notifier.error(err.message)
268 getSelectedLanguageLabel () {
269 return this.i18n('{{\'{0} languages selected')
272 getDefaultLanguageLabel () {
273 return this.i18n('No language')
276 getSelectedCategoryLabel () {
277 return this.i18n('{{\'{0} categories selected')
280 getDefaultCategoryLabel () {
281 return this.i18n('No category')
284 private updateForm () {
285 this.form.patchValue(this.customConfig)