X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2F%2Badmin%2Fconfig%2Fedit-custom-config%2Fedit-custom-config.component.ts;h=ce2ea8a6c15b911591405ee74a63954cc423610b;hb=d9eaee3939bf2e93e5d775d32bce77842201faba;hp=3f92054603c5fdcfcac6a43c88d5e1272118eeb1;hpb=b1d40cff89f7cff565a98cdbcea9a624196a169a;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts index 3f9205460..ce2ea8a6c 100644 --- a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts +++ b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts @@ -1,22 +1,13 @@ import { Component, OnInit } from '@angular/core' -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 { - ADMIN_EMAIL, - CACHE_PREVIEWS_SIZE, - INSTANCE_NAME, - INSTANCE_SHORT_DESCRIPTION, - SERVICES_TWITTER_USERNAME, - SIGNUP_LIMIT, - TRANSCODING_THREADS -} from '@app/shared/forms/form-validators/custom-config' +import { CustomConfigValidatorsService, FormReactive, UserValidatorsService } from '@app/shared' import { NotificationsService } from 'angular2-notifications' import { CustomConfig } from '../../../../../../shared/models/server/custom-config.model' import { I18n } from '@ngx-translate/i18n-polyfill' +import { BuildFormDefaultValues, FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' @Component({ selector: 'my-edit-custom-config', @@ -24,10 +15,7 @@ import { I18n } from '@ngx-translate/i18n-polyfill' styleUrls: [ './edit-custom-config.component.scss' ] }) export class EditCustomConfigComponent extends FormReactive implements OnInit { - customConfig: CustomConfig - resolutions = [ '240p', '360p', '480p', '720p', '1080p' ] - - videoQuotaOptions = [ + static videoQuotaOptions = [ { value: -1, label: 'Unlimited' }, { value: 0, label: '0' }, { value: 100 * 1024 * 1024, label: '100MB' }, @@ -37,45 +25,35 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit { { value: 20 * 1024 * 1024 * 1024, label: '20GB' }, { value: 50 * 1024 * 1024 * 1024, label: '50GB' } ] + static videoQuotaDailyOptions = [ + { value: -1, label: 'Unlimited' }, + { value: 0, label: '0' }, + { value: 10 * 1024 * 1024, label: '10MB' }, + { value: 50 * 1024 * 1024, label: '50MB' }, + { value: 100 * 1024 * 1024, label: '100MB' }, + { value: 500 * 1024 * 1024, label: '500MB' }, + { value: 2 * 1024 * 1024 * 1024, label: '2GB' }, + { value: 5 * 1024 * 1024 * 1024, label: '5GB' } + ] + + customConfig: CustomConfig + resolutions = [ '240p', '360p', '480p', '720p', '1080p' ] + transcodingThreadOptions = [ + { value: 0, label: 'Auto (via ffmpeg)' }, { value: 1, label: '1' }, { value: 2, label: '2' }, { value: 4, label: '4' }, { value: 8, label: '8' } ] - form: FormGroup - formErrors = { - instanceName: '', - instanceShortDescription: '', - instanceDescription: '', - instanceTerms: '', - instanceDefaultClientRoute: '', - instanceDefaultNSFWPolicy: '', - servicesTwitterUsername: '', - cachePreviewsSize: '', - signupLimit: '', - adminEmail: '', - userVideoQuota: '', - transcodingThreads: '', - customizationJavascript: '', - customizationCSS: '' - } - validationMessages = { - instanceShortDescription: INSTANCE_SHORT_DESCRIPTION.MESSAGES, - instanceName: INSTANCE_NAME.MESSAGES, - servicesTwitterUsername: SERVICES_TWITTER_USERNAME, - cachePreviewsSize: CACHE_PREVIEWS_SIZE.MESSAGES, - signupLimit: SIGNUP_LIMIT.MESSAGES, - adminEmail: ADMIN_EMAIL.MESSAGES, - userVideoQuota: USER_VIDEO_QUOTA.MESSAGES - } - private oldCustomJavascript: string private oldCustomCSS: string constructor ( - private formBuilder: FormBuilder, + protected formValidatorService: FormValidatorService, + private customConfigValidatorsService: CustomConfigValidatorsService, + private userValidatorsService: UserValidatorsService, private router: Router, private notificationsService: NotificationsService, private configService: ConfigService, @@ -86,43 +64,52 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit { super() } + get videoQuotaOptions () { + return EditCustomConfigComponent.videoQuotaOptions + } + + get videoQuotaDailyOptions () { + return EditCustomConfigComponent.videoQuotaDailyOptions + } + getResolutionKey (resolution: string) { return 'transcodingResolution' + resolution } - buildForm () { + ngOnInit () { const formGroupData = { - instanceName: [ '', INSTANCE_NAME.VALIDATORS ], - instanceShortDescription: [ '', INSTANCE_SHORT_DESCRIPTION.VALIDATORS ], - instanceDescription: [ '' ], - instanceTerms: [ '' ], - instanceDefaultClientRoute: [ '' ], - instanceDefaultNSFWPolicy: [ '' ], - servicesTwitterUsername: [ '', SERVICES_TWITTER_USERNAME.VALIDATORS ], - servicesTwitterWhitelisted: [ ], - cachePreviewsSize: [ '', CACHE_PREVIEWS_SIZE.VALIDATORS ], - signupEnabled: [ ], - signupLimit: [ '', SIGNUP_LIMIT.VALIDATORS ], - adminEmail: [ '', ADMIN_EMAIL.VALIDATORS ], - userVideoQuota: [ '', USER_VIDEO_QUOTA.VALIDATORS ], - transcodingThreads: [ '', TRANSCODING_THREADS.VALIDATORS ], - transcodingEnabled: [ ], - customizationJavascript: [ '' ], - customizationCSS: [ '' ] + instanceName: this.customConfigValidatorsService.INSTANCE_NAME, + instanceShortDescription: this.customConfigValidatorsService.INSTANCE_SHORT_DESCRIPTION, + instanceDescription: null, + instanceTerms: null, + instanceDefaultClientRoute: null, + instanceDefaultNSFWPolicy: null, + servicesTwitterUsername: this.customConfigValidatorsService.SERVICES_TWITTER_USERNAME, + servicesTwitterWhitelisted: null, + cachePreviewsSize: this.customConfigValidatorsService.CACHE_PREVIEWS_SIZE, + cacheCaptionsSize: this.customConfigValidatorsService.CACHE_CAPTIONS_SIZE, + signupEnabled: null, + signupLimit: this.customConfigValidatorsService.SIGNUP_LIMIT, + signupRequiresEmailVerification: null, + importVideosHttpEnabled: null, + importVideosTorrentEnabled: null, + adminEmail: this.customConfigValidatorsService.ADMIN_EMAIL, + userVideoQuota: this.userValidatorsService.USER_VIDEO_QUOTA, + userVideoQuotaDaily: this.userValidatorsService.USER_VIDEO_QUOTA_DAILY, + transcodingThreads: this.customConfigValidatorsService.TRANSCODING_THREADS, + transcodingEnabled: null, + customizationJavascript: null, + customizationCSS: null } + const defaultValues: BuildFormDefaultValues = {} for (const resolution of this.resolutions) { const key = this.getResolutionKey(resolution) - formGroupData[key] = [ false ] + defaultValues[key] = 'false' + formGroupData[key] = null } - this.form = this.formBuilder.group(formGroupData) - - this.form.valueChanges.subscribe(data => this.onValueChanged(data)) - } - - ngOnInit () { - this.buildForm() + this.buildForm(formGroupData) this.configService.getCustomConfig() .subscribe( @@ -161,14 +148,12 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit { const customizationsText = customizations.join('/') // FIXME: i18n service does not support string concatenation - const message = this.i18n('You set custom {{ customizationsText }}. ', { customizationsText }) + + const message = this.i18n('You set custom {{customizationsText}}. ', { customizationsText }) + this.i18n('This could lead to security issues or bugs if you do not understand it. ') + this.i18n('Are you sure you want to update the configuration?') - const label = this.i18n( - 'Please type "I understand the {{ customizationsText }} I set" to confirm.', - { customizationsText } - ) - const expectedInputValue = this.i18n('I understand the {{ customizationsText }} I set', { customizationsText}) + + const label = this.i18n('Please type') + ` "I understand the ${customizationsText} I set" ` + this.i18n('to confirm.') + const expectedInputValue = `I understand the ${customizationsText} I set` const confirmRes = await this.confirmService.confirmWithInput(message, label, expectedInputValue) if (confirmRes === false) return @@ -196,17 +181,22 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit { cache: { previews: { size: this.form.value['cachePreviewsSize'] + }, + captions: { + size: this.form.value['cacheCaptionsSize'] } }, signup: { enabled: this.form.value['signupEnabled'], - limit: this.form.value['signupLimit'] + limit: this.form.value['signupLimit'], + requiresEmailVerification: this.form.value['signupRequiresEmailVerification'] }, admin: { email: this.form.value['adminEmail'] }, user: { - videoQuota: this.form.value['userVideoQuota'] + videoQuota: this.form.value['userVideoQuota'], + videoQuotaDaily: this.form.value['userVideoQuotaDaily'] }, transcoding: { enabled: this.form.value['transcodingEnabled'], @@ -218,6 +208,16 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit { '720p': this.form.value[this.getResolutionKey('720p')], '1080p': this.form.value[this.getResolutionKey('1080p')] } + }, + import: { + videos: { + http: { + enabled: this.form.value['importVideosHttpEnabled'] + }, + torrent: { + enabled: this.form.value['importVideosTorrentEnabled'] + } + } } } @@ -249,14 +249,19 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit { servicesTwitterUsername: this.customConfig.services.twitter.username, servicesTwitterWhitelisted: this.customConfig.services.twitter.whitelisted, cachePreviewsSize: this.customConfig.cache.previews.size, + cacheCaptionsSize: this.customConfig.cache.captions.size, signupEnabled: this.customConfig.signup.enabled, signupLimit: this.customConfig.signup.limit, + signupRequiresEmailVerification: this.customConfig.signup.requiresEmailVerification, adminEmail: this.customConfig.admin.email, userVideoQuota: this.customConfig.user.videoQuota, + userVideoQuotaDaily: this.customConfig.user.videoQuotaDaily, transcodingThreads: this.customConfig.transcoding.threads, transcodingEnabled: this.customConfig.transcoding.enabled, customizationJavascript: this.customConfig.instance.customizations.javascript, - customizationCSS: this.customConfig.instance.customizations.css + customizationCSS: this.customConfig.instance.customizations.css, + importVideosHttpEnabled: this.customConfig.import.videos.http.enabled, + importVideosTorrentEnabled: this.customConfig.import.videos.torrent.enabled } for (const resolution of this.resolutions) {