]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts
Fix error log when updating redundancy
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / config / edit-custom-config / edit-custom-config.component.ts
CommitLineData
fd206f0b 1import { Component, OnInit } from '@angular/core'
fd206f0b
C
2import { ConfigService } from '@app/+admin/config/shared/config.service'
3import { ServerService } from '@app/core/server/server.service'
e309822b 4import { CustomConfigValidatorsService, FormReactive, UserValidatorsService } from '@app/shared'
f8b2c1b4 5import { Notifier } from '@app/core'
09cababd 6import { CustomConfig } from '../../../../../../shared/models/server/custom-config.model'
b1d40cff 7import { I18n } from '@ngx-translate/i18n-polyfill'
0dc64777 8import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
ccc00cb2
C
9import { SelectItem } from 'primeng/api'
10import { forkJoin } from 'rxjs'
11import { first } from 'rxjs/operators'
fd206f0b
C
12
13@Component({
14 selector: 'my-edit-custom-config',
15 templateUrl: './edit-custom-config.component.html',
16 styleUrls: [ './edit-custom-config.component.scss' ]
17})
18export class EditCustomConfigComponent extends FormReactive implements OnInit {
bee0abff 19 customConfig: CustomConfig
bee0abff 20
00aa1f0d 21 resolutions: { id: string, label: string }[] = []
3827c3b3 22 transcodingThreadOptions: { label: string, value: number }[] = []
fd206f0b 23
ccc00cb2
C
24 languageItems: SelectItem[] = []
25 categoryItems: SelectItem[] = []
26
fd206f0b 27 constructor (
d18d6478 28 protected formValidatorService: FormValidatorService,
e309822b
C
29 private customConfigValidatorsService: CustomConfigValidatorsService,
30 private userValidatorsService: UserValidatorsService,
f8b2c1b4 31 private notifier: Notifier,
fd206f0b 32 private configService: ConfigService,
1f30a185 33 private serverService: ServerService,
b1d40cff 34 private i18n: I18n
fd206f0b
C
35 ) {
36 super()
3827c3b3
C
37
38 this.resolutions = [
5c7d6508 39 {
40 id: '0p',
41 label: this.i18n('Audio-only')
42 },
00aa1f0d
C
43 {
44 id: '240p',
45 label: this.i18n('240p')
46 },
47 {
48 id: '360p',
49 label: this.i18n('360p')
50 },
51 {
52 id: '480p',
53 label: this.i18n('480p')
54 },
55 {
56 id: '720p',
57 label: this.i18n('720p')
58 },
59 {
60 id: '1080p',
61 label: this.i18n('1080p')
62 },
63 {
64 id: '2160p',
65 label: this.i18n('2160p')
66 }
3827c3b3
C
67 ]
68
69 this.transcodingThreadOptions = [
70 { value: 0, label: this.i18n('Auto (via ffmpeg)') },
71 { value: 1, label: '1' },
72 { value: 2, label: '2' },
73 { value: 4, label: '4' },
74 { value: 8, label: '8' }
75 ]
fd206f0b
C
76 }
77
41a676db 78 get videoQuotaOptions () {
3827c3b3 79 return this.configService.videoQuotaOptions
41a676db
C
80 }
81
82 get videoQuotaDailyOptions () {
3827c3b3 83 return this.configService.videoQuotaDailyOptions
41a676db
C
84 }
85
7cd4d2ba
C
86 get availableThemes () {
87 return this.serverService.getConfig().theme.registered
ffb321be 88 .map(t => t.name)
7cd4d2ba
C
89 }
90
fd206f0b 91 getResolutionKey (resolution: string) {
3866f1a0 92 return 'transcoding.resolutions.' + resolution
fd206f0b
C
93 }
94
d18d6478 95 ngOnInit () {
3866f1a0
C
96 const formGroupData: { [key in keyof CustomConfig ]: any } = {
97 instance: {
98 name: this.customConfigValidatorsService.INSTANCE_NAME,
99 shortDescription: this.customConfigValidatorsService.INSTANCE_SHORT_DESCRIPTION,
100 description: null,
ccc00cb2 101
f8802489 102 isNSFW: false,
3866f1a0 103 defaultNSFWPolicy: null,
ccc00cb2
C
104
105 terms: null,
106 codeOfConduct: null,
8ae03c37
C
107
108 creationReason: null,
ccc00cb2
C
109 moderationInformation: null,
110 administrator: null,
111 maintenanceLifetime: null,
112 businessModel: null,
113
be04c6fd
C
114 hardwareInformation: null,
115
ccc00cb2
C
116 categories: null,
117 languages: null,
118
119 defaultClientRoute: null,
120
3866f1a0
C
121 customizations: {
122 javascript: null,
123 css: null
124 }
125 },
7cd4d2ba
C
126 theme: {
127 default: null
128 },
3866f1a0
C
129 services: {
130 twitter: {
131 username: this.customConfigValidatorsService.SERVICES_TWITTER_USERNAME,
132 whitelisted: null
133 }
134 },
135 cache: {
136 previews: {
137 size: this.customConfigValidatorsService.CACHE_PREVIEWS_SIZE
138 },
139 captions: {
140 size: this.customConfigValidatorsService.CACHE_CAPTIONS_SIZE
141 }
142 },
143 signup: {
144 enabled: null,
145 limit: this.customConfigValidatorsService.SIGNUP_LIMIT,
146 requiresEmailVerification: null
147 },
148 import: {
149 videos: {
150 http: {
151 enabled: null
152 },
153 torrent: {
154 enabled: null
155 }
156 }
157 },
158 admin: {
159 email: this.customConfigValidatorsService.ADMIN_EMAIL
160 },
161 contactForm: {
162 enabled: null
163 },
164 user: {
165 videoQuota: this.userValidatorsService.USER_VIDEO_QUOTA,
166 videoQuotaDaily: this.userValidatorsService.USER_VIDEO_QUOTA_DAILY
167 },
168 transcoding: {
169 enabled: null,
170 threads: this.customConfigValidatorsService.TRANSCODING_THREADS,
171 allowAdditionalExtensions: null,
536598cf 172 allowAudioFiles: null,
5d9e4eaa
C
173 resolutions: {},
174 hls: {
175 enabled: null
5a71acd2
C
176 },
177 webtorrent: {
178 enabled: null
5d9e4eaa 179 }
7ccddd7b
JM
180 },
181 autoBlacklist: {
182 videos: {
183 ofUsers: {
184 enabled: null
185 }
186 }
0dc64777
C
187 },
188 followers: {
189 instance: {
190 enabled: null,
191 manualApproval: null
192 }
e1b49ee5
C
193 },
194 followings: {
195 instance: {
196 autoFollowBack: {
197 enabled: null
198 },
199 autoFollowIndex: {
200 enabled: null,
201 indexUrl: this.customConfigValidatorsService.INDEX_URL
202 }
203 }
3866f1a0 204 }
fd206f0b
C
205 }
206
3866f1a0
C
207 const defaultValues = {
208 transcoding: {
209 resolutions: {}
210 }
211 }
fd206f0b 212 for (const resolution of this.resolutions) {
00aa1f0d
C
213 defaultValues.transcoding.resolutions[resolution.id] = 'false'
214 formGroupData.transcoding.resolutions[resolution.id] = null
fd206f0b
C
215 }
216
d18d6478 217 this.buildForm(formGroupData)
fd206f0b 218
ccc00cb2
C
219 forkJoin([
220 this.configService.getCustomConfig(),
221 this.serverService.videoLanguagesLoaded.pipe(first()), // First so the observable completes
222 this.serverService.videoCategoriesLoaded.pipe(first())
223 ]).subscribe(
224 ([ config ]) => {
225 this.customConfig = config
fd206f0b 226
ccc00cb2
C
227 const languages = this.serverService.getVideoLanguages()
228 this.languageItems = languages.map(l => ({ label: l.label, value: l.id }))
fd206f0b 229
ccc00cb2
C
230 const categories = this.serverService.getVideoCategories()
231 this.categoryItems = categories.map(l => ({ label: l.label, value: l.id }))
232
233 this.updateForm()
234 // Force form validation
235 this.forceCheck()
236 },
237
238 err => this.notifier.error(err.message)
239 )
fd206f0b
C
240 }
241
242 isTranscodingEnabled () {
3866f1a0 243 return this.form.value['transcoding']['enabled'] === true
fd206f0b
C
244 }
245
246 isSignupEnabled () {
3866f1a0 247 return this.form.value['signup']['enabled'] === true
fd206f0b
C
248 }
249
1f30a185 250 async formValidated () {
3866f1a0 251 this.configService.updateCustomConfig(this.form.value)
fd206f0b
C
252 .subscribe(
253 res => {
254 this.customConfig = res
255
256 // Reload general configuration
257 this.serverService.loadConfig()
258
259 this.updateForm()
66b16caf 260
f8b2c1b4 261 this.notifier.success(this.i18n('Configuration updated.'))
fd206f0b
C
262 },
263
f8b2c1b4 264 err => this.notifier.error(err.message)
fd206f0b
C
265 )
266 }
267
ccc00cb2
C
268 getSelectedLanguageLabel () {
269 return this.i18n('{{\'{0} languages selected')
270 }
271
272 getDefaultLanguageLabel () {
273 return this.i18n('No language')
274 }
275
276 getSelectedCategoryLabel () {
277 return this.i18n('{{\'{0} categories selected')
278 }
279
280 getDefaultCategoryLabel () {
281 return this.i18n('No category')
282 }
283
fd206f0b 284 private updateForm () {
3866f1a0 285 this.form.patchValue(this.customConfig)
fd206f0b 286 }
fd206f0b 287}