]>
Commit | Line | Data |
---|---|---|
ccc00cb2 | 1 | import { forkJoin } from 'rxjs' |
80ac2e55 | 2 | import { pairwise } from 'rxjs/operators' |
45e0d669 | 3 | import { ViewportScroller } from '@angular/common' |
67ed6552 C |
4 | import { AfterViewChecked, Component, OnInit, ViewChild } from '@angular/core' |
5 | import { ConfigService } from '@app/+admin/config/shared/config.service' | |
6 | import { Notifier } from '@app/core' | |
7 | import { ServerService } from '@app/core/server/server.service' | |
52c4976f | 8 | import { |
7ed1edbb C |
9 | ADMIN_EMAIL_VALIDATOR, |
10 | CACHE_CAPTIONS_SIZE_VALIDATOR, | |
11 | CACHE_PREVIEWS_SIZE_VALIDATOR, | |
9129b769 | 12 | CONCURRENCY_VALIDATOR, |
7ed1edbb C |
13 | INDEX_URL_VALIDATOR, |
14 | INSTANCE_NAME_VALIDATOR, | |
15 | INSTANCE_SHORT_DESCRIPTION_VALIDATOR, | |
16 | SEARCH_INDEX_URL_VALIDATOR, | |
17 | SERVICES_TWITTER_USERNAME_VALIDATOR, | |
18 | SIGNUP_LIMIT_VALIDATOR, | |
19 | TRANSCODING_THREADS_VALIDATOR | |
20 | } from '@app/shared/form-validators/custom-config-validators' | |
21 | import { USER_VIDEO_QUOTA_DAILY_VALIDATOR, USER_VIDEO_QUOTA_VALIDATOR } from '@app/shared/form-validators/user-validators' | |
22 | import { FormReactive, FormValidatorService, SelectOptionsItem } from '@app/shared/shared-forms' | |
45c6bcf3 | 23 | import { NgbNav } from '@ng-bootstrap/ng-bootstrap' |
67ed6552 | 24 | import { CustomConfig, ServerConfig } from '@shared/models' |
fd206f0b C |
25 | |
26 | @Component({ | |
27 | selector: 'my-edit-custom-config', | |
28 | templateUrl: './edit-custom-config.component.html', | |
29 | styleUrls: [ './edit-custom-config.component.scss' ] | |
30 | }) | |
45e0d669 | 31 | export class EditCustomConfigComponent extends FormReactive implements OnInit, AfterViewChecked { |
45c6bcf3 C |
32 | // FIXME: use built-in router |
33 | @ViewChild('nav') nav: NgbNav | |
45e0d669 RK |
34 | |
35 | initDone = false | |
bee0abff | 36 | customConfig: CustomConfig |
bee0abff | 37 | |
46db9430 | 38 | resolutions: { id: string, label: string, description?: string }[] = [] |
c6c0fa6c | 39 | liveResolutions: { id: string, label: string, description?: string }[] = [] |
9129b769 | 40 | concurrencyOptions: number[] = [] |
3827c3b3 | 41 | transcodingThreadOptions: { label: string, value: number }[] = [] |
fb719404 | 42 | liveMaxDurationOptions: { label: string, value: number }[] = [] |
fd206f0b | 43 | |
80ac2e55 C |
44 | vodTranscodingProfileOptions: string[] = [] |
45 | liveTranscodingProfileOptions: string[] = [] | |
46 | ||
52c4976f C |
47 | languageItems: SelectOptionsItem[] = [] |
48 | categoryItems: SelectOptionsItem[] = [] | |
ccc00cb2 | 49 | |
16a173bb C |
50 | signupAlertMessage: string |
51 | ||
ba430d75 C |
52 | private serverConfig: ServerConfig |
53 | ||
fd206f0b | 54 | constructor ( |
45e0d669 | 55 | private viewportScroller: ViewportScroller, |
d18d6478 | 56 | protected formValidatorService: FormValidatorService, |
f8b2c1b4 | 57 | private notifier: Notifier, |
fd206f0b | 58 | private configService: ConfigService, |
66357162 | 59 | private serverService: ServerService |
fd206f0b C |
60 | ) { |
61 | super() | |
3827c3b3 C |
62 | |
63 | this.resolutions = [ | |
2fa9c40e | 64 | { |
5c7d6508 | 65 | id: '0p', |
66357162 C |
66 | label: $localize`Audio-only`, |
67 | description: $localize`A <code>.mp4</code> that keeps the original audio track, with no video` | |
5c7d6508 | 68 | }, |
00aa1f0d C |
69 | { |
70 | id: '240p', | |
66357162 | 71 | label: $localize`240p` |
00aa1f0d C |
72 | }, |
73 | { | |
74 | id: '360p', | |
66357162 | 75 | label: $localize`360p` |
00aa1f0d C |
76 | }, |
77 | { | |
78 | id: '480p', | |
66357162 | 79 | label: $localize`480p` |
00aa1f0d C |
80 | }, |
81 | { | |
82 | id: '720p', | |
66357162 | 83 | label: $localize`720p` |
00aa1f0d C |
84 | }, |
85 | { | |
86 | id: '1080p', | |
66357162 | 87 | label: $localize`1080p` |
00aa1f0d | 88 | }, |
b7085c71 RK |
89 | { |
90 | id: '1440p', | |
91 | label: $localize`1440p` | |
92 | }, | |
00aa1f0d C |
93 | { |
94 | id: '2160p', | |
66357162 | 95 | label: $localize`2160p` |
00aa1f0d | 96 | } |
3827c3b3 C |
97 | ] |
98 | ||
c6c0fa6c C |
99 | this.liveResolutions = this.resolutions.filter(r => r.id !== '0p') |
100 | ||
3827c3b3 | 101 | this.transcodingThreadOptions = [ |
66357162 | 102 | { value: 0, label: $localize`Auto (via ffmpeg)` }, |
3827c3b3 C |
103 | { value: 1, label: '1' }, |
104 | { value: 2, label: '2' }, | |
105 | { value: 4, label: '4' }, | |
106 | { value: 8, label: '8' } | |
107 | ] | |
9129b769 | 108 | this.concurrencyOptions = [ 1, 2, 3, 4, 5, 6 ] |
fb719404 | 109 | |
80ac2e55 C |
110 | this.vodTranscodingProfileOptions = [ 'default' ] |
111 | this.liveTranscodingProfileOptions = [ 'default' ] | |
112 | ||
fb719404 | 113 | this.liveMaxDurationOptions = [ |
c9bc850e | 114 | { value: -1, label: $localize`No limit` }, |
fb719404 C |
115 | { value: 1000 * 3600, label: $localize`1 hour` }, |
116 | { value: 1000 * 3600 * 3, label: $localize`3 hours` }, | |
117 | { value: 1000 * 3600 * 5, label: $localize`5 hours` }, | |
118 | { value: 1000 * 3600 * 10, label: $localize`10 hours` } | |
119 | ] | |
fd206f0b C |
120 | } |
121 | ||
41a676db | 122 | get videoQuotaOptions () { |
3827c3b3 | 123 | return this.configService.videoQuotaOptions |
41a676db C |
124 | } |
125 | ||
126 | get videoQuotaDailyOptions () { | |
3827c3b3 | 127 | return this.configService.videoQuotaDailyOptions |
41a676db C |
128 | } |
129 | ||
7cd4d2ba | 130 | get availableThemes () { |
ba430d75 | 131 | return this.serverConfig.theme.registered |
ffb321be | 132 | .map(t => t.name) |
7cd4d2ba C |
133 | } |
134 | ||
4f20856e C |
135 | get liveRTMPPort () { |
136 | return this.serverConfig.live.rtmp.port | |
137 | } | |
138 | ||
80ac2e55 C |
139 | getAvailableTranscodingProfile (type: 'live' | 'vod') { |
140 | if (type === 'live') { | |
141 | return this.serverConfig.live.transcoding.availableProfiles | |
142 | } | |
143 | ||
144 | return this.serverConfig.transcoding.availableProfiles | |
145 | } | |
146 | ||
ea5cdc11 RK |
147 | getTotalTranscodingThreads () { |
148 | const transcodingEnabled = this.form.value['transcoding']['enabled'] | |
149 | const transcodingThreads = this.form.value['transcoding']['threads'] | |
150 | const liveTranscodingEnabled = this.form.value['live']['transcoding']['enabled'] | |
151 | const liveTranscodingThreads = this.form.value['live']['transcoding']['threads'] | |
152 | ||
153 | // checks whether all enabled method are on fixed values and not on auto (= 0) | |
154 | let noneOnAuto = !transcodingEnabled || +transcodingThreads > 0 | |
155 | noneOnAuto &&= !liveTranscodingEnabled || +liveTranscodingThreads > 0 | |
156 | ||
157 | // count total of fixed value, repalcing auto by a single thread (knowing it will display "at least") | |
158 | let value = 0 | |
159 | if (transcodingEnabled) value += +transcodingThreads || 1 | |
160 | if (liveTranscodingEnabled) value += +liveTranscodingThreads || 1 | |
161 | ||
162 | return { | |
163 | value, | |
164 | atMost: noneOnAuto, // auto switches everything to a least estimation since ffmpeg will take as many threads as possible | |
165 | unit: value > 1 | |
166 | ? $localize`threads` | |
167 | : $localize`thread` | |
168 | } | |
169 | } | |
170 | ||
fd206f0b | 171 | getResolutionKey (resolution: string) { |
3866f1a0 | 172 | return 'transcoding.resolutions.' + resolution |
fd206f0b C |
173 | } |
174 | ||
d18d6478 | 175 | ngOnInit () { |
ba430d75 C |
176 | this.serverConfig = this.serverService.getTmpConfig() |
177 | this.serverService.getConfig() | |
fb719404 C |
178 | .subscribe(config => { |
179 | this.serverConfig = config | |
180 | }) | |
ba430d75 | 181 | |
3866f1a0 C |
182 | const formGroupData: { [key in keyof CustomConfig ]: any } = { |
183 | instance: { | |
7ed1edbb C |
184 | name: INSTANCE_NAME_VALIDATOR, |
185 | shortDescription: INSTANCE_SHORT_DESCRIPTION_VALIDATOR, | |
3866f1a0 | 186 | description: null, |
ccc00cb2 | 187 | |
f8802489 | 188 | isNSFW: false, |
3866f1a0 | 189 | defaultNSFWPolicy: null, |
ccc00cb2 C |
190 | |
191 | terms: null, | |
192 | codeOfConduct: null, | |
8ae03c37 C |
193 | |
194 | creationReason: null, | |
ccc00cb2 C |
195 | moderationInformation: null, |
196 | administrator: null, | |
197 | maintenanceLifetime: null, | |
198 | businessModel: null, | |
199 | ||
be04c6fd C |
200 | hardwareInformation: null, |
201 | ||
ccc00cb2 C |
202 | categories: null, |
203 | languages: null, | |
204 | ||
205 | defaultClientRoute: null, | |
206 | ||
3866f1a0 C |
207 | customizations: { |
208 | javascript: null, | |
209 | css: null | |
210 | } | |
211 | }, | |
7cd4d2ba C |
212 | theme: { |
213 | default: null | |
214 | }, | |
3866f1a0 C |
215 | services: { |
216 | twitter: { | |
7ed1edbb | 217 | username: SERVICES_TWITTER_USERNAME_VALIDATOR, |
3866f1a0 C |
218 | whitelisted: null |
219 | } | |
220 | }, | |
221 | cache: { | |
222 | previews: { | |
7ed1edbb | 223 | size: CACHE_PREVIEWS_SIZE_VALIDATOR |
3866f1a0 C |
224 | }, |
225 | captions: { | |
7ed1edbb | 226 | size: CACHE_CAPTIONS_SIZE_VALIDATOR |
3866f1a0 C |
227 | } |
228 | }, | |
229 | signup: { | |
230 | enabled: null, | |
7ed1edbb | 231 | limit: SIGNUP_LIMIT_VALIDATOR, |
3866f1a0 C |
232 | requiresEmailVerification: null |
233 | }, | |
234 | import: { | |
235 | videos: { | |
9129b769 | 236 | concurrency: CONCURRENCY_VALIDATOR, |
3866f1a0 C |
237 | http: { |
238 | enabled: null | |
239 | }, | |
240 | torrent: { | |
241 | enabled: null | |
242 | } | |
243 | } | |
244 | }, | |
ba5d4a84 RK |
245 | trending: { |
246 | videos: { | |
247 | algorithms: { | |
248 | enabled: null, | |
249 | default: null | |
250 | } | |
251 | } | |
252 | }, | |
3866f1a0 | 253 | admin: { |
7ed1edbb | 254 | email: ADMIN_EMAIL_VALIDATOR |
3866f1a0 C |
255 | }, |
256 | contactForm: { | |
257 | enabled: null | |
258 | }, | |
259 | user: { | |
7ed1edbb C |
260 | videoQuota: USER_VIDEO_QUOTA_VALIDATOR, |
261 | videoQuotaDaily: USER_VIDEO_QUOTA_DAILY_VALIDATOR | |
3866f1a0 C |
262 | }, |
263 | transcoding: { | |
264 | enabled: null, | |
7ed1edbb | 265 | threads: TRANSCODING_THREADS_VALIDATOR, |
3866f1a0 | 266 | allowAdditionalExtensions: null, |
536598cf | 267 | allowAudioFiles: null, |
80ac2e55 | 268 | profile: null, |
9129b769 | 269 | concurrency: CONCURRENCY_VALIDATOR, |
5d9e4eaa C |
270 | resolutions: {}, |
271 | hls: { | |
272 | enabled: null | |
5a71acd2 C |
273 | }, |
274 | webtorrent: { | |
275 | enabled: null | |
5d9e4eaa | 276 | } |
7ccddd7b | 277 | }, |
c6c0fa6c C |
278 | live: { |
279 | enabled: null, | |
280 | ||
fb719404 | 281 | maxDuration: null, |
a056ca48 C |
282 | maxInstanceLives: null, |
283 | maxUserLives: null, | |
fb719404 C |
284 | allowReplay: null, |
285 | ||
c6c0fa6c C |
286 | transcoding: { |
287 | enabled: null, | |
288 | threads: TRANSCODING_THREADS_VALIDATOR, | |
80ac2e55 | 289 | profile: null, |
c6c0fa6c C |
290 | resolutions: {} |
291 | } | |
292 | }, | |
7ccddd7b JM |
293 | autoBlacklist: { |
294 | videos: { | |
295 | ofUsers: { | |
296 | enabled: null | |
297 | } | |
298 | } | |
0dc64777 C |
299 | }, |
300 | followers: { | |
301 | instance: { | |
302 | enabled: null, | |
303 | manualApproval: null | |
304 | } | |
e1b49ee5 C |
305 | }, |
306 | followings: { | |
307 | instance: { | |
308 | autoFollowBack: { | |
309 | enabled: null | |
310 | }, | |
311 | autoFollowIndex: { | |
312 | enabled: null, | |
7ed1edbb | 313 | indexUrl: INDEX_URL_VALIDATOR |
e1b49ee5 C |
314 | } |
315 | } | |
72c33e71 C |
316 | }, |
317 | broadcastMessage: { | |
318 | enabled: null, | |
319 | level: null, | |
320 | dismissable: null, | |
321 | message: null | |
5fb2e288 C |
322 | }, |
323 | search: { | |
324 | remoteUri: { | |
325 | users: null, | |
326 | anonymous: null | |
327 | }, | |
328 | searchIndex: { | |
329 | enabled: null, | |
7ed1edbb | 330 | url: SEARCH_INDEX_URL_VALIDATOR, |
5fb2e288 C |
331 | disableLocalSearch: null, |
332 | isDefaultSearch: null | |
333 | } | |
3866f1a0 | 334 | } |
fd206f0b C |
335 | } |
336 | ||
3866f1a0 C |
337 | const defaultValues = { |
338 | transcoding: { | |
339 | resolutions: {} | |
c6c0fa6c C |
340 | }, |
341 | live: { | |
342 | transcoding: { | |
343 | resolutions: {} | |
344 | } | |
3866f1a0 C |
345 | } |
346 | } | |
c6c0fa6c | 347 | |
fd206f0b | 348 | for (const resolution of this.resolutions) { |
00aa1f0d C |
349 | defaultValues.transcoding.resolutions[resolution.id] = 'false' |
350 | formGroupData.transcoding.resolutions[resolution.id] = null | |
fd206f0b C |
351 | } |
352 | ||
c6c0fa6c C |
353 | for (const resolution of this.liveResolutions) { |
354 | defaultValues.live.transcoding.resolutions[resolution.id] = 'false' | |
355 | formGroupData.live.transcoding.resolutions[resolution.id] = null | |
356 | } | |
357 | ||
d18d6478 | 358 | this.buildForm(formGroupData) |
04cda1d7 | 359 | this.loadForm() |
16a173bb | 360 | |
04cda1d7 | 361 | this.checkTranscodingFields() |
16a173bb | 362 | this.checkSignupField() |
fd206f0b C |
363 | } |
364 | ||
45e0d669 RK |
365 | ngAfterViewChecked () { |
366 | if (!this.initDone) { | |
367 | this.initDone = true | |
368 | this.gotoAnchor() | |
369 | } | |
370 | } | |
371 | ||
fd206f0b | 372 | isTranscodingEnabled () { |
3866f1a0 | 373 | return this.form.value['transcoding']['enabled'] === true |
fd206f0b C |
374 | } |
375 | ||
c6c0fa6c C |
376 | isLiveEnabled () { |
377 | return this.form.value['live']['enabled'] === true | |
378 | } | |
379 | ||
380 | isLiveTranscodingEnabled () { | |
381 | return this.form.value['live']['transcoding']['enabled'] === true | |
382 | } | |
383 | ||
fd206f0b | 384 | isSignupEnabled () { |
3866f1a0 | 385 | return this.form.value['signup']['enabled'] === true |
fd206f0b C |
386 | } |
387 | ||
5fb2e288 C |
388 | isSearchIndexEnabled () { |
389 | return this.form.value['search']['searchIndex']['enabled'] === true | |
390 | } | |
391 | ||
4ee6a8b1 C |
392 | isAutoFollowIndexEnabled () { |
393 | return this.form.value['followings']['instance']['autoFollowIndex']['enabled'] === true | |
394 | } | |
395 | ||
ba5d4a84 RK |
396 | trendingVideosAlgorithmsEnabledIncludes (algorithm: string) { |
397 | return this.form.value['trending']['videos']['algorithms']['enabled'].find((e: string) => e === algorithm) | |
3da68f0a RK |
398 | } |
399 | ||
1f30a185 | 400 | async formValidated () { |
210856a7 C |
401 | const value: CustomConfig = this.form.getRawValue() |
402 | ||
210856a7 | 403 | this.configService.updateCustomConfig(value) |
fd206f0b C |
404 | .subscribe( |
405 | res => { | |
406 | this.customConfig = res | |
407 | ||
408 | // Reload general configuration | |
ba430d75 | 409 | this.serverService.resetConfig() |
fd206f0b C |
410 | |
411 | this.updateForm() | |
66b16caf | 412 | |
66357162 | 413 | this.notifier.success($localize`Configuration updated.`) |
fd206f0b C |
414 | }, |
415 | ||
f8b2c1b4 | 416 | err => this.notifier.error(err.message) |
fd206f0b C |
417 | ) |
418 | } | |
419 | ||
45e0d669 | 420 | gotoAnchor () { |
45c6bcf3 | 421 | const hashToNav = { |
45e0d669 RK |
422 | 'customizations': 'advanced-configuration' |
423 | } | |
424 | const hash = window.location.hash.replace('#', '') | |
425 | ||
45c6bcf3 C |
426 | if (hash && Object.keys(hashToNav).includes(hash)) { |
427 | this.nav.select(hashToNav[hash]) | |
45e0d669 RK |
428 | setTimeout(() => this.viewportScroller.scrollToAnchor(hash), 100) |
429 | } | |
430 | } | |
431 | ||
fb719404 C |
432 | hasConsistentOptions () { |
433 | if (this.hasLiveAllowReplayConsistentOptions()) return true | |
434 | ||
435 | return false | |
436 | } | |
437 | ||
438 | hasLiveAllowReplayConsistentOptions () { | |
439 | if (this.isTranscodingEnabled() === false && this.isLiveEnabled() && this.form.value['live']['allowReplay'] === true) { | |
440 | return false | |
441 | } | |
442 | ||
443 | return true | |
444 | } | |
445 | ||
fd206f0b | 446 | private updateForm () { |
3866f1a0 | 447 | this.form.patchValue(this.customConfig) |
fd206f0b | 448 | } |
04cda1d7 C |
449 | |
450 | private loadForm () { | |
451 | forkJoin([ | |
452 | this.configService.getCustomConfig(), | |
453 | this.serverService.getVideoLanguages(), | |
454 | this.serverService.getVideoCategories() | |
455 | ]).subscribe( | |
456 | ([ config, languages, categories ]) => { | |
457 | this.customConfig = config | |
458 | ||
52c4976f C |
459 | this.languageItems = languages.map(l => ({ label: l.label, id: l.id })) |
460 | this.categoryItems = categories.map(l => ({ label: l.label, id: l.id + '' })) | |
04cda1d7 C |
461 | |
462 | this.updateForm() | |
463 | // Force form validation | |
464 | this.forceCheck() | |
465 | }, | |
466 | ||
467 | err => this.notifier.error(err.message) | |
468 | ) | |
469 | } | |
470 | ||
471 | private checkTranscodingFields () { | |
472 | const hlsControl = this.form.get('transcoding.hls.enabled') | |
473 | const webtorrentControl = this.form.get('transcoding.webtorrent.enabled') | |
474 | ||
475 | webtorrentControl.valueChanges | |
476 | .subscribe(newValue => { | |
477 | if (newValue === false && !hlsControl.disabled) { | |
478 | hlsControl.disable() | |
479 | } | |
480 | ||
481 | if (newValue === true && !hlsControl.enabled) { | |
482 | hlsControl.enable() | |
483 | } | |
484 | }) | |
485 | ||
486 | hlsControl.valueChanges | |
487 | .subscribe(newValue => { | |
488 | if (newValue === false && !webtorrentControl.disabled) { | |
489 | webtorrentControl.disable() | |
490 | } | |
491 | ||
492 | if (newValue === true && !webtorrentControl.enabled) { | |
493 | webtorrentControl.enable() | |
494 | } | |
495 | }) | |
496 | } | |
16a173bb C |
497 | |
498 | private checkSignupField () { | |
499 | const signupControl = this.form.get('signup.enabled') | |
500 | ||
501 | signupControl.valueChanges | |
502 | .pipe(pairwise()) | |
503 | .subscribe(([ oldValue, newValue ]) => { | |
504 | if (oldValue !== true && newValue === true) { | |
505 | // tslint:disable:max-line-length | |
506 | this.signupAlertMessage = $localize`You enabled signup: we automatically enabled the "Block new videos automatically" checkbox of the "Videos" section just below.` | |
507 | ||
508 | this.form.patchValue({ | |
509 | autoBlacklist: { | |
510 | videos: { | |
511 | ofUsers: { | |
512 | enabled: true | |
513 | } | |
514 | } | |
515 | } | |
516 | }) | |
517 | } | |
518 | }) | |
519 | } | |
fd206f0b | 520 | } |