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