]>
Commit | Line | Data |
---|---|---|
fd206f0b | 1 | import { Component, OnInit } from '@angular/core' |
fd206f0b C |
2 | import { ConfigService } from '@app/+admin/config/shared/config.service' |
3 | import { ServerService } from '@app/core/server/server.service' | |
e309822b | 4 | import { CustomConfigValidatorsService, FormReactive, UserValidatorsService } from '@app/shared' |
f8b2c1b4 | 5 | import { Notifier } from '@app/core' |
09cababd | 6 | import { CustomConfig } from '../../../../../../shared/models/server/custom-config.model' |
b1d40cff | 7 | import { I18n } from '@ngx-translate/i18n-polyfill' |
0dc64777 | 8 | import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' |
ccc00cb2 C |
9 | import { SelectItem } from 'primeng/api' |
10 | import { forkJoin } from 'rxjs' | |
ba430d75 | 11 | import { ServerConfig } from '@shared/models' |
fd206f0b C |
12 | |
13 | @Component({ | |
14 | selector: 'my-edit-custom-config', | |
15 | templateUrl: './edit-custom-config.component.html', | |
16 | styleUrls: [ './edit-custom-config.component.scss' ] | |
17 | }) | |
18 | export class EditCustomConfigComponent extends FormReactive implements OnInit { | |
bee0abff | 19 | customConfig: CustomConfig |
bee0abff | 20 | |
46db9430 | 21 | resolutions: { id: string, label: string, description?: string }[] = [] |
3827c3b3 | 22 | transcodingThreadOptions: { label: string, value: number }[] = [] |
fd206f0b | 23 | |
ccc00cb2 C |
24 | languageItems: SelectItem[] = [] |
25 | categoryItems: SelectItem[] = [] | |
26 | ||
ba430d75 C |
27 | private serverConfig: ServerConfig |
28 | ||
fd206f0b | 29 | constructor ( |
d18d6478 | 30 | protected formValidatorService: FormValidatorService, |
e309822b C |
31 | private customConfigValidatorsService: CustomConfigValidatorsService, |
32 | private userValidatorsService: UserValidatorsService, | |
f8b2c1b4 | 33 | private notifier: Notifier, |
fd206f0b | 34 | private configService: ConfigService, |
1f30a185 | 35 | private serverService: ServerService, |
b1d40cff | 36 | private i18n: I18n |
fd206f0b C |
37 | ) { |
38 | super() | |
3827c3b3 C |
39 | |
40 | this.resolutions = [ | |
2fa9c40e | 41 | { |
5c7d6508 | 42 | id: '0p', |
46db9430 | 43 | label: this.i18n('Audio-only'), |
6a07a058 | 44 | description: this.i18n('A <code>.mp4</code> that keeps the original audio track, with no video') |
5c7d6508 | 45 | }, |
00aa1f0d C |
46 | { |
47 | id: '240p', | |
48 | label: this.i18n('240p') | |
49 | }, | |
50 | { | |
51 | id: '360p', | |
52 | label: this.i18n('360p') | |
53 | }, | |
54 | { | |
55 | id: '480p', | |
56 | label: this.i18n('480p') | |
57 | }, | |
58 | { | |
59 | id: '720p', | |
60 | label: this.i18n('720p') | |
61 | }, | |
62 | { | |
63 | id: '1080p', | |
64 | label: this.i18n('1080p') | |
65 | }, | |
66 | { | |
67 | id: '2160p', | |
68 | label: this.i18n('2160p') | |
69 | } | |
3827c3b3 C |
70 | ] |
71 | ||
72 | this.transcodingThreadOptions = [ | |
73 | { value: 0, label: this.i18n('Auto (via ffmpeg)') }, | |
74 | { value: 1, label: '1' }, | |
75 | { value: 2, label: '2' }, | |
76 | { value: 4, label: '4' }, | |
77 | { value: 8, label: '8' } | |
78 | ] | |
fd206f0b C |
79 | } |
80 | ||
41a676db | 81 | get videoQuotaOptions () { |
3827c3b3 | 82 | return this.configService.videoQuotaOptions |
41a676db C |
83 | } |
84 | ||
85 | get videoQuotaDailyOptions () { | |
3827c3b3 | 86 | return this.configService.videoQuotaDailyOptions |
41a676db C |
87 | } |
88 | ||
7cd4d2ba | 89 | get availableThemes () { |
ba430d75 | 90 | return this.serverConfig.theme.registered |
ffb321be | 91 | .map(t => t.name) |
7cd4d2ba C |
92 | } |
93 | ||
fd206f0b | 94 | getResolutionKey (resolution: string) { |
3866f1a0 | 95 | return 'transcoding.resolutions.' + resolution |
fd206f0b C |
96 | } |
97 | ||
d18d6478 | 98 | ngOnInit () { |
ba430d75 C |
99 | this.serverConfig = this.serverService.getTmpConfig() |
100 | this.serverService.getConfig() | |
101 | .subscribe(config => this.serverConfig = config) | |
102 | ||
3866f1a0 C |
103 | const formGroupData: { [key in keyof CustomConfig ]: any } = { |
104 | instance: { | |
105 | name: this.customConfigValidatorsService.INSTANCE_NAME, | |
106 | shortDescription: this.customConfigValidatorsService.INSTANCE_SHORT_DESCRIPTION, | |
107 | description: null, | |
ccc00cb2 | 108 | |
f8802489 | 109 | isNSFW: false, |
3866f1a0 | 110 | defaultNSFWPolicy: null, |
ccc00cb2 C |
111 | |
112 | terms: null, | |
113 | codeOfConduct: null, | |
8ae03c37 C |
114 | |
115 | creationReason: null, | |
ccc00cb2 C |
116 | moderationInformation: null, |
117 | administrator: null, | |
118 | maintenanceLifetime: null, | |
119 | businessModel: null, | |
120 | ||
be04c6fd C |
121 | hardwareInformation: null, |
122 | ||
ccc00cb2 C |
123 | categories: null, |
124 | languages: null, | |
125 | ||
126 | defaultClientRoute: null, | |
127 | ||
3866f1a0 C |
128 | customizations: { |
129 | javascript: null, | |
130 | css: null | |
131 | } | |
132 | }, | |
7cd4d2ba C |
133 | theme: { |
134 | default: null | |
135 | }, | |
3866f1a0 C |
136 | services: { |
137 | twitter: { | |
138 | username: this.customConfigValidatorsService.SERVICES_TWITTER_USERNAME, | |
139 | whitelisted: null | |
140 | } | |
141 | }, | |
142 | cache: { | |
143 | previews: { | |
144 | size: this.customConfigValidatorsService.CACHE_PREVIEWS_SIZE | |
145 | }, | |
146 | captions: { | |
147 | size: this.customConfigValidatorsService.CACHE_CAPTIONS_SIZE | |
148 | } | |
149 | }, | |
150 | signup: { | |
151 | enabled: null, | |
152 | limit: this.customConfigValidatorsService.SIGNUP_LIMIT, | |
153 | requiresEmailVerification: null | |
154 | }, | |
155 | import: { | |
156 | videos: { | |
157 | http: { | |
158 | enabled: null | |
159 | }, | |
160 | torrent: { | |
161 | enabled: null | |
162 | } | |
163 | } | |
164 | }, | |
165 | admin: { | |
166 | email: this.customConfigValidatorsService.ADMIN_EMAIL | |
167 | }, | |
168 | contactForm: { | |
169 | enabled: null | |
170 | }, | |
171 | user: { | |
172 | videoQuota: this.userValidatorsService.USER_VIDEO_QUOTA, | |
173 | videoQuotaDaily: this.userValidatorsService.USER_VIDEO_QUOTA_DAILY | |
174 | }, | |
175 | transcoding: { | |
176 | enabled: null, | |
177 | threads: this.customConfigValidatorsService.TRANSCODING_THREADS, | |
178 | allowAdditionalExtensions: null, | |
536598cf | 179 | allowAudioFiles: null, |
5d9e4eaa C |
180 | resolutions: {}, |
181 | hls: { | |
182 | enabled: null | |
5a71acd2 C |
183 | }, |
184 | webtorrent: { | |
185 | enabled: null | |
5d9e4eaa | 186 | } |
7ccddd7b JM |
187 | }, |
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, | |
208 | indexUrl: this.customConfigValidatorsService.INDEX_URL | |
209 | } | |
210 | } | |
3866f1a0 | 211 | } |
fd206f0b C |
212 | } |
213 | ||
3866f1a0 C |
214 | const defaultValues = { |
215 | transcoding: { | |
216 | resolutions: {} | |
217 | } | |
218 | } | |
fd206f0b | 219 | for (const resolution of this.resolutions) { |
00aa1f0d C |
220 | defaultValues.transcoding.resolutions[resolution.id] = 'false' |
221 | formGroupData.transcoding.resolutions[resolution.id] = null | |
fd206f0b C |
222 | } |
223 | ||
d18d6478 | 224 | this.buildForm(formGroupData) |
04cda1d7 C |
225 | this.loadForm() |
226 | this.checkTranscodingFields() | |
fd206f0b C |
227 | } |
228 | ||
229 | isTranscodingEnabled () { | |
3866f1a0 | 230 | return this.form.value['transcoding']['enabled'] === true |
fd206f0b C |
231 | } |
232 | ||
233 | isSignupEnabled () { | |
3866f1a0 | 234 | return this.form.value['signup']['enabled'] === true |
fd206f0b C |
235 | } |
236 | ||
4ee6a8b1 C |
237 | isAutoFollowIndexEnabled () { |
238 | return this.form.value['followings']['instance']['autoFollowIndex']['enabled'] === true | |
239 | } | |
240 | ||
1f30a185 | 241 | async formValidated () { |
04cda1d7 | 242 | this.configService.updateCustomConfig(this.form.getRawValue()) |
fd206f0b C |
243 | .subscribe( |
244 | res => { | |
245 | this.customConfig = res | |
246 | ||
247 | // Reload general configuration | |
ba430d75 | 248 | this.serverService.resetConfig() |
fd206f0b C |
249 | |
250 | this.updateForm() | |
66b16caf | 251 | |
f8b2c1b4 | 252 | this.notifier.success(this.i18n('Configuration updated.')) |
fd206f0b C |
253 | }, |
254 | ||
f8b2c1b4 | 255 | err => this.notifier.error(err.message) |
fd206f0b C |
256 | ) |
257 | } | |
258 | ||
ccc00cb2 C |
259 | getSelectedLanguageLabel () { |
260 | return this.i18n('{{\'{0} languages selected') | |
261 | } | |
262 | ||
263 | getDefaultLanguageLabel () { | |
264 | return this.i18n('No language') | |
265 | } | |
266 | ||
267 | getSelectedCategoryLabel () { | |
268 | return this.i18n('{{\'{0} categories selected') | |
269 | } | |
270 | ||
271 | getDefaultCategoryLabel () { | |
272 | return this.i18n('No category') | |
273 | } | |
274 | ||
fd206f0b | 275 | private updateForm () { |
3866f1a0 | 276 | this.form.patchValue(this.customConfig) |
fd206f0b | 277 | } |
04cda1d7 C |
278 | |
279 | private loadForm () { | |
280 | forkJoin([ | |
281 | this.configService.getCustomConfig(), | |
282 | this.serverService.getVideoLanguages(), | |
283 | this.serverService.getVideoCategories() | |
284 | ]).subscribe( | |
285 | ([ config, languages, categories ]) => { | |
286 | this.customConfig = config | |
287 | ||
288 | this.languageItems = languages.map(l => ({ label: l.label, value: l.id })) | |
289 | this.categoryItems = categories.map(l => ({ label: l.label, value: l.id })) | |
290 | ||
291 | this.updateForm() | |
292 | // Force form validation | |
293 | this.forceCheck() | |
294 | }, | |
295 | ||
296 | err => this.notifier.error(err.message) | |
297 | ) | |
298 | } | |
299 | ||
300 | private checkTranscodingFields () { | |
301 | const hlsControl = this.form.get('transcoding.hls.enabled') | |
302 | const webtorrentControl = this.form.get('transcoding.webtorrent.enabled') | |
303 | ||
304 | webtorrentControl.valueChanges | |
305 | .subscribe(newValue => { | |
306 | if (newValue === false && !hlsControl.disabled) { | |
307 | hlsControl.disable() | |
308 | } | |
309 | ||
310 | if (newValue === true && !hlsControl.enabled) { | |
311 | hlsControl.enable() | |
312 | } | |
313 | }) | |
314 | ||
315 | hlsControl.valueChanges | |
316 | .subscribe(newValue => { | |
317 | if (newValue === false && !webtorrentControl.disabled) { | |
318 | webtorrentControl.disable() | |
319 | } | |
320 | ||
321 | if (newValue === true && !webtorrentControl.enabled) { | |
322 | webtorrentControl.enable() | |
323 | } | |
324 | }) | |
325 | } | |
fd206f0b | 326 | } |