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