]>
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, | |
7ed1edbb C |
21 | SEARCH_INDEX_URL_VALIDATOR, |
22 | SERVICES_TWITTER_USERNAME_VALIDATOR, | |
23 | SIGNUP_LIMIT_VALIDATOR, | |
1f256e7d | 24 | SIGNUP_MINIMUM_AGE_VALIDATOR, |
754b6f5f FC |
25 | TRANSCODING_THREADS_VALIDATOR, |
26 | MAX_VIDEO_CHANNELS_PER_USER_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' | |
21e493d4 | 29 | import { FormReactive, FormValidatorService } 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 ( |
53e4e201 C |
55 | private router: Router, |
56 | private route: ActivatedRoute, | |
d18d6478 | 57 | protected formValidatorService: FormValidatorService, |
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 | }, | |
109 | cache: { | |
110 | previews: { | |
7ed1edbb | 111 | size: CACHE_PREVIEWS_SIZE_VALIDATOR |
3866f1a0 C |
112 | }, |
113 | captions: { | |
7ed1edbb | 114 | size: CACHE_CAPTIONS_SIZE_VALIDATOR |
b3d5cb92 C |
115 | }, |
116 | torrents: { | |
117 | size: CACHE_CAPTIONS_SIZE_VALIDATOR | |
3866f1a0 C |
118 | } |
119 | }, | |
120 | signup: { | |
121 | enabled: null, | |
7ed1edbb | 122 | limit: SIGNUP_LIMIT_VALIDATOR, |
1f256e7d P |
123 | requiresEmailVerification: null, |
124 | minimumAge: SIGNUP_MINIMUM_AGE_VALIDATOR | |
3866f1a0 C |
125 | }, |
126 | import: { | |
127 | videos: { | |
9129b769 | 128 | concurrency: CONCURRENCY_VALIDATOR, |
3866f1a0 C |
129 | http: { |
130 | enabled: null | |
131 | }, | |
132 | torrent: { | |
133 | enabled: null | |
134 | } | |
135 | } | |
136 | }, | |
ba5d4a84 RK |
137 | trending: { |
138 | videos: { | |
139 | algorithms: { | |
140 | enabled: null, | |
141 | default: null | |
142 | } | |
143 | } | |
144 | }, | |
3866f1a0 | 145 | admin: { |
7ed1edbb | 146 | email: ADMIN_EMAIL_VALIDATOR |
3866f1a0 C |
147 | }, |
148 | contactForm: { | |
149 | enabled: null | |
150 | }, | |
151 | user: { | |
7ed1edbb C |
152 | videoQuota: USER_VIDEO_QUOTA_VALIDATOR, |
153 | videoQuotaDaily: USER_VIDEO_QUOTA_DAILY_VALIDATOR | |
3866f1a0 | 154 | }, |
754b6f5f FC |
155 | videoChannels: { |
156 | maxPerUser: MAX_VIDEO_CHANNELS_PER_USER_VALIDATOR | |
157 | }, | |
3866f1a0 C |
158 | transcoding: { |
159 | enabled: null, | |
7ed1edbb | 160 | threads: TRANSCODING_THREADS_VALIDATOR, |
3866f1a0 | 161 | allowAdditionalExtensions: null, |
536598cf | 162 | allowAudioFiles: null, |
80ac2e55 | 163 | profile: null, |
9129b769 | 164 | concurrency: CONCURRENCY_VALIDATOR, |
5d9e4eaa C |
165 | resolutions: {}, |
166 | hls: { | |
167 | enabled: null | |
5a71acd2 C |
168 | }, |
169 | webtorrent: { | |
170 | enabled: null | |
5d9e4eaa | 171 | } |
7ccddd7b | 172 | }, |
c6c0fa6c C |
173 | live: { |
174 | enabled: null, | |
175 | ||
4e55c132 C |
176 | maxDuration: MAX_LIVE_DURATION_VALIDATOR, |
177 | maxInstanceLives: MAX_INSTANCE_LIVES_VALIDATOR, | |
178 | maxUserLives: MAX_USER_LIVES_VALIDATOR, | |
fb719404 C |
179 | allowReplay: null, |
180 | ||
c6c0fa6c C |
181 | transcoding: { |
182 | enabled: null, | |
183 | threads: TRANSCODING_THREADS_VALIDATOR, | |
80ac2e55 | 184 | profile: null, |
c6c0fa6c C |
185 | resolutions: {} |
186 | } | |
187 | }, | |
7ccddd7b JM |
188 | autoBlacklist: { |
189 | videos: { | |
190 | ofUsers: { | |
191 | enabled: null | |
192 | } | |
193 | } | |
0dc64777 C |
194 | }, |
195 | followers: { | |
196 | instance: { | |
197 | enabled: null, | |
198 | manualApproval: null | |
199 | } | |
e1b49ee5 C |
200 | }, |
201 | followings: { | |
202 | instance: { | |
203 | autoFollowBack: { | |
204 | enabled: null | |
205 | }, | |
206 | autoFollowIndex: { | |
207 | enabled: null, | |
7ed1edbb | 208 | indexUrl: INDEX_URL_VALIDATOR |
e1b49ee5 C |
209 | } |
210 | } | |
72c33e71 C |
211 | }, |
212 | broadcastMessage: { | |
213 | enabled: null, | |
214 | level: null, | |
215 | dismissable: null, | |
216 | message: null | |
5fb2e288 C |
217 | }, |
218 | search: { | |
219 | remoteUri: { | |
220 | users: null, | |
221 | anonymous: null | |
222 | }, | |
223 | searchIndex: { | |
224 | enabled: null, | |
7ed1edbb | 225 | url: SEARCH_INDEX_URL_VALIDATOR, |
5fb2e288 C |
226 | disableLocalSearch: null, |
227 | isDefaultSearch: null | |
228 | } | |
2539932e C |
229 | }, |
230 | ||
231 | instanceCustomHomepage: { | |
232 | content: null | |
3866f1a0 | 233 | } |
fd206f0b C |
234 | } |
235 | ||
3866f1a0 C |
236 | const defaultValues = { |
237 | transcoding: { | |
238 | resolutions: {} | |
c6c0fa6c C |
239 | }, |
240 | live: { | |
241 | transcoding: { | |
242 | resolutions: {} | |
243 | } | |
3866f1a0 C |
244 | } |
245 | } | |
c6c0fa6c | 246 | |
5f46d28c | 247 | for (const resolution of this.editConfigurationService.getVODResolutions()) { |
00aa1f0d C |
248 | defaultValues.transcoding.resolutions[resolution.id] = 'false' |
249 | formGroupData.transcoding.resolutions[resolution.id] = null | |
fd206f0b C |
250 | } |
251 | ||
5f46d28c | 252 | for (const resolution of this.editConfigurationService.getLiveResolutions()) { |
c6c0fa6c C |
253 | defaultValues.live.transcoding.resolutions[resolution.id] = 'false' |
254 | formGroupData.live.transcoding.resolutions[resolution.id] = null | |
255 | } | |
256 | ||
d18d6478 | 257 | this.buildForm(formGroupData) |
16a173bb | 258 | |
5f46d28c C |
259 | if (this.route.snapshot.fragment) { |
260 | this.onNavChange(this.route.snapshot.fragment) | |
45e0d669 | 261 | } |
5fb2e288 | 262 | |
5f46d28c C |
263 | this.loadConfigAndUpdateForm() |
264 | this.loadCategoriesAndLanguages() | |
cf0c8ee5 C |
265 | |
266 | if (!this.isUpdateAllowed()) { | |
8d8a037e JB |
267 | this.form.disable() |
268 | } | |
3da68f0a RK |
269 | } |
270 | ||
98ab5dc8 | 271 | formValidated () { |
2539932e | 272 | const value: ComponentCustomConfig = this.form.getRawValue() |
210856a7 | 273 | |
2539932e C |
274 | forkJoin([ |
275 | this.configService.updateCustomConfig(omit(value, 'instanceCustomHomepage')), | |
276 | this.customPage.updateInstanceHomepage(value.instanceCustomHomepage.content) | |
277 | ]) | |
1378c0d3 C |
278 | .subscribe({ |
279 | next: ([ resConfig ]) => { | |
2539932e C |
280 | const instanceCustomHomepage = { |
281 | content: value.instanceCustomHomepage.content | |
282 | } | |
283 | ||
284 | this.customConfig = { ...resConfig, instanceCustomHomepage } | |
fd206f0b C |
285 | |
286 | // Reload general configuration | |
ba430d75 | 287 | this.serverService.resetConfig() |
9df52d66 C |
288 | .subscribe(config => { |
289 | this.serverConfig = config | |
290 | }) | |
fd206f0b C |
291 | |
292 | this.updateForm() | |
66b16caf | 293 | |
66357162 | 294 | this.notifier.success($localize`Configuration updated.`) |
fd206f0b C |
295 | }, |
296 | ||
1378c0d3 C |
297 | error: err => this.notifier.error(err.message) |
298 | }) | |
fd206f0b C |
299 | } |
300 | ||
cf0c8ee5 C |
301 | isUpdateAllowed () { |
302 | return this.serverConfig.webadmin.configuration.edition.allowed === true | |
303 | } | |
304 | ||
fb719404 C |
305 | hasConsistentOptions () { |
306 | if (this.hasLiveAllowReplayConsistentOptions()) return true | |
307 | ||
308 | return false | |
309 | } | |
310 | ||
311 | hasLiveAllowReplayConsistentOptions () { | |
5f46d28c C |
312 | if ( |
313 | this.editConfigurationService.isTranscodingEnabled(this.form) === false && | |
314 | this.editConfigurationService.isLiveEnabled(this.form) && | |
315 | this.form.value['live']['allowReplay'] === true | |
316 | ) { | |
fb719404 C |
317 | return false |
318 | } | |
319 | ||
320 | return true | |
321 | } | |
322 | ||
53e4e201 C |
323 | onNavChange (newActiveNav: string) { |
324 | this.activeNav = newActiveNav | |
325 | ||
326 | this.router.navigate([], { fragment: this.activeNav }) | |
327 | } | |
328 | ||
45ba09fe C |
329 | grabAllErrors (errorObjectArg?: any) { |
330 | const errorObject = errorObjectArg || this.formErrors | |
331 | ||
332 | let acc: string[] = [] | |
333 | ||
334 | for (const key of Object.keys(errorObject)) { | |
335 | const value = errorObject[key] | |
336 | if (!value) continue | |
337 | ||
338 | if (typeof value === 'string') { | |
339 | acc.push(value) | |
340 | } else { | |
341 | acc = acc.concat(this.grabAllErrors(value)) | |
342 | } | |
343 | } | |
344 | ||
345 | return acc | |
346 | } | |
347 | ||
fd206f0b | 348 | private updateForm () { |
3866f1a0 | 349 | this.form.patchValue(this.customConfig) |
fd206f0b | 350 | } |
04cda1d7 | 351 | |
5f46d28c | 352 | private loadConfigAndUpdateForm () { |
2539932e C |
353 | forkJoin([ |
354 | this.configService.getCustomConfig(), | |
355 | this.customPage.getInstanceHomepage() | |
1378c0d3 C |
356 | ]).subscribe({ |
357 | next: ([ config, homepage ]) => { | |
2539932e | 358 | this.customConfig = { ...config, instanceCustomHomepage: homepage } |
04cda1d7 | 359 | |
04cda1d7 C |
360 | this.updateForm() |
361 | // Force form validation | |
362 | this.forceCheck() | |
363 | }, | |
364 | ||
1378c0d3 C |
365 | error: err => this.notifier.error(err.message) |
366 | }) | |
04cda1d7 C |
367 | } |
368 | ||
5f46d28c C |
369 | private loadCategoriesAndLanguages () { |
370 | forkJoin([ | |
371 | this.serverService.getVideoLanguages(), | |
372 | this.serverService.getVideoCategories() | |
1378c0d3 C |
373 | ]).subscribe({ |
374 | next: ([ languages, categories ]) => { | |
5f46d28c C |
375 | this.languageItems = languages.map(l => ({ label: l.label, id: l.id })) |
376 | this.categoryItems = categories.map(l => ({ label: l.label, id: l.id + '' })) | |
377 | }, | |
16a173bb | 378 | |
1378c0d3 C |
379 | error: err => this.notifier.error(err.message) |
380 | }) | |
16a173bb | 381 | } |
fd206f0b | 382 | } |