import { FormBuilder, FormGroup } from '@angular/forms'
import { Router } from '@angular/router'
import { ConfigService } from '@app/+admin/config/shared/config.service'
+import { ConfirmService } from '@app/core'
import { ServerService } from '@app/core/server/server.service'
import { FormReactive, USER_VIDEO_QUOTA } from '@app/shared'
import {
signupLimit: '',
adminEmail: '',
userVideoQuota: '',
- transcodingThreads: ''
+ transcodingThreads: '',
+ customizationJavascript: '',
+ customizationCSS: ''
}
validationMessages = {
instanceName: INSTANCE_NAME.MESSAGES,
userVideoQuota: USER_VIDEO_QUOTA.MESSAGES
}
+ private oldCustomJavascript: string
+ private oldCustomCSS: string
+
constructor (
private formBuilder: FormBuilder,
private router: Router,
private notificationsService: NotificationsService,
private configService: ConfigService,
- private serverService: ServerService
+ private serverService: ServerService,
+ private confirmService: ConfirmService
) {
super()
}
adminEmail: [ '', ADMIN_EMAIL.VALIDATORS ],
userVideoQuota: [ '', USER_VIDEO_QUOTA.VALIDATORS ],
transcodingThreads: [ '', TRANSCODING_THREADS.VALIDATORS ],
- transcodingEnabled: [ ]
+ transcodingEnabled: [ ],
+ customizationJavascript: [ '' ],
+ customizationCSS: [ '' ]
}
for (const resolution of this.resolutions) {
res => {
this.customConfig = res
+ this.oldCustomCSS = this.customConfig.instance.customizations.css
+ this.oldCustomJavascript = this.customConfig.instance.customizations.javascript
+
this.updateForm()
},
return this.form.value['signupEnabled'] === true
}
- formValidated () {
+ async formValidated () {
+ const newCustomizationJavascript = this.form.value['customizationJavascript']
+ const newCustomizationCSS = this.form.value['customizationCSS']
+
+ const customizations = []
+ if (newCustomizationJavascript && newCustomizationJavascript !== this.oldCustomJavascript) customizations.push('JavaScript')
+ if (newCustomizationCSS && newCustomizationCSS !== this.oldCustomCSS) customizations.push('CSS')
+
+ if (customizations.length !== 0) {
+ const customizationsText = customizations.join('/')
+
+ const message = `You set custom ${customizationsText}. ` +
+ 'This could lead to security issues or bugs if you do not understand it. ' +
+ 'Are you sure you want to update the configuration?'
+ const label = `Please type "I understand the ${customizationsText} I set" to confirm.`
+ const expectedInputValue = `I understand the ${customizationsText} I set`
+
+ const confirmRes = await this.confirmService.confirmWithInput(message, label, expectedInputValue)
+ if (confirmRes === false) return
+ }
+
const data = {
instance: {
name: this.form.value['instanceName'],
description: this.form.value['instanceDescription'],
- terms: this.form.value['instanceTerms']
+ terms: this.form.value['instanceTerms'],
+ customizations: {
+ javascript: this.form.value['customizationJavascript'],
+ css: this.form.value['customizationCSS']
+ }
},
cache: {
previews: {
adminEmail: this.customConfig.admin.email,
userVideoQuota: this.customConfig.user.videoQuota,
transcodingThreads: this.customConfig.transcoding.threads,
- transcodingEnabled: this.customConfig.transcoding.enabled
+ transcodingEnabled: this.customConfig.transcoding.enabled,
+ customizationJavascript: this.customConfig.instance.customizations.javascript,
+ customizationCSS: this.customConfig.instance.customizations.css
}
for (const resolution of this.resolutions) {