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