2018-01-17 10:32:03 +01:00
|
|
|
import { Component, OnInit } from '@angular/core'
|
|
|
|
import { ConfigService } from '@app/+admin/config/shared/config.service'
|
|
|
|
import { ServerService } from '@app/core/server/server.service'
|
2018-06-05 15:01:45 +02:00
|
|
|
import { CustomConfigValidatorsService, FormReactive, UserValidatorsService } from '@app/shared'
|
2018-12-19 16:04:34 +01:00
|
|
|
import { Notifier } from '@app/core'
|
2018-02-28 18:04:46 +01:00
|
|
|
import { CustomConfig } from '../../../../../../shared/models/server/custom-config.model'
|
2018-06-04 16:21:17 +02:00
|
|
|
import { I18n } from '@ngx-translate/i18n-polyfill'
|
2018-06-05 10:58:45 +02:00
|
|
|
import { BuildFormDefaultValues, FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
|
2018-01-17 10:32:03 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'my-edit-custom-config',
|
|
|
|
templateUrl: './edit-custom-config.component.html',
|
|
|
|
styleUrls: [ './edit-custom-config.component.scss' ]
|
|
|
|
})
|
|
|
|
export class EditCustomConfigComponent extends FormReactive implements OnInit {
|
2018-08-28 09:01:35 +02:00
|
|
|
customConfig: CustomConfig
|
|
|
|
|
2018-09-26 14:46:54 +02:00
|
|
|
resolutions: string[] = []
|
|
|
|
transcodingThreadOptions: { label: string, value: number }[] = []
|
2018-01-17 10:32:03 +01:00
|
|
|
|
2018-02-22 15:29:32 +01:00
|
|
|
private oldCustomJavascript: string
|
|
|
|
private oldCustomCSS: string
|
|
|
|
|
2018-01-17 10:32:03 +01:00
|
|
|
constructor (
|
2018-06-05 10:58:45 +02:00
|
|
|
protected formValidatorService: FormValidatorService,
|
2018-06-05 15:01:45 +02:00
|
|
|
private customConfigValidatorsService: CustomConfigValidatorsService,
|
|
|
|
private userValidatorsService: UserValidatorsService,
|
2018-12-19 16:04:34 +01:00
|
|
|
private notifier: Notifier,
|
2018-01-17 10:32:03 +01:00
|
|
|
private configService: ConfigService,
|
2018-02-22 15:29:32 +01:00
|
|
|
private serverService: ServerService,
|
2018-06-04 16:21:17 +02:00
|
|
|
private i18n: I18n
|
2018-01-17 10:32:03 +01:00
|
|
|
) {
|
|
|
|
super()
|
2018-09-26 14:46:54 +02:00
|
|
|
|
|
|
|
this.resolutions = [
|
|
|
|
this.i18n('240p'),
|
|
|
|
this.i18n('360p'),
|
|
|
|
this.i18n('480p'),
|
|
|
|
this.i18n('720p'),
|
|
|
|
this.i18n('1080p')
|
|
|
|
]
|
|
|
|
|
|
|
|
this.transcodingThreadOptions = [
|
|
|
|
{ value: 0, label: this.i18n('Auto (via ffmpeg)') },
|
|
|
|
{ value: 1, label: '1' },
|
|
|
|
{ value: 2, label: '2' },
|
|
|
|
{ value: 4, label: '4' },
|
|
|
|
{ value: 8, label: '8' }
|
|
|
|
]
|
2018-01-17 10:32:03 +01:00
|
|
|
}
|
|
|
|
|
2018-08-28 17:39:29 +02:00
|
|
|
get videoQuotaOptions () {
|
2018-09-26 14:46:54 +02:00
|
|
|
return this.configService.videoQuotaOptions
|
2018-08-28 17:39:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
get videoQuotaDailyOptions () {
|
2018-09-26 14:46:54 +02:00
|
|
|
return this.configService.videoQuotaDailyOptions
|
2018-08-28 17:39:29 +02:00
|
|
|
}
|
|
|
|
|
2018-01-17 10:32:03 +01:00
|
|
|
getResolutionKey (resolution: string) {
|
|
|
|
return 'transcodingResolution' + resolution
|
|
|
|
}
|
|
|
|
|
2018-06-05 10:58:45 +02:00
|
|
|
ngOnInit () {
|
2018-10-18 14:35:31 +02:00
|
|
|
const formGroupData: { [key: string]: any } = {
|
2018-06-05 15:01:45 +02:00
|
|
|
instanceName: this.customConfigValidatorsService.INSTANCE_NAME,
|
|
|
|
instanceShortDescription: this.customConfigValidatorsService.INSTANCE_SHORT_DESCRIPTION,
|
2018-06-05 10:58:45 +02:00
|
|
|
instanceDescription: null,
|
|
|
|
instanceTerms: null,
|
|
|
|
instanceDefaultClientRoute: null,
|
|
|
|
instanceDefaultNSFWPolicy: null,
|
2018-06-05 15:01:45 +02:00
|
|
|
servicesTwitterUsername: this.customConfigValidatorsService.SERVICES_TWITTER_USERNAME,
|
2018-06-05 10:58:45 +02:00
|
|
|
servicesTwitterWhitelisted: null,
|
2018-06-05 15:01:45 +02:00
|
|
|
cachePreviewsSize: this.customConfigValidatorsService.CACHE_PREVIEWS_SIZE,
|
2018-07-12 19:02:00 +02:00
|
|
|
cacheCaptionsSize: this.customConfigValidatorsService.CACHE_CAPTIONS_SIZE,
|
2018-06-05 10:58:45 +02:00
|
|
|
signupEnabled: null,
|
2018-06-05 15:01:45 +02:00
|
|
|
signupLimit: this.customConfigValidatorsService.SIGNUP_LIMIT,
|
2018-08-31 09:18:19 +02:00
|
|
|
signupRequiresEmailVerification: null,
|
2018-08-03 11:10:31 +02:00
|
|
|
importVideosHttpEnabled: null,
|
2018-08-07 10:07:53 +02:00
|
|
|
importVideosTorrentEnabled: null,
|
2018-06-05 15:01:45 +02:00
|
|
|
adminEmail: this.customConfigValidatorsService.ADMIN_EMAIL,
|
|
|
|
userVideoQuota: this.userValidatorsService.USER_VIDEO_QUOTA,
|
2018-08-28 09:01:35 +02:00
|
|
|
userVideoQuotaDaily: this.userValidatorsService.USER_VIDEO_QUOTA_DAILY,
|
2018-06-05 15:01:45 +02:00
|
|
|
transcodingThreads: this.customConfigValidatorsService.TRANSCODING_THREADS,
|
2018-12-11 14:52:50 +01:00
|
|
|
transcodingAllowAdditionalExtensions: null,
|
2018-06-05 10:58:45 +02:00
|
|
|
transcodingEnabled: null,
|
|
|
|
customizationJavascript: null,
|
|
|
|
customizationCSS: null
|
2018-01-17 10:32:03 +01:00
|
|
|
}
|
|
|
|
|
2018-06-05 10:58:45 +02:00
|
|
|
const defaultValues: BuildFormDefaultValues = {}
|
2018-01-17 10:32:03 +01:00
|
|
|
for (const resolution of this.resolutions) {
|
|
|
|
const key = this.getResolutionKey(resolution)
|
2018-06-05 10:58:45 +02:00
|
|
|
defaultValues[key] = 'false'
|
|
|
|
formGroupData[key] = null
|
2018-01-17 10:32:03 +01:00
|
|
|
}
|
|
|
|
|
2018-06-05 10:58:45 +02:00
|
|
|
this.buildForm(formGroupData)
|
2018-01-17 10:32:03 +01:00
|
|
|
|
|
|
|
this.configService.getCustomConfig()
|
|
|
|
.subscribe(
|
|
|
|
res => {
|
|
|
|
this.customConfig = res
|
|
|
|
|
2018-02-22 15:29:32 +01:00
|
|
|
this.oldCustomCSS = this.customConfig.instance.customizations.css
|
|
|
|
this.oldCustomJavascript = this.customConfig.instance.customizations.javascript
|
|
|
|
|
2018-01-17 10:32:03 +01:00
|
|
|
this.updateForm()
|
2018-03-23 09:31:42 +01:00
|
|
|
// Force form validation
|
|
|
|
this.forceCheck()
|
2018-01-17 10:32:03 +01:00
|
|
|
},
|
|
|
|
|
2018-12-19 16:04:34 +01:00
|
|
|
err => this.notifier.error(err.message)
|
2018-01-17 10:32:03 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
isTranscodingEnabled () {
|
|
|
|
return this.form.value['transcodingEnabled'] === true
|
|
|
|
}
|
|
|
|
|
|
|
|
isSignupEnabled () {
|
|
|
|
return this.form.value['signupEnabled'] === true
|
|
|
|
}
|
|
|
|
|
2018-02-22 15:29:32 +01:00
|
|
|
async formValidated () {
|
2018-03-01 13:57:29 +01:00
|
|
|
const data: CustomConfig = {
|
2018-01-31 16:42:40 +01:00
|
|
|
instance: {
|
|
|
|
name: this.form.value['instanceName'],
|
2018-03-15 14:31:08 +01:00
|
|
|
shortDescription: this.form.value['instanceShortDescription'],
|
2018-01-31 16:42:40 +01:00
|
|
|
description: this.form.value['instanceDescription'],
|
2018-02-22 10:22:53 +01:00
|
|
|
terms: this.form.value['instanceTerms'],
|
2018-03-01 13:57:29 +01:00
|
|
|
defaultClientRoute: this.form.value['instanceDefaultClientRoute'],
|
2018-04-19 11:01:34 +02:00
|
|
|
defaultNSFWPolicy: this.form.value['instanceDefaultNSFWPolicy'],
|
2018-02-22 10:22:53 +01:00
|
|
|
customizations: {
|
|
|
|
javascript: this.form.value['customizationJavascript'],
|
|
|
|
css: this.form.value['customizationCSS']
|
|
|
|
}
|
2018-01-31 16:42:40 +01:00
|
|
|
},
|
2018-05-10 12:26:47 +02:00
|
|
|
services: {
|
|
|
|
twitter: {
|
|
|
|
username: this.form.value['servicesTwitterUsername'],
|
|
|
|
whitelisted: this.form.value['servicesTwitterWhitelisted']
|
|
|
|
}
|
|
|
|
},
|
2018-01-17 10:32:03 +01:00
|
|
|
cache: {
|
|
|
|
previews: {
|
|
|
|
size: this.form.value['cachePreviewsSize']
|
2018-07-12 19:02:00 +02:00
|
|
|
},
|
|
|
|
captions: {
|
|
|
|
size: this.form.value['cacheCaptionsSize']
|
2018-01-17 10:32:03 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
signup: {
|
|
|
|
enabled: this.form.value['signupEnabled'],
|
2018-08-31 09:18:19 +02:00
|
|
|
limit: this.form.value['signupLimit'],
|
|
|
|
requiresEmailVerification: this.form.value['signupRequiresEmailVerification']
|
2018-01-17 10:32:03 +01:00
|
|
|
},
|
|
|
|
admin: {
|
|
|
|
email: this.form.value['adminEmail']
|
|
|
|
},
|
|
|
|
user: {
|
2018-08-28 09:01:35 +02:00
|
|
|
videoQuota: this.form.value['userVideoQuota'],
|
|
|
|
videoQuotaDaily: this.form.value['userVideoQuotaDaily']
|
2018-01-17 10:32:03 +01:00
|
|
|
},
|
|
|
|
transcoding: {
|
|
|
|
enabled: this.form.value['transcodingEnabled'],
|
2018-12-11 14:52:50 +01:00
|
|
|
allowAdditionalExtensions: this.form.value['transcodingAllowAdditionalExtensions'],
|
2018-01-17 10:32:03 +01:00
|
|
|
threads: this.form.value['transcodingThreads'],
|
|
|
|
resolutions: {
|
|
|
|
'240p': this.form.value[this.getResolutionKey('240p')],
|
|
|
|
'360p': this.form.value[this.getResolutionKey('360p')],
|
|
|
|
'480p': this.form.value[this.getResolutionKey('480p')],
|
|
|
|
'720p': this.form.value[this.getResolutionKey('720p')],
|
|
|
|
'1080p': this.form.value[this.getResolutionKey('1080p')]
|
|
|
|
}
|
2018-08-03 11:10:31 +02:00
|
|
|
},
|
|
|
|
import: {
|
|
|
|
videos: {
|
|
|
|
http: {
|
|
|
|
enabled: this.form.value['importVideosHttpEnabled']
|
2018-08-07 10:07:53 +02:00
|
|
|
},
|
|
|
|
torrent: {
|
|
|
|
enabled: this.form.value['importVideosTorrentEnabled']
|
2018-08-03 11:10:31 +02:00
|
|
|
}
|
|
|
|
}
|
2018-01-17 10:32:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.configService.updateCustomConfig(data)
|
|
|
|
.subscribe(
|
|
|
|
res => {
|
|
|
|
this.customConfig = res
|
|
|
|
|
|
|
|
// Reload general configuration
|
|
|
|
this.serverService.loadConfig()
|
|
|
|
|
|
|
|
this.updateForm()
|
2018-01-31 16:42:40 +01:00
|
|
|
|
2018-12-19 16:04:34 +01:00
|
|
|
this.notifier.success(this.i18n('Configuration updated.'))
|
2018-01-17 10:32:03 +01:00
|
|
|
},
|
|
|
|
|
2018-12-19 16:04:34 +01:00
|
|
|
err => this.notifier.error(err.message)
|
2018-01-17 10:32:03 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
private updateForm () {
|
2018-10-18 14:35:31 +02:00
|
|
|
const data: { [key: string]: any } = {
|
2018-01-31 16:42:40 +01:00
|
|
|
instanceName: this.customConfig.instance.name,
|
2018-03-15 14:31:08 +01:00
|
|
|
instanceShortDescription: this.customConfig.instance.shortDescription,
|
2018-01-31 16:42:40 +01:00
|
|
|
instanceDescription: this.customConfig.instance.description,
|
|
|
|
instanceTerms: this.customConfig.instance.terms,
|
2018-03-01 13:57:29 +01:00
|
|
|
instanceDefaultClientRoute: this.customConfig.instance.defaultClientRoute,
|
2018-04-19 11:01:34 +02:00
|
|
|
instanceDefaultNSFWPolicy: this.customConfig.instance.defaultNSFWPolicy,
|
2018-05-10 12:26:47 +02:00
|
|
|
servicesTwitterUsername: this.customConfig.services.twitter.username,
|
|
|
|
servicesTwitterWhitelisted: this.customConfig.services.twitter.whitelisted,
|
2018-01-17 10:32:03 +01:00
|
|
|
cachePreviewsSize: this.customConfig.cache.previews.size,
|
2018-07-13 18:21:19 +02:00
|
|
|
cacheCaptionsSize: this.customConfig.cache.captions.size,
|
2018-01-17 10:32:03 +01:00
|
|
|
signupEnabled: this.customConfig.signup.enabled,
|
|
|
|
signupLimit: this.customConfig.signup.limit,
|
2018-08-31 09:18:19 +02:00
|
|
|
signupRequiresEmailVerification: this.customConfig.signup.requiresEmailVerification,
|
2018-01-17 10:32:03 +01:00
|
|
|
adminEmail: this.customConfig.admin.email,
|
|
|
|
userVideoQuota: this.customConfig.user.videoQuota,
|
2018-08-28 09:01:35 +02:00
|
|
|
userVideoQuotaDaily: this.customConfig.user.videoQuotaDaily,
|
2018-01-17 10:32:03 +01:00
|
|
|
transcodingThreads: this.customConfig.transcoding.threads,
|
2018-02-22 10:22:53 +01:00
|
|
|
transcodingEnabled: this.customConfig.transcoding.enabled,
|
2018-12-11 14:52:50 +01:00
|
|
|
transcodingAllowAdditionalExtensions: this.customConfig.transcoding.allowAdditionalExtensions,
|
2018-02-22 10:22:53 +01:00
|
|
|
customizationJavascript: this.customConfig.instance.customizations.javascript,
|
2018-08-03 11:10:31 +02:00
|
|
|
customizationCSS: this.customConfig.instance.customizations.css,
|
2018-08-07 10:07:53 +02:00
|
|
|
importVideosHttpEnabled: this.customConfig.import.videos.http.enabled,
|
|
|
|
importVideosTorrentEnabled: this.customConfig.import.videos.torrent.enabled
|
2018-01-17 10:32:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for (const resolution of this.resolutions) {
|
|
|
|
const key = this.getResolutionKey(resolution)
|
|
|
|
data[key] = this.customConfig.transcoding.resolutions[resolution]
|
|
|
|
}
|
|
|
|
|
|
|
|
this.form.patchValue(data)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|