]>
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 | |
00aa1f0d | 21 | resolutions: { id: string, label: 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', |
43 | label: this.i18n('Audio-only') | |
44 | }, | |
00aa1f0d C |
45 | { |
46 | id: '240p', | |
47 | label: this.i18n('240p') | |
48 | }, | |
49 | { | |
50 | id: '360p', | |
51 | label: this.i18n('360p') | |
52 | }, | |
53 | { | |
54 | id: '480p', | |
55 | label: this.i18n('480p') | |
56 | }, | |
57 | { | |
58 | id: '720p', | |
59 | label: this.i18n('720p') | |
60 | }, | |
61 | { | |
62 | id: '1080p', | |
63 | label: this.i18n('1080p') | |
64 | }, | |
65 | { | |
66 | id: '2160p', | |
67 | label: this.i18n('2160p') | |
68 | } | |
3827c3b3 C |
69 | ] |
70 | ||
71 | this.transcodingThreadOptions = [ | |
72 | { value: 0, label: this.i18n('Auto (via ffmpeg)') }, | |
73 | { value: 1, label: '1' }, | |
74 | { value: 2, label: '2' }, | |
75 | { value: 4, label: '4' }, | |
76 | { value: 8, label: '8' } | |
77 | ] | |
fd206f0b C |
78 | } |
79 | ||
41a676db | 80 | get videoQuotaOptions () { |
3827c3b3 | 81 | return this.configService.videoQuotaOptions |
41a676db C |
82 | } |
83 | ||
84 | get videoQuotaDailyOptions () { | |
3827c3b3 | 85 | return this.configService.videoQuotaDailyOptions |
41a676db C |
86 | } |
87 | ||
7cd4d2ba | 88 | get availableThemes () { |
ba430d75 | 89 | return this.serverConfig.theme.registered |
ffb321be | 90 | .map(t => t.name) |
7cd4d2ba C |
91 | } |
92 | ||
fd206f0b | 93 | getResolutionKey (resolution: string) { |
3866f1a0 | 94 | return 'transcoding.resolutions.' + resolution |
fd206f0b C |
95 | } |
96 | ||
d18d6478 | 97 | ngOnInit () { |
ba430d75 C |
98 | this.serverConfig = this.serverService.getTmpConfig() |
99 | this.serverService.getConfig() | |
100 | .subscribe(config => this.serverConfig = config) | |
101 | ||
3866f1a0 C |
102 | const formGroupData: { [key in keyof CustomConfig ]: any } = { |
103 | instance: { | |
104 | name: this.customConfigValidatorsService.INSTANCE_NAME, | |
105 | shortDescription: this.customConfigValidatorsService.INSTANCE_SHORT_DESCRIPTION, | |
106 | description: null, | |
ccc00cb2 | 107 | |
f8802489 | 108 | isNSFW: false, |
3866f1a0 | 109 | defaultNSFWPolicy: null, |
ccc00cb2 C |
110 | |
111 | terms: null, | |
112 | codeOfConduct: null, | |
8ae03c37 C |
113 | |
114 | creationReason: null, | |
ccc00cb2 C |
115 | moderationInformation: null, |
116 | administrator: null, | |
117 | maintenanceLifetime: null, | |
118 | businessModel: null, | |
119 | ||
be04c6fd C |
120 | hardwareInformation: null, |
121 | ||
ccc00cb2 C |
122 | categories: null, |
123 | languages: null, | |
124 | ||
125 | defaultClientRoute: null, | |
126 | ||
3866f1a0 C |
127 | customizations: { |
128 | javascript: null, | |
129 | css: null | |
130 | } | |
131 | }, | |
7cd4d2ba C |
132 | theme: { |
133 | default: null | |
134 | }, | |
3866f1a0 C |
135 | services: { |
136 | twitter: { | |
137 | username: this.customConfigValidatorsService.SERVICES_TWITTER_USERNAME, | |
138 | whitelisted: null | |
139 | } | |
140 | }, | |
141 | cache: { | |
142 | previews: { | |
143 | size: this.customConfigValidatorsService.CACHE_PREVIEWS_SIZE | |
144 | }, | |
145 | captions: { | |
146 | size: this.customConfigValidatorsService.CACHE_CAPTIONS_SIZE | |
147 | } | |
148 | }, | |
149 | signup: { | |
150 | enabled: null, | |
151 | limit: this.customConfigValidatorsService.SIGNUP_LIMIT, | |
152 | requiresEmailVerification: null | |
153 | }, | |
154 | import: { | |
155 | videos: { | |
156 | http: { | |
157 | enabled: null | |
158 | }, | |
159 | torrent: { | |
160 | enabled: null | |
161 | } | |
162 | } | |
163 | }, | |
164 | admin: { | |
165 | email: this.customConfigValidatorsService.ADMIN_EMAIL | |
166 | }, | |
167 | contactForm: { | |
168 | enabled: null | |
169 | }, | |
170 | user: { | |
171 | videoQuota: this.userValidatorsService.USER_VIDEO_QUOTA, | |
172 | videoQuotaDaily: this.userValidatorsService.USER_VIDEO_QUOTA_DAILY | |
173 | }, | |
174 | transcoding: { | |
175 | enabled: null, | |
176 | threads: this.customConfigValidatorsService.TRANSCODING_THREADS, | |
177 | allowAdditionalExtensions: null, | |
536598cf | 178 | allowAudioFiles: null, |
5d9e4eaa C |
179 | resolutions: {}, |
180 | hls: { | |
181 | enabled: null | |
5a71acd2 C |
182 | }, |
183 | webtorrent: { | |
184 | enabled: null | |
5d9e4eaa | 185 | } |
7ccddd7b JM |
186 | }, |
187 | autoBlacklist: { | |
188 | videos: { | |
189 | ofUsers: { | |
190 | enabled: null | |
191 | } | |
192 | } | |
0dc64777 C |
193 | }, |
194 | followers: { | |
195 | instance: { | |
196 | enabled: null, | |
197 | manualApproval: null | |
198 | } | |
e1b49ee5 C |
199 | }, |
200 | followings: { | |
201 | instance: { | |
202 | autoFollowBack: { | |
203 | enabled: null | |
204 | }, | |
205 | autoFollowIndex: { | |
206 | enabled: null, | |
207 | indexUrl: this.customConfigValidatorsService.INDEX_URL | |
208 | } | |
209 | } | |
3866f1a0 | 210 | } |
fd206f0b C |
211 | } |
212 | ||
3866f1a0 C |
213 | const defaultValues = { |
214 | transcoding: { | |
215 | resolutions: {} | |
216 | } | |
217 | } | |
fd206f0b | 218 | for (const resolution of this.resolutions) { |
00aa1f0d C |
219 | defaultValues.transcoding.resolutions[resolution.id] = 'false' |
220 | formGroupData.transcoding.resolutions[resolution.id] = null | |
fd206f0b C |
221 | } |
222 | ||
d18d6478 | 223 | this.buildForm(formGroupData) |
fd206f0b | 224 | |
ccc00cb2 C |
225 | forkJoin([ |
226 | this.configService.getCustomConfig(), | |
ba430d75 C |
227 | this.serverService.getVideoLanguages(), |
228 | this.serverService.getVideoCategories() | |
ccc00cb2 | 229 | ]).subscribe( |
ba430d75 | 230 | ([ config, languages, categories ]) => { |
ccc00cb2 | 231 | this.customConfig = config |
fd206f0b | 232 | |
ccc00cb2 | 233 | this.languageItems = languages.map(l => ({ label: l.label, value: l.id })) |
ccc00cb2 C |
234 | this.categoryItems = categories.map(l => ({ label: l.label, value: l.id })) |
235 | ||
236 | this.updateForm() | |
237 | // Force form validation | |
238 | this.forceCheck() | |
239 | }, | |
240 | ||
241 | err => this.notifier.error(err.message) | |
242 | ) | |
fd206f0b C |
243 | } |
244 | ||
245 | isTranscodingEnabled () { | |
3866f1a0 | 246 | return this.form.value['transcoding']['enabled'] === true |
fd206f0b C |
247 | } |
248 | ||
249 | isSignupEnabled () { | |
3866f1a0 | 250 | return this.form.value['signup']['enabled'] === true |
fd206f0b C |
251 | } |
252 | ||
1f30a185 | 253 | async formValidated () { |
3866f1a0 | 254 | this.configService.updateCustomConfig(this.form.value) |
ba430d75 C |
255 | .pipe( |
256 | ) | |
fd206f0b C |
257 | .subscribe( |
258 | res => { | |
259 | this.customConfig = res | |
260 | ||
261 | // Reload general configuration | |
ba430d75 | 262 | this.serverService.resetConfig() |
fd206f0b C |
263 | |
264 | this.updateForm() | |
66b16caf | 265 | |
f8b2c1b4 | 266 | this.notifier.success(this.i18n('Configuration updated.')) |
fd206f0b C |
267 | }, |
268 | ||
f8b2c1b4 | 269 | err => this.notifier.error(err.message) |
fd206f0b C |
270 | ) |
271 | } | |
272 | ||
ccc00cb2 C |
273 | getSelectedLanguageLabel () { |
274 | return this.i18n('{{\'{0} languages selected') | |
275 | } | |
276 | ||
277 | getDefaultLanguageLabel () { | |
278 | return this.i18n('No language') | |
279 | } | |
280 | ||
281 | getSelectedCategoryLabel () { | |
282 | return this.i18n('{{\'{0} categories selected') | |
283 | } | |
284 | ||
285 | getDefaultCategoryLabel () { | |
286 | return this.i18n('No category') | |
287 | } | |
288 | ||
fd206f0b | 289 | private updateForm () { |
3866f1a0 | 290 | this.form.patchValue(this.customConfig) |
fd206f0b | 291 | } |
fd206f0b | 292 | } |