]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts
Fix subtitles import
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / config / edit-custom-config / edit-custom-config.component.ts
CommitLineData
5f46d28c 1
4e55c132
C
2import { forkJoin } from 'rxjs'
3import { SelectOptionsItem } from 'src/types/select-options-item.model'
5f46d28c 4import { Component, OnInit } from '@angular/core'
53e4e201 5import { ActivatedRoute, Router } from '@angular/router'
67ed6552
C
6import { ConfigService } from '@app/+admin/config/shared/config.service'
7import { Notifier } from '@app/core'
8import { ServerService } from '@app/core/server/server.service'
52c4976f 9import {
7ed1edbb
C
10 ADMIN_EMAIL_VALIDATOR,
11 CACHE_CAPTIONS_SIZE_VALIDATOR,
12 CACHE_PREVIEWS_SIZE_VALIDATOR,
9129b769 13 CONCURRENCY_VALIDATOR,
7ed1edbb
C
14 INDEX_URL_VALIDATOR,
15 INSTANCE_NAME_VALIDATOR,
16 INSTANCE_SHORT_DESCRIPTION_VALIDATOR,
4e55c132
C
17 MAX_INSTANCE_LIVES_VALIDATOR,
18 MAX_LIVE_DURATION_VALIDATOR,
19 MAX_USER_LIVES_VALIDATOR,
7ed1edbb
C
20 SEARCH_INDEX_URL_VALIDATOR,
21 SERVICES_TWITTER_USERNAME_VALIDATOR,
22 SIGNUP_LIMIT_VALIDATOR,
23 TRANSCODING_THREADS_VALIDATOR
24} from '@app/shared/form-validators/custom-config-validators'
25import { USER_VIDEO_QUOTA_DAILY_VALIDATOR, USER_VIDEO_QUOTA_VALIDATOR } from '@app/shared/form-validators/user-validators'
21e493d4 26import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
67ed6552 27import { CustomConfig, ServerConfig } from '@shared/models'
5f46d28c 28import { EditConfigurationService } from './edit-configuration.service'
fd206f0b
C
29
30@Component({
31 selector: 'my-edit-custom-config',
32 templateUrl: './edit-custom-config.component.html',
33 styleUrls: [ './edit-custom-config.component.scss' ]
34})
5f46d28c
C
35export class EditCustomConfigComponent extends FormReactive implements OnInit {
36 activeNav: string
45e0d669 37
bee0abff 38 customConfig: CustomConfig
5f46d28c 39 serverConfig: ServerConfig
80ac2e55 40
52c4976f
C
41 languageItems: SelectOptionsItem[] = []
42 categoryItems: SelectOptionsItem[] = []
ccc00cb2 43
fd206f0b 44 constructor (
53e4e201
C
45 private router: Router,
46 private route: ActivatedRoute,
d18d6478 47 protected formValidatorService: FormValidatorService,
f8b2c1b4 48 private notifier: Notifier,
fd206f0b 49 private configService: ConfigService,
5f46d28c
C
50 private serverService: ServerService,
51 private editConfigurationService: EditConfigurationService
fd206f0b
C
52 ) {
53 super()
fd206f0b
C
54 }
55
d18d6478 56 ngOnInit () {
ba430d75
C
57 this.serverConfig = this.serverService.getTmpConfig()
58 this.serverService.getConfig()
fb719404
C
59 .subscribe(config => {
60 this.serverConfig = config
61 })
ba430d75 62
3866f1a0
C
63 const formGroupData: { [key in keyof CustomConfig ]: any } = {
64 instance: {
7ed1edbb
C
65 name: INSTANCE_NAME_VALIDATOR,
66 shortDescription: INSTANCE_SHORT_DESCRIPTION_VALIDATOR,
3866f1a0 67 description: null,
ccc00cb2 68
f8802489 69 isNSFW: false,
3866f1a0 70 defaultNSFWPolicy: null,
ccc00cb2
C
71
72 terms: null,
73 codeOfConduct: null,
8ae03c37
C
74
75 creationReason: null,
ccc00cb2
C
76 moderationInformation: null,
77 administrator: null,
78 maintenanceLifetime: null,
79 businessModel: null,
80
be04c6fd
C
81 hardwareInformation: null,
82
ccc00cb2
C
83 categories: null,
84 languages: null,
85
86 defaultClientRoute: null,
87
3866f1a0
C
88 customizations: {
89 javascript: null,
90 css: null
91 }
92 },
7cd4d2ba
C
93 theme: {
94 default: null
95 },
3866f1a0
C
96 services: {
97 twitter: {
7ed1edbb 98 username: SERVICES_TWITTER_USERNAME_VALIDATOR,
3866f1a0
C
99 whitelisted: null
100 }
101 },
102 cache: {
103 previews: {
7ed1edbb 104 size: CACHE_PREVIEWS_SIZE_VALIDATOR
3866f1a0
C
105 },
106 captions: {
7ed1edbb 107 size: CACHE_CAPTIONS_SIZE_VALIDATOR
b3d5cb92
C
108 },
109 torrents: {
110 size: CACHE_CAPTIONS_SIZE_VALIDATOR
3866f1a0
C
111 }
112 },
113 signup: {
114 enabled: null,
7ed1edbb 115 limit: SIGNUP_LIMIT_VALIDATOR,
3866f1a0
C
116 requiresEmailVerification: null
117 },
118 import: {
119 videos: {
9129b769 120 concurrency: CONCURRENCY_VALIDATOR,
3866f1a0
C
121 http: {
122 enabled: null
123 },
124 torrent: {
125 enabled: null
126 }
127 }
128 },
ba5d4a84
RK
129 trending: {
130 videos: {
131 algorithms: {
132 enabled: null,
133 default: null
134 }
135 }
136 },
3866f1a0 137 admin: {
7ed1edbb 138 email: ADMIN_EMAIL_VALIDATOR
3866f1a0
C
139 },
140 contactForm: {
141 enabled: null
142 },
143 user: {
7ed1edbb
C
144 videoQuota: USER_VIDEO_QUOTA_VALIDATOR,
145 videoQuotaDaily: USER_VIDEO_QUOTA_DAILY_VALIDATOR
3866f1a0
C
146 },
147 transcoding: {
148 enabled: null,
7ed1edbb 149 threads: TRANSCODING_THREADS_VALIDATOR,
3866f1a0 150 allowAdditionalExtensions: null,
536598cf 151 allowAudioFiles: null,
80ac2e55 152 profile: null,
9129b769 153 concurrency: CONCURRENCY_VALIDATOR,
5d9e4eaa
C
154 resolutions: {},
155 hls: {
156 enabled: null
5a71acd2
C
157 },
158 webtorrent: {
159 enabled: null
5d9e4eaa 160 }
7ccddd7b 161 },
c6c0fa6c
C
162 live: {
163 enabled: null,
164
4e55c132
C
165 maxDuration: MAX_LIVE_DURATION_VALIDATOR,
166 maxInstanceLives: MAX_INSTANCE_LIVES_VALIDATOR,
167 maxUserLives: MAX_USER_LIVES_VALIDATOR,
fb719404
C
168 allowReplay: null,
169
c6c0fa6c
C
170 transcoding: {
171 enabled: null,
172 threads: TRANSCODING_THREADS_VALIDATOR,
80ac2e55 173 profile: null,
c6c0fa6c
C
174 resolutions: {}
175 }
176 },
7ccddd7b
JM
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,
7ed1edbb 197 indexUrl: INDEX_URL_VALIDATOR
e1b49ee5
C
198 }
199 }
72c33e71
C
200 },
201 broadcastMessage: {
202 enabled: null,
203 level: null,
204 dismissable: null,
205 message: null
5fb2e288
C
206 },
207 search: {
208 remoteUri: {
209 users: null,
210 anonymous: null
211 },
212 searchIndex: {
213 enabled: null,
7ed1edbb 214 url: SEARCH_INDEX_URL_VALIDATOR,
5fb2e288
C
215 disableLocalSearch: null,
216 isDefaultSearch: null
217 }
3866f1a0 218 }
fd206f0b
C
219 }
220
3866f1a0
C
221 const defaultValues = {
222 transcoding: {
223 resolutions: {}
c6c0fa6c
C
224 },
225 live: {
226 transcoding: {
227 resolutions: {}
228 }
3866f1a0
C
229 }
230 }
c6c0fa6c 231
5f46d28c 232 for (const resolution of this.editConfigurationService.getVODResolutions()) {
00aa1f0d
C
233 defaultValues.transcoding.resolutions[resolution.id] = 'false'
234 formGroupData.transcoding.resolutions[resolution.id] = null
fd206f0b
C
235 }
236
5f46d28c 237 for (const resolution of this.editConfigurationService.getLiveResolutions()) {
c6c0fa6c
C
238 defaultValues.live.transcoding.resolutions[resolution.id] = 'false'
239 formGroupData.live.transcoding.resolutions[resolution.id] = null
240 }
241
d18d6478 242 this.buildForm(formGroupData)
16a173bb 243
5f46d28c
C
244 if (this.route.snapshot.fragment) {
245 this.onNavChange(this.route.snapshot.fragment)
45e0d669 246 }
5fb2e288 247
5f46d28c
C
248 this.loadConfigAndUpdateForm()
249 this.loadCategoriesAndLanguages()
3da68f0a
RK
250 }
251
1f30a185 252 async formValidated () {
210856a7
C
253 const value: CustomConfig = this.form.getRawValue()
254
210856a7 255 this.configService.updateCustomConfig(value)
fd206f0b
C
256 .subscribe(
257 res => {
258 this.customConfig = res
259
260 // Reload general configuration
ba430d75 261 this.serverService.resetConfig()
fd206f0b
C
262
263 this.updateForm()
66b16caf 264
66357162 265 this.notifier.success($localize`Configuration updated.`)
fd206f0b
C
266 },
267
f8b2c1b4 268 err => this.notifier.error(err.message)
fd206f0b
C
269 )
270 }
271
fb719404
C
272 hasConsistentOptions () {
273 if (this.hasLiveAllowReplayConsistentOptions()) return true
274
275 return false
276 }
277
278 hasLiveAllowReplayConsistentOptions () {
5f46d28c
C
279 if (
280 this.editConfigurationService.isTranscodingEnabled(this.form) === false &&
281 this.editConfigurationService.isLiveEnabled(this.form) &&
282 this.form.value['live']['allowReplay'] === true
283 ) {
fb719404
C
284 return false
285 }
286
287 return true
288 }
289
53e4e201
C
290 onNavChange (newActiveNav: string) {
291 this.activeNav = newActiveNav
292
293 this.router.navigate([], { fragment: this.activeNav })
294 }
295
45ba09fe
C
296 grabAllErrors (errorObjectArg?: any) {
297 const errorObject = errorObjectArg || this.formErrors
298
299 let acc: string[] = []
300
301 for (const key of Object.keys(errorObject)) {
302 const value = errorObject[key]
303 if (!value) continue
304
305 if (typeof value === 'string') {
306 acc.push(value)
307 } else {
308 acc = acc.concat(this.grabAllErrors(value))
309 }
310 }
311
312 return acc
313 }
314
fd206f0b 315 private updateForm () {
3866f1a0 316 this.form.patchValue(this.customConfig)
fd206f0b 317 }
04cda1d7 318
5f46d28c
C
319 private loadConfigAndUpdateForm () {
320 this.configService.getCustomConfig()
321 .subscribe(config => {
04cda1d7
C
322 this.customConfig = config
323
04cda1d7
C
324 this.updateForm()
325 // Force form validation
326 this.forceCheck()
327 },
328
329 err => this.notifier.error(err.message)
330 )
331 }
332
5f46d28c
C
333 private loadCategoriesAndLanguages () {
334 forkJoin([
335 this.serverService.getVideoLanguages(),
336 this.serverService.getVideoCategories()
337 ]).subscribe(
338 ([ languages, categories ]) => {
339 this.languageItems = languages.map(l => ({ label: l.label, id: l.id }))
340 this.categoryItems = categories.map(l => ({ label: l.label, id: l.id + '' }))
341 },
16a173bb 342
5f46d28c
C
343 err => this.notifier.error(err.message)
344 )
16a173bb 345 }
fd206f0b 346}