1 import { forkJoin } from 'rxjs'
2 import { ViewportScroller } from '@angular/common'
3 import { AfterViewChecked, Component, OnInit, ViewChild } from '@angular/core'
4 import { ConfigService } from '@app/+admin/config/shared/config.service'
5 import { Notifier } from '@app/core'
6 import { ServerService } from '@app/core/server/server.service'
8 CustomConfigValidatorsService,
13 } from '@app/shared/shared-forms'
14 import { NgbNav } from '@ng-bootstrap/ng-bootstrap'
15 import { I18n } from '@ngx-translate/i18n-polyfill'
16 import { CustomConfig, ServerConfig } from '@shared/models'
19 selector: 'my-edit-custom-config',
20 templateUrl: './edit-custom-config.component.html',
21 styleUrls: [ './edit-custom-config.component.scss' ]
23 export class EditCustomConfigComponent extends FormReactive implements OnInit, AfterViewChecked {
24 // FIXME: use built-in router
25 @ViewChild('nav') nav: NgbNav
28 customConfig: CustomConfig
30 resolutions: { id: string, label: string, description?: string }[] = []
31 transcodingThreadOptions: { label: string, value: number }[] = []
33 languageItems: SelectOptionsItem[] = []
34 categoryItems: SelectOptionsItem[] = []
36 private serverConfig: ServerConfig
39 private viewportScroller: ViewportScroller,
40 protected formValidatorService: FormValidatorService,
41 private customConfigValidatorsService: CustomConfigValidatorsService,
42 private userValidatorsService: UserValidatorsService,
43 private notifier: Notifier,
44 private configService: ConfigService,
45 private serverService: ServerService,
53 label: this.i18n('Audio-only'),
54 description: this.i18n('A <code>.mp4</code> that keeps the original audio track, with no video')
58 label: this.i18n('240p')
62 label: this.i18n('360p')
66 label: this.i18n('480p')
70 label: this.i18n('720p')
74 label: this.i18n('1080p')
78 label: this.i18n('2160p')
82 this.transcodingThreadOptions = [
83 { value: 0, label: this.i18n('Auto (via ffmpeg)') },
84 { value: 1, label: '1' },
85 { value: 2, label: '2' },
86 { value: 4, label: '4' },
87 { value: 8, label: '8' }
91 get videoQuotaOptions () {
92 return this.configService.videoQuotaOptions
95 get videoQuotaDailyOptions () {
96 return this.configService.videoQuotaDailyOptions
99 get availableThemes () {
100 return this.serverConfig.theme.registered
104 getResolutionKey (resolution: string) {
105 return 'transcoding.resolutions.' + resolution
109 this.serverConfig = this.serverService.getTmpConfig()
110 this.serverService.getConfig()
111 .subscribe(config => this.serverConfig = config)
113 const formGroupData: { [key in keyof CustomConfig ]: any } = {
115 name: this.customConfigValidatorsService.INSTANCE_NAME,
116 shortDescription: this.customConfigValidatorsService.INSTANCE_SHORT_DESCRIPTION,
120 defaultNSFWPolicy: null,
125 creationReason: null,
126 moderationInformation: null,
128 maintenanceLifetime: null,
131 hardwareInformation: null,
136 defaultClientRoute: null,
148 username: this.customConfigValidatorsService.SERVICES_TWITTER_USERNAME,
154 size: this.customConfigValidatorsService.CACHE_PREVIEWS_SIZE
157 size: this.customConfigValidatorsService.CACHE_CAPTIONS_SIZE
162 limit: this.customConfigValidatorsService.SIGNUP_LIMIT,
163 requiresEmailVerification: null
176 email: this.customConfigValidatorsService.ADMIN_EMAIL
182 videoQuota: this.userValidatorsService.USER_VIDEO_QUOTA,
183 videoQuotaDaily: this.userValidatorsService.USER_VIDEO_QUOTA_DAILY
187 threads: this.customConfigValidatorsService.TRANSCODING_THREADS,
188 allowAdditionalExtensions: null,
189 allowAudioFiles: null,
218 indexUrl: this.customConfigValidatorsService.INDEX_URL
235 url: this.customConfigValidatorsService.SEARCH_INDEX_URL,
236 disableLocalSearch: null,
237 isDefaultSearch: null
242 const defaultValues = {
247 for (const resolution of this.resolutions) {
248 defaultValues.transcoding.resolutions[resolution.id] = 'false'
249 formGroupData.transcoding.resolutions[resolution.id] = null
252 this.buildForm(formGroupData)
254 this.checkTranscodingFields()
257 ngAfterViewChecked () {
258 if (!this.initDone) {
264 isTranscodingEnabled () {
265 return this.form.value['transcoding']['enabled'] === true
269 return this.form.value['signup']['enabled'] === true
272 isSearchIndexEnabled () {
273 return this.form.value['search']['searchIndex']['enabled'] === true
276 isAutoFollowIndexEnabled () {
277 return this.form.value['followings']['instance']['autoFollowIndex']['enabled'] === true
280 async formValidated () {
281 this.configService.updateCustomConfig(this.form.getRawValue())
284 this.customConfig = res
286 // Reload general configuration
287 this.serverService.resetConfig()
291 this.notifier.success(this.i18n('Configuration updated.'))
294 err => this.notifier.error(err.message)
300 'customizations': 'advanced-configuration'
302 const hash = window.location.hash.replace('#', '')
304 if (hash && Object.keys(hashToNav).includes(hash)) {
305 this.nav.select(hashToNav[hash])
306 setTimeout(() => this.viewportScroller.scrollToAnchor(hash), 100)
310 private updateForm () {
311 this.form.patchValue(this.customConfig)
314 private loadForm () {
316 this.configService.getCustomConfig(),
317 this.serverService.getVideoLanguages(),
318 this.serverService.getVideoCategories()
320 ([ config, languages, categories ]) => {
321 this.customConfig = config
323 this.languageItems = languages.map(l => ({ label: l.label, id: l.id }))
324 this.categoryItems = categories.map(l => ({ label: l.label, id: l.id + '' }))
327 // Force form validation
331 err => this.notifier.error(err.message)
335 private checkTranscodingFields () {
336 const hlsControl = this.form.get('transcoding.hls.enabled')
337 const webtorrentControl = this.form.get('transcoding.webtorrent.enabled')
339 webtorrentControl.valueChanges
340 .subscribe(newValue => {
341 if (newValue === false && !hlsControl.disabled) {
345 if (newValue === true && !hlsControl.enabled) {
350 hlsControl.valueChanges
351 .subscribe(newValue => {
352 if (newValue === false && !webtorrentControl.disabled) {
353 webtorrentControl.disable()
356 if (newValue === true && !webtorrentControl.enabled) {
357 webtorrentControl.enable()