]>
Commit | Line | Data |
---|---|---|
1 | import { Component, OnInit } from '@angular/core' | |
2 | import { ConfigService } from '@app/+admin/config/shared/config.service' | |
3 | import { ServerService } from '@app/core/server/server.service' | |
4 | import { CustomConfigValidatorsService, FormReactive, UserValidatorsService } from '@app/shared' | |
5 | import { Notifier } from '@app/core' | |
6 | import { CustomConfig } from '../../../../../../shared/models/server/custom-config.model' | |
7 | import { I18n } from '@ngx-translate/i18n-polyfill' | |
8 | import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' | |
9 | ||
10 | @Component({ | |
11 | selector: 'my-edit-custom-config', | |
12 | templateUrl: './edit-custom-config.component.html', | |
13 | styleUrls: [ './edit-custom-config.component.scss' ] | |
14 | }) | |
15 | export class EditCustomConfigComponent extends FormReactive implements OnInit { | |
16 | customConfig: CustomConfig | |
17 | ||
18 | resolutions: { id: string, label: string }[] = [] | |
19 | transcodingThreadOptions: { label: string, value: number }[] = [] | |
20 | ||
21 | constructor ( | |
22 | protected formValidatorService: FormValidatorService, | |
23 | private customConfigValidatorsService: CustomConfigValidatorsService, | |
24 | private userValidatorsService: UserValidatorsService, | |
25 | private notifier: Notifier, | |
26 | private configService: ConfigService, | |
27 | private serverService: ServerService, | |
28 | private i18n: I18n | |
29 | ) { | |
30 | super() | |
31 | ||
32 | this.resolutions = [ | |
33 | { | |
34 | id: '240p', | |
35 | label: this.i18n('240p') | |
36 | }, | |
37 | { | |
38 | id: '360p', | |
39 | label: this.i18n('360p') | |
40 | }, | |
41 | { | |
42 | id: '480p', | |
43 | label: this.i18n('480p') | |
44 | }, | |
45 | { | |
46 | id: '720p', | |
47 | label: this.i18n('720p') | |
48 | }, | |
49 | { | |
50 | id: '1080p', | |
51 | label: this.i18n('1080p') | |
52 | }, | |
53 | { | |
54 | id: '2160p', | |
55 | label: this.i18n('2160p') | |
56 | } | |
57 | ] | |
58 | ||
59 | this.transcodingThreadOptions = [ | |
60 | { value: 0, label: this.i18n('Auto (via ffmpeg)') }, | |
61 | { value: 1, label: '1' }, | |
62 | { value: 2, label: '2' }, | |
63 | { value: 4, label: '4' }, | |
64 | { value: 8, label: '8' } | |
65 | ] | |
66 | } | |
67 | ||
68 | get videoQuotaOptions () { | |
69 | return this.configService.videoQuotaOptions | |
70 | } | |
71 | ||
72 | get videoQuotaDailyOptions () { | |
73 | return this.configService.videoQuotaDailyOptions | |
74 | } | |
75 | ||
76 | get availableThemes () { | |
77 | return this.serverService.getConfig().theme.registered | |
78 | } | |
79 | ||
80 | getResolutionKey (resolution: string) { | |
81 | return 'transcoding.resolutions.' + resolution | |
82 | } | |
83 | ||
84 | ngOnInit () { | |
85 | const formGroupData: { [key in keyof CustomConfig ]: any } = { | |
86 | instance: { | |
87 | name: this.customConfigValidatorsService.INSTANCE_NAME, | |
88 | shortDescription: this.customConfigValidatorsService.INSTANCE_SHORT_DESCRIPTION, | |
89 | description: null, | |
90 | terms: null, | |
91 | defaultClientRoute: null, | |
92 | isNSFW: false, | |
93 | defaultNSFWPolicy: null, | |
94 | customizations: { | |
95 | javascript: null, | |
96 | css: null | |
97 | } | |
98 | }, | |
99 | theme: { | |
100 | default: null | |
101 | }, | |
102 | services: { | |
103 | twitter: { | |
104 | username: this.customConfigValidatorsService.SERVICES_TWITTER_USERNAME, | |
105 | whitelisted: null | |
106 | } | |
107 | }, | |
108 | cache: { | |
109 | previews: { | |
110 | size: this.customConfigValidatorsService.CACHE_PREVIEWS_SIZE | |
111 | }, | |
112 | captions: { | |
113 | size: this.customConfigValidatorsService.CACHE_CAPTIONS_SIZE | |
114 | } | |
115 | }, | |
116 | signup: { | |
117 | enabled: null, | |
118 | limit: this.customConfigValidatorsService.SIGNUP_LIMIT, | |
119 | requiresEmailVerification: null | |
120 | }, | |
121 | import: { | |
122 | videos: { | |
123 | http: { | |
124 | enabled: null | |
125 | }, | |
126 | torrent: { | |
127 | enabled: null | |
128 | } | |
129 | } | |
130 | }, | |
131 | admin: { | |
132 | email: this.customConfigValidatorsService.ADMIN_EMAIL | |
133 | }, | |
134 | contactForm: { | |
135 | enabled: null | |
136 | }, | |
137 | user: { | |
138 | videoQuota: this.userValidatorsService.USER_VIDEO_QUOTA, | |
139 | videoQuotaDaily: this.userValidatorsService.USER_VIDEO_QUOTA_DAILY | |
140 | }, | |
141 | transcoding: { | |
142 | enabled: null, | |
143 | threads: this.customConfigValidatorsService.TRANSCODING_THREADS, | |
144 | allowAdditionalExtensions: null, | |
145 | allowAudioFiles: null, | |
146 | resolutions: {} | |
147 | }, | |
148 | autoBlacklist: { | |
149 | videos: { | |
150 | ofUsers: { | |
151 | enabled: null | |
152 | } | |
153 | } | |
154 | }, | |
155 | followers: { | |
156 | instance: { | |
157 | enabled: null, | |
158 | manualApproval: null | |
159 | } | |
160 | } | |
161 | } | |
162 | ||
163 | const defaultValues = { | |
164 | transcoding: { | |
165 | resolutions: {} | |
166 | } | |
167 | } | |
168 | for (const resolution of this.resolutions) { | |
169 | defaultValues.transcoding.resolutions[resolution.id] = 'false' | |
170 | formGroupData.transcoding.resolutions[resolution.id] = null | |
171 | } | |
172 | ||
173 | this.buildForm(formGroupData) | |
174 | ||
175 | this.configService.getCustomConfig() | |
176 | .subscribe( | |
177 | res => { | |
178 | this.customConfig = res | |
179 | ||
180 | this.updateForm() | |
181 | // Force form validation | |
182 | this.forceCheck() | |
183 | }, | |
184 | ||
185 | err => this.notifier.error(err.message) | |
186 | ) | |
187 | } | |
188 | ||
189 | isTranscodingEnabled () { | |
190 | return this.form.value['transcoding']['enabled'] === true | |
191 | } | |
192 | ||
193 | isSignupEnabled () { | |
194 | return this.form.value['signup']['enabled'] === true | |
195 | } | |
196 | ||
197 | async formValidated () { | |
198 | this.configService.updateCustomConfig(this.form.value) | |
199 | .subscribe( | |
200 | res => { | |
201 | this.customConfig = res | |
202 | ||
203 | // Reload general configuration | |
204 | this.serverService.loadConfig() | |
205 | ||
206 | this.updateForm() | |
207 | ||
208 | this.notifier.success(this.i18n('Configuration updated.')) | |
209 | }, | |
210 | ||
211 | err => this.notifier.error(err.message) | |
212 | ) | |
213 | } | |
214 | ||
215 | private updateForm () { | |
216 | this.form.patchValue(this.customConfig) | |
217 | } | |
218 | ||
219 | } |