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 { BuildFormDefaultValues, 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: string[] = []
19 transcodingThreadOptions: { label: string, value: number }[] = []
21 private oldCustomJavascript: string
22 private oldCustomCSS: string
25 protected formValidatorService: FormValidatorService,
26 private customConfigValidatorsService: CustomConfigValidatorsService,
27 private userValidatorsService: UserValidatorsService,
28 private notifier: Notifier,
29 private configService: ConfigService,
30 private serverService: ServerService,
43 this.transcodingThreadOptions = [
44 { value: 0, label: this.i18n('Auto (via ffmpeg)') },
45 { value: 1, label: '1' },
46 { value: 2, label: '2' },
47 { value: 4, label: '4' },
48 { value: 8, label: '8' }
52 get videoQuotaOptions () {
53 return this.configService.videoQuotaOptions
56 get videoQuotaDailyOptions () {
57 return this.configService.videoQuotaDailyOptions
60 getResolutionKey (resolution: string) {
61 return 'transcodingResolution' + resolution
65 const formGroupData: { [key: string]: any } = {
66 instanceName: this.customConfigValidatorsService.INSTANCE_NAME,
67 instanceShortDescription: this.customConfigValidatorsService.INSTANCE_SHORT_DESCRIPTION,
68 instanceDescription: null,
70 instanceDefaultClientRoute: null,
71 instanceDefaultNSFWPolicy: null,
72 servicesTwitterUsername: this.customConfigValidatorsService.SERVICES_TWITTER_USERNAME,
73 servicesTwitterWhitelisted: null,
74 cachePreviewsSize: this.customConfigValidatorsService.CACHE_PREVIEWS_SIZE,
75 cacheCaptionsSize: this.customConfigValidatorsService.CACHE_CAPTIONS_SIZE,
77 signupLimit: this.customConfigValidatorsService.SIGNUP_LIMIT,
78 signupRequiresEmailVerification: null,
79 importVideosHttpEnabled: null,
80 importVideosTorrentEnabled: null,
81 adminEmail: this.customConfigValidatorsService.ADMIN_EMAIL,
82 userVideoQuota: this.userValidatorsService.USER_VIDEO_QUOTA,
83 userVideoQuotaDaily: this.userValidatorsService.USER_VIDEO_QUOTA_DAILY,
84 transcodingThreads: this.customConfigValidatorsService.TRANSCODING_THREADS,
85 transcodingAllowAdditionalExtensions: null,
86 transcodingEnabled: null,
87 customizationJavascript: null,
88 customizationCSS: null
91 const defaultValues: BuildFormDefaultValues = {}
92 for (const resolution of this.resolutions) {
93 const key = this.getResolutionKey(resolution)
94 defaultValues[key] = 'false'
95 formGroupData[key] = null
98 this.buildForm(formGroupData)
100 this.configService.getCustomConfig()
103 this.customConfig = res
105 this.oldCustomCSS = this.customConfig.instance.customizations.css
106 this.oldCustomJavascript = this.customConfig.instance.customizations.javascript
109 // Force form validation
113 err => this.notifier.error(err.message)
117 isTranscodingEnabled () {
118 return this.form.value['transcodingEnabled'] === true
122 return this.form.value['signupEnabled'] === true
125 async formValidated () {
126 const data: CustomConfig = {
128 name: this.form.value['instanceName'],
129 shortDescription: this.form.value['instanceShortDescription'],
130 description: this.form.value['instanceDescription'],
131 terms: this.form.value['instanceTerms'],
132 defaultClientRoute: this.form.value['instanceDefaultClientRoute'],
133 defaultNSFWPolicy: this.form.value['instanceDefaultNSFWPolicy'],
135 javascript: this.form.value['customizationJavascript'],
136 css: this.form.value['customizationCSS']
141 username: this.form.value['servicesTwitterUsername'],
142 whitelisted: this.form.value['servicesTwitterWhitelisted']
147 size: this.form.value['cachePreviewsSize']
150 size: this.form.value['cacheCaptionsSize']
154 enabled: this.form.value['signupEnabled'],
155 limit: this.form.value['signupLimit'],
156 requiresEmailVerification: this.form.value['signupRequiresEmailVerification']
159 email: this.form.value['adminEmail']
162 videoQuota: this.form.value['userVideoQuota'],
163 videoQuotaDaily: this.form.value['userVideoQuotaDaily']
166 enabled: this.form.value['transcodingEnabled'],
167 allowAdditionalExtensions: this.form.value['transcodingAllowAdditionalExtensions'],
168 threads: this.form.value['transcodingThreads'],
170 '240p': this.form.value[this.getResolutionKey('240p')],
171 '360p': this.form.value[this.getResolutionKey('360p')],
172 '480p': this.form.value[this.getResolutionKey('480p')],
173 '720p': this.form.value[this.getResolutionKey('720p')],
174 '1080p': this.form.value[this.getResolutionKey('1080p')]
180 enabled: this.form.value['importVideosHttpEnabled']
183 enabled: this.form.value['importVideosTorrentEnabled']
189 this.configService.updateCustomConfig(data)
192 this.customConfig = res
194 // Reload general configuration
195 this.serverService.loadConfig()
199 this.notifier.success(this.i18n('Configuration updated.'))
202 err => this.notifier.error(err.message)
206 private updateForm () {
207 const data: { [key: string]: any } = {
208 instanceName: this.customConfig.instance.name,
209 instanceShortDescription: this.customConfig.instance.shortDescription,
210 instanceDescription: this.customConfig.instance.description,
211 instanceTerms: this.customConfig.instance.terms,
212 instanceDefaultClientRoute: this.customConfig.instance.defaultClientRoute,
213 instanceDefaultNSFWPolicy: this.customConfig.instance.defaultNSFWPolicy,
214 servicesTwitterUsername: this.customConfig.services.twitter.username,
215 servicesTwitterWhitelisted: this.customConfig.services.twitter.whitelisted,
216 cachePreviewsSize: this.customConfig.cache.previews.size,
217 cacheCaptionsSize: this.customConfig.cache.captions.size,
218 signupEnabled: this.customConfig.signup.enabled,
219 signupLimit: this.customConfig.signup.limit,
220 signupRequiresEmailVerification: this.customConfig.signup.requiresEmailVerification,
221 adminEmail: this.customConfig.admin.email,
222 userVideoQuota: this.customConfig.user.videoQuota,
223 userVideoQuotaDaily: this.customConfig.user.videoQuotaDaily,
224 transcodingThreads: this.customConfig.transcoding.threads,
225 transcodingEnabled: this.customConfig.transcoding.enabled,
226 transcodingAllowAdditionalExtensions: this.customConfig.transcoding.allowAdditionalExtensions,
227 customizationJavascript: this.customConfig.instance.customizations.javascript,
228 customizationCSS: this.customConfig.instance.customizations.css,
229 importVideosHttpEnabled: this.customConfig.import.videos.http.enabled,
230 importVideosTorrentEnabled: this.customConfig.import.videos.torrent.enabled
233 for (const resolution of this.resolutions) {
234 const key = this.getResolutionKey(resolution)
235 data[key] = this.customConfig.transcoding.resolutions[resolution]
238 this.form.patchValue(data)