]>
Commit | Line | Data |
---|---|---|
5f46d28c | 1 | |
2539932e | 2 | import omit from 'lodash-es/omit' |
4e55c132 C |
3 | import { forkJoin } from 'rxjs' |
4 | import { SelectOptionsItem } from 'src/types/select-options-item.model' | |
5f46d28c | 5 | import { Component, OnInit } from '@angular/core' |
53e4e201 | 6 | import { ActivatedRoute, Router } from '@angular/router' |
67ed6552 C |
7 | import { ConfigService } from '@app/+admin/config/shared/config.service' |
8 | import { Notifier } from '@app/core' | |
9 | import { ServerService } from '@app/core/server/server.service' | |
52c4976f | 10 | import { |
7ed1edbb C |
11 | ADMIN_EMAIL_VALIDATOR, |
12 | CACHE_CAPTIONS_SIZE_VALIDATOR, | |
13 | CACHE_PREVIEWS_SIZE_VALIDATOR, | |
9129b769 | 14 | CONCURRENCY_VALIDATOR, |
7ed1edbb C |
15 | INDEX_URL_VALIDATOR, |
16 | INSTANCE_NAME_VALIDATOR, | |
17 | INSTANCE_SHORT_DESCRIPTION_VALIDATOR, | |
4e55c132 C |
18 | MAX_INSTANCE_LIVES_VALIDATOR, |
19 | MAX_LIVE_DURATION_VALIDATOR, | |
20 | MAX_USER_LIVES_VALIDATOR, | |
5c5bcea2 | 21 | MAX_VIDEO_CHANNELS_PER_USER_VALIDATOR, |
7ed1edbb C |
22 | SEARCH_INDEX_URL_VALIDATOR, |
23 | SERVICES_TWITTER_USERNAME_VALIDATOR, | |
24 | SIGNUP_LIMIT_VALIDATOR, | |
1f256e7d | 25 | SIGNUP_MINIMUM_AGE_VALIDATOR, |
5c5bcea2 | 26 | TRANSCODING_THREADS_VALIDATOR |
7ed1edbb C |
27 | } from '@app/shared/form-validators/custom-config-validators' |
28 | import { USER_VIDEO_QUOTA_DAILY_VALIDATOR, USER_VIDEO_QUOTA_VALIDATOR } from '@app/shared/form-validators/user-validators' | |
5c5bcea2 | 29 | import { FormReactive, FormReactiveService } from '@app/shared/shared-forms' |
2539932e | 30 | import { CustomPageService } from '@app/shared/shared-main/custom-page' |
2989628b | 31 | import { CustomConfig, CustomPage, HTMLServerConfig } from '@shared/models' |
5f46d28c | 32 | import { EditConfigurationService } from './edit-configuration.service' |
fd206f0b | 33 | |
2539932e C |
34 | type ComponentCustomConfig = CustomConfig & { |
35 | instanceCustomHomepage: CustomPage | |
36 | } | |
37 | ||
fd206f0b C |
38 | @Component({ |
39 | selector: 'my-edit-custom-config', | |
40 | templateUrl: './edit-custom-config.component.html', | |
41 | styleUrls: [ './edit-custom-config.component.scss' ] | |
42 | }) | |
5f46d28c C |
43 | export class EditCustomConfigComponent extends FormReactive implements OnInit { |
44 | activeNav: string | |
45e0d669 | 45 | |
2539932e | 46 | customConfig: ComponentCustomConfig |
2989628b | 47 | serverConfig: HTMLServerConfig |
80ac2e55 | 48 | |
2539932e C |
49 | homepage: CustomPage |
50 | ||
52c4976f C |
51 | languageItems: SelectOptionsItem[] = [] |
52 | categoryItems: SelectOptionsItem[] = [] | |
ccc00cb2 | 53 | |
fd206f0b | 54 | constructor ( |
5c5bcea2 | 55 | protected formReactiveService: FormReactiveService, |
53e4e201 C |
56 | private router: Router, |
57 | private route: ActivatedRoute, | |
f8b2c1b4 | 58 | private notifier: Notifier, |
fd206f0b | 59 | private configService: ConfigService, |
2539932e | 60 | private customPage: CustomPageService, |
5f46d28c C |
61 | private serverService: ServerService, |
62 | private editConfigurationService: EditConfigurationService | |
fd206f0b C |
63 | ) { |
64 | super() | |
fd206f0b C |
65 | } |
66 | ||
d18d6478 | 67 | ngOnInit () { |
2989628b | 68 | this.serverConfig = this.serverService.getHTMLConfig() |
ba430d75 | 69 | |
2539932e | 70 | const formGroupData: { [key in keyof ComponentCustomConfig ]: any } = { |
3866f1a0 | 71 | instance: { |
7ed1edbb C |
72 | name: INSTANCE_NAME_VALIDATOR, |
73 | shortDescription: INSTANCE_SHORT_DESCRIPTION_VALIDATOR, | |
3866f1a0 | 74 | description: null, |
ccc00cb2 | 75 | |
f8802489 | 76 | isNSFW: false, |
3866f1a0 | 77 | defaultNSFWPolicy: null, |
ccc00cb2 C |
78 | |
79 | terms: null, | |
80 | codeOfConduct: null, | |
8ae03c37 C |
81 | |
82 | creationReason: null, | |
ccc00cb2 C |
83 | moderationInformation: null, |
84 | administrator: null, | |
85 | maintenanceLifetime: null, | |
86 | businessModel: null, | |
87 | ||
be04c6fd C |
88 | hardwareInformation: null, |
89 | ||
ccc00cb2 C |
90 | categories: null, |
91 | languages: null, | |
92 | ||
93 | defaultClientRoute: null, | |
94 | ||
3866f1a0 C |
95 | customizations: { |
96 | javascript: null, | |
97 | css: null | |
98 | } | |
99 | }, | |
7cd4d2ba C |
100 | theme: { |
101 | default: null | |
102 | }, | |
3866f1a0 C |
103 | services: { |
104 | twitter: { | |
7ed1edbb | 105 | username: SERVICES_TWITTER_USERNAME_VALIDATOR, |
3866f1a0 C |
106 | whitelisted: null |
107 | } | |
108 | }, | |
0bc53e20 C |
109 | client: { |
110 | videos: { | |
111 | miniature: { | |
112 | preferAuthorDisplayName: null | |
113 | } | |
114 | }, | |
115 | menu: { | |
116 | login: { | |
117 | redirectOnSingleExternalAuth: null | |
118 | } | |
119 | } | |
120 | }, | |
3866f1a0 C |
121 | cache: { |
122 | previews: { | |
7ed1edbb | 123 | size: CACHE_PREVIEWS_SIZE_VALIDATOR |
3866f1a0 C |
124 | }, |
125 | captions: { | |
7ed1edbb | 126 | size: CACHE_CAPTIONS_SIZE_VALIDATOR |
b3d5cb92 C |
127 | }, |
128 | torrents: { | |
129 | size: CACHE_CAPTIONS_SIZE_VALIDATOR | |
3866f1a0 C |
130 | } |
131 | }, | |
132 | signup: { | |
133 | enabled: null, | |
7ed1edbb | 134 | limit: SIGNUP_LIMIT_VALIDATOR, |
9589907c | 135 | requiresApproval: null, |
1f256e7d P |
136 | requiresEmailVerification: null, |
137 | minimumAge: SIGNUP_MINIMUM_AGE_VALIDATOR | |
3866f1a0 C |
138 | }, |
139 | import: { | |
140 | videos: { | |
9129b769 | 141 | concurrency: CONCURRENCY_VALIDATOR, |
3866f1a0 C |
142 | http: { |
143 | enabled: null | |
144 | }, | |
145 | torrent: { | |
146 | enabled: null | |
147 | } | |
2a491182 F |
148 | }, |
149 | videoChannelSynchronization: { | |
150 | enabled: null | |
3866f1a0 C |
151 | } |
152 | }, | |
ba5d4a84 RK |
153 | trending: { |
154 | videos: { | |
155 | algorithms: { | |
156 | enabled: null, | |
157 | default: null | |
158 | } | |
159 | } | |
160 | }, | |
3866f1a0 | 161 | admin: { |
7ed1edbb | 162 | email: ADMIN_EMAIL_VALIDATOR |
3866f1a0 C |
163 | }, |
164 | contactForm: { | |
165 | enabled: null | |
166 | }, | |
167 | user: { | |
b302c80d W |
168 | history: { |
169 | videos: { | |
170 | enabled: null | |
171 | } | |
172 | }, | |
7ed1edbb C |
173 | videoQuota: USER_VIDEO_QUOTA_VALIDATOR, |
174 | videoQuotaDaily: USER_VIDEO_QUOTA_DAILY_VALIDATOR | |
3866f1a0 | 175 | }, |
754b6f5f FC |
176 | videoChannels: { |
177 | maxPerUser: MAX_VIDEO_CHANNELS_PER_USER_VALIDATOR | |
178 | }, | |
3866f1a0 C |
179 | transcoding: { |
180 | enabled: null, | |
7ed1edbb | 181 | threads: TRANSCODING_THREADS_VALIDATOR, |
3866f1a0 | 182 | allowAdditionalExtensions: null, |
536598cf | 183 | allowAudioFiles: null, |
80ac2e55 | 184 | profile: null, |
9129b769 | 185 | concurrency: CONCURRENCY_VALIDATOR, |
5d9e4eaa | 186 | resolutions: {}, |
84cae54e | 187 | alwaysTranscodeOriginalResolution: null, |
5d9e4eaa C |
188 | hls: { |
189 | enabled: null | |
5a71acd2 C |
190 | }, |
191 | webtorrent: { | |
192 | enabled: null | |
5d9e4eaa | 193 | } |
7ccddd7b | 194 | }, |
c6c0fa6c C |
195 | live: { |
196 | enabled: null, | |
197 | ||
4e55c132 C |
198 | maxDuration: MAX_LIVE_DURATION_VALIDATOR, |
199 | maxInstanceLives: MAX_INSTANCE_LIVES_VALIDATOR, | |
200 | maxUserLives: MAX_USER_LIVES_VALIDATOR, | |
fb719404 | 201 | allowReplay: null, |
f443a746 C |
202 | latencySetting: { |
203 | enabled: null | |
204 | }, | |
fb719404 | 205 | |
c6c0fa6c C |
206 | transcoding: { |
207 | enabled: null, | |
208 | threads: TRANSCODING_THREADS_VALIDATOR, | |
80ac2e55 | 209 | profile: null, |
84cae54e C |
210 | resolutions: {}, |
211 | alwaysTranscodeOriginalResolution: null | |
c6c0fa6c C |
212 | } |
213 | }, | |
92e66e04 | 214 | videoStudio: { |
c729caf6 C |
215 | enabled: null |
216 | }, | |
7ccddd7b JM |
217 | autoBlacklist: { |
218 | videos: { | |
219 | ofUsers: { | |
220 | enabled: null | |
221 | } | |
222 | } | |
0dc64777 C |
223 | }, |
224 | followers: { | |
225 | instance: { | |
226 | enabled: null, | |
227 | manualApproval: null | |
228 | } | |
e1b49ee5 C |
229 | }, |
230 | followings: { | |
231 | instance: { | |
232 | autoFollowBack: { | |
233 | enabled: null | |
234 | }, | |
235 | autoFollowIndex: { | |
236 | enabled: null, | |
7ed1edbb | 237 | indexUrl: INDEX_URL_VALIDATOR |
e1b49ee5 C |
238 | } |
239 | } | |
72c33e71 C |
240 | }, |
241 | broadcastMessage: { | |
242 | enabled: null, | |
243 | level: null, | |
244 | dismissable: null, | |
245 | message: null | |
5fb2e288 C |
246 | }, |
247 | search: { | |
248 | remoteUri: { | |
249 | users: null, | |
250 | anonymous: null | |
251 | }, | |
252 | searchIndex: { | |
253 | enabled: null, | |
7ed1edbb | 254 | url: SEARCH_INDEX_URL_VALIDATOR, |
5fb2e288 C |
255 | disableLocalSearch: null, |
256 | isDefaultSearch: null | |
257 | } | |
2539932e C |
258 | }, |
259 | ||
260 | instanceCustomHomepage: { | |
261 | content: null | |
3866f1a0 | 262 | } |
fd206f0b C |
263 | } |
264 | ||
3866f1a0 C |
265 | const defaultValues = { |
266 | transcoding: { | |
267 | resolutions: {} | |
c6c0fa6c C |
268 | }, |
269 | live: { | |
270 | transcoding: { | |
271 | resolutions: {} | |
272 | } | |
3866f1a0 C |
273 | } |
274 | } | |
c6c0fa6c | 275 | |
5f46d28c | 276 | for (const resolution of this.editConfigurationService.getVODResolutions()) { |
00aa1f0d C |
277 | defaultValues.transcoding.resolutions[resolution.id] = 'false' |
278 | formGroupData.transcoding.resolutions[resolution.id] = null | |
fd206f0b C |
279 | } |
280 | ||
5f46d28c | 281 | for (const resolution of this.editConfigurationService.getLiveResolutions()) { |
c6c0fa6c C |
282 | defaultValues.live.transcoding.resolutions[resolution.id] = 'false' |
283 | formGroupData.live.transcoding.resolutions[resolution.id] = null | |
284 | } | |
285 | ||
d18d6478 | 286 | this.buildForm(formGroupData) |
16a173bb | 287 | |
5f46d28c C |
288 | if (this.route.snapshot.fragment) { |
289 | this.onNavChange(this.route.snapshot.fragment) | |
45e0d669 | 290 | } |
5fb2e288 | 291 | |
5f46d28c C |
292 | this.loadConfigAndUpdateForm() |
293 | this.loadCategoriesAndLanguages() | |
cf0c8ee5 C |
294 | |
295 | if (!this.isUpdateAllowed()) { | |
8d8a037e JB |
296 | this.form.disable() |
297 | } | |
3da68f0a RK |
298 | } |
299 | ||
98ab5dc8 | 300 | formValidated () { |
8b69f9f0 C |
301 | this.forceCheck() |
302 | if (!this.form.valid) return | |
303 | ||
2539932e | 304 | const value: ComponentCustomConfig = this.form.getRawValue() |
210856a7 | 305 | |
2539932e C |
306 | forkJoin([ |
307 | this.configService.updateCustomConfig(omit(value, 'instanceCustomHomepage')), | |
308 | this.customPage.updateInstanceHomepage(value.instanceCustomHomepage.content) | |
309 | ]) | |
1378c0d3 C |
310 | .subscribe({ |
311 | next: ([ resConfig ]) => { | |
2539932e C |
312 | const instanceCustomHomepage = { |
313 | content: value.instanceCustomHomepage.content | |
314 | } | |
315 | ||
316 | this.customConfig = { ...resConfig, instanceCustomHomepage } | |
fd206f0b C |
317 | |
318 | // Reload general configuration | |
ba430d75 | 319 | this.serverService.resetConfig() |
9df52d66 C |
320 | .subscribe(config => { |
321 | this.serverConfig = config | |
322 | }) | |
fd206f0b C |
323 | |
324 | this.updateForm() | |
66b16caf | 325 | |
66357162 | 326 | this.notifier.success($localize`Configuration updated.`) |
fd206f0b C |
327 | }, |
328 | ||
1378c0d3 C |
329 | error: err => this.notifier.error(err.message) |
330 | }) | |
fd206f0b C |
331 | } |
332 | ||
cf0c8ee5 C |
333 | isUpdateAllowed () { |
334 | return this.serverConfig.webadmin.configuration.edition.allowed === true | |
335 | } | |
336 | ||
fb719404 C |
337 | hasConsistentOptions () { |
338 | if (this.hasLiveAllowReplayConsistentOptions()) return true | |
339 | ||
340 | return false | |
341 | } | |
342 | ||
343 | hasLiveAllowReplayConsistentOptions () { | |
5f46d28c C |
344 | if ( |
345 | this.editConfigurationService.isTranscodingEnabled(this.form) === false && | |
346 | this.editConfigurationService.isLiveEnabled(this.form) && | |
347 | this.form.value['live']['allowReplay'] === true | |
348 | ) { | |
fb719404 C |
349 | return false |
350 | } | |
351 | ||
352 | return true | |
353 | } | |
354 | ||
53e4e201 C |
355 | onNavChange (newActiveNav: string) { |
356 | this.activeNav = newActiveNav | |
357 | ||
358 | this.router.navigate([], { fragment: this.activeNav }) | |
359 | } | |
360 | ||
45ba09fe C |
361 | grabAllErrors (errorObjectArg?: any) { |
362 | const errorObject = errorObjectArg || this.formErrors | |
363 | ||
364 | let acc: string[] = [] | |
365 | ||
366 | for (const key of Object.keys(errorObject)) { | |
367 | const value = errorObject[key] | |
368 | if (!value) continue | |
369 | ||
370 | if (typeof value === 'string') { | |
371 | acc.push(value) | |
372 | } else { | |
373 | acc = acc.concat(this.grabAllErrors(value)) | |
374 | } | |
375 | } | |
376 | ||
377 | return acc | |
378 | } | |
379 | ||
fd206f0b | 380 | private updateForm () { |
3866f1a0 | 381 | this.form.patchValue(this.customConfig) |
fd206f0b | 382 | } |
04cda1d7 | 383 | |
5f46d28c | 384 | private loadConfigAndUpdateForm () { |
2539932e C |
385 | forkJoin([ |
386 | this.configService.getCustomConfig(), | |
387 | this.customPage.getInstanceHomepage() | |
1378c0d3 C |
388 | ]).subscribe({ |
389 | next: ([ config, homepage ]) => { | |
2539932e | 390 | this.customConfig = { ...config, instanceCustomHomepage: homepage } |
04cda1d7 | 391 | |
04cda1d7 | 392 | this.updateForm() |
8b69f9f0 | 393 | this.markAllAsDirty() |
04cda1d7 C |
394 | }, |
395 | ||
1378c0d3 C |
396 | error: err => this.notifier.error(err.message) |
397 | }) | |
04cda1d7 C |
398 | } |
399 | ||
5f46d28c C |
400 | private loadCategoriesAndLanguages () { |
401 | forkJoin([ | |
402 | this.serverService.getVideoLanguages(), | |
403 | this.serverService.getVideoCategories() | |
1378c0d3 C |
404 | ]).subscribe({ |
405 | next: ([ languages, categories ]) => { | |
5f46d28c C |
406 | this.languageItems = languages.map(l => ({ label: l.label, id: l.id })) |
407 | this.categoryItems = categories.map(l => ({ label: l.label, id: l.id + '' })) | |
408 | }, | |
16a173bb | 409 | |
1378c0d3 C |
410 | error: err => this.notifier.error(err.message) |
411 | }) | |
16a173bb | 412 | } |
fd206f0b | 413 | } |