]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts
Add 4k conf in transcoding in admin panel
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / config / edit-custom-config / edit-custom-config.component.ts
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 { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
9
10 @Component({
11 selector: 'my-edit-custom-config',
12 templateUrl: './edit-custom-config.component.html',
13 styleUrls: [ './edit-custom-config.component.scss' ]
14 })
15 export class EditCustomConfigComponent extends FormReactive implements OnInit {
16 customConfig: CustomConfig
17
18 resolutions: { id: string, label: string }[] = []
19 transcodingThreadOptions: { label: string, value: number }[] = []
20
21 constructor (
22 protected formValidatorService: FormValidatorService,
23 private customConfigValidatorsService: CustomConfigValidatorsService,
24 private userValidatorsService: UserValidatorsService,
25 private notifier: Notifier,
26 private configService: ConfigService,
27 private serverService: ServerService,
28 private i18n: I18n
29 ) {
30 super()
31
32 this.resolutions = [
33 {
34 id: '240p',
35 label: this.i18n('240p')
36 },
37 {
38 id: '360p',
39 label: this.i18n('360p')
40 },
41 {
42 id: '480p',
43 label: this.i18n('480p')
44 },
45 {
46 id: '720p',
47 label: this.i18n('720p')
48 },
49 {
50 id: '1080p',
51 label: this.i18n('1080p')
52 },
53 {
54 id: '2160p',
55 label: this.i18n('2160p')
56 }
57 ]
58
59 this.transcodingThreadOptions = [
60 { value: 0, label: this.i18n('Auto (via ffmpeg)') },
61 { value: 1, label: '1' },
62 { value: 2, label: '2' },
63 { value: 4, label: '4' },
64 { value: 8, label: '8' }
65 ]
66 }
67
68 get videoQuotaOptions () {
69 return this.configService.videoQuotaOptions
70 }
71
72 get videoQuotaDailyOptions () {
73 return this.configService.videoQuotaDailyOptions
74 }
75
76 getResolutionKey (resolution: string) {
77 return 'transcoding.resolutions.' + resolution
78 }
79
80 ngOnInit () {
81 const formGroupData: { [key in keyof CustomConfig ]: any } = {
82 instance: {
83 name: this.customConfigValidatorsService.INSTANCE_NAME,
84 shortDescription: this.customConfigValidatorsService.INSTANCE_SHORT_DESCRIPTION,
85 description: null,
86 terms: null,
87 defaultClientRoute: null,
88 isNSFW: false,
89 defaultNSFWPolicy: null,
90 customizations: {
91 javascript: null,
92 css: null
93 }
94 },
95 services: {
96 twitter: {
97 username: this.customConfigValidatorsService.SERVICES_TWITTER_USERNAME,
98 whitelisted: null
99 }
100 },
101 cache: {
102 previews: {
103 size: this.customConfigValidatorsService.CACHE_PREVIEWS_SIZE
104 },
105 captions: {
106 size: this.customConfigValidatorsService.CACHE_CAPTIONS_SIZE
107 }
108 },
109 signup: {
110 enabled: null,
111 limit: this.customConfigValidatorsService.SIGNUP_LIMIT,
112 requiresEmailVerification: null
113 },
114 import: {
115 videos: {
116 http: {
117 enabled: null
118 },
119 torrent: {
120 enabled: null
121 }
122 }
123 },
124 admin: {
125 email: this.customConfigValidatorsService.ADMIN_EMAIL
126 },
127 contactForm: {
128 enabled: null
129 },
130 user: {
131 videoQuota: this.userValidatorsService.USER_VIDEO_QUOTA,
132 videoQuotaDaily: this.userValidatorsService.USER_VIDEO_QUOTA_DAILY
133 },
134 transcoding: {
135 enabled: null,
136 threads: this.customConfigValidatorsService.TRANSCODING_THREADS,
137 allowAdditionalExtensions: null,
138 allowAudioFiles: null,
139 resolutions: {}
140 },
141 autoBlacklist: {
142 videos: {
143 ofUsers: {
144 enabled: null
145 }
146 }
147 },
148 followers: {
149 instance: {
150 enabled: null,
151 manualApproval: null
152 }
153 }
154 }
155
156 const defaultValues = {
157 transcoding: {
158 resolutions: {}
159 }
160 }
161 for (const resolution of this.resolutions) {
162 defaultValues.transcoding.resolutions[resolution.id] = 'false'
163 formGroupData.transcoding.resolutions[resolution.id] = null
164 }
165
166 this.buildForm(formGroupData)
167
168 this.configService.getCustomConfig()
169 .subscribe(
170 res => {
171 this.customConfig = res
172
173 this.updateForm()
174 // Force form validation
175 this.forceCheck()
176 },
177
178 err => this.notifier.error(err.message)
179 )
180 }
181
182 isTranscodingEnabled () {
183 return this.form.value['transcoding']['enabled'] === true
184 }
185
186 isSignupEnabled () {
187 return this.form.value['signup']['enabled'] === true
188 }
189
190 async formValidated () {
191 this.configService.updateCustomConfig(this.form.value)
192 .subscribe(
193 res => {
194 this.customConfig = res
195
196 // Reload general configuration
197 this.serverService.loadConfig()
198
199 this.updateForm()
200
201 this.notifier.success(this.i18n('Configuration updated.'))
202 },
203
204 err => this.notifier.error(err.message)
205 )
206 }
207
208 private updateForm () {
209 this.form.patchValue(this.customConfig)
210 }
211
212 }