]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/config/edit-custom-config/edit-configuration.service.ts
Fix admin edition disabling feature
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / config / edit-custom-config / edit-configuration.service.ts
CommitLineData
5f46d28c
C
1import { Injectable } from '@angular/core'
2import { FormGroup } from '@angular/forms'
3
4export type ResolutionOption = {
5 id: string
6 label: string
7 description?: string
8}
9
10@Injectable()
11export class EditConfigurationService {
12
13 getVODResolutions () {
14 return [
15 {
16 id: '0p',
17 label: $localize`Audio-only`,
18 description: $localize`A <code>.mp4</code> that keeps the original audio track, with no video`
19 },
20 {
21 id: '240p',
22 label: $localize`240p`
23 },
24 {
25 id: '360p',
26 label: $localize`360p`
27 },
28 {
29 id: '480p',
30 label: $localize`480p`
31 },
32 {
33 id: '720p',
34 label: $localize`720p`
35 },
36 {
37 id: '1080p',
38 label: $localize`1080p`
39 },
40 {
41 id: '1440p',
42 label: $localize`1440p`
43 },
44 {
45 id: '2160p',
46 label: $localize`2160p`
47 }
48 ]
49 }
50
51 getLiveResolutions () {
52 return this.getVODResolutions().filter(r => r.id !== '0p')
53 }
54
55 isTranscodingEnabled (form: FormGroup) {
56 return form.value['transcoding']['enabled'] === true
57 }
58
59 isLiveEnabled (form: FormGroup) {
60 return form.value['live']['enabled'] === true
61 }
62
63 isLiveTranscodingEnabled (form: FormGroup) {
64 return form.value['live']['transcoding']['enabled'] === true
65 }
66
67 getTotalTranscodingThreads (form: FormGroup) {
68 const transcodingEnabled = form.value['transcoding']['enabled']
69 const transcodingThreads = form.value['transcoding']['threads']
70 const liveTranscodingEnabled = form.value['live']['transcoding']['enabled']
71 const liveTranscodingThreads = form.value['live']['transcoding']['threads']
72
73 // checks whether all enabled method are on fixed values and not on auto (= 0)
74 let noneOnAuto = !transcodingEnabled || +transcodingThreads > 0
75 noneOnAuto &&= !liveTranscodingEnabled || +liveTranscodingThreads > 0
76
77 // count total of fixed value, repalcing auto by a single thread (knowing it will display "at least")
78 let value = 0
79 if (transcodingEnabled) value += +transcodingThreads || 1
80 if (liveTranscodingEnabled) value += +liveTranscodingThreads || 1
81
82 return {
83 value,
84 atMost: noneOnAuto, // auto switches everything to a least estimation since ffmpeg will take as many threads as possible
85 unit: value > 1
86 ? $localize`threads`
87 : $localize`thread`
88 }
89 }
90}