]>
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' |
fd206f0b C |
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 { | |
bee0abff | 16 | customConfig: CustomConfig |
bee0abff | 17 | |
00aa1f0d | 18 | resolutions: { id: string, label: string }[] = [] |
3827c3b3 | 19 | transcodingThreadOptions: { label: string, value: number }[] = [] |
fd206f0b | 20 | |
fd206f0b | 21 | constructor ( |
d18d6478 | 22 | protected formValidatorService: FormValidatorService, |
e309822b C |
23 | private customConfigValidatorsService: CustomConfigValidatorsService, |
24 | private userValidatorsService: UserValidatorsService, | |
f8b2c1b4 | 25 | private notifier: Notifier, |
fd206f0b | 26 | private configService: ConfigService, |
1f30a185 | 27 | private serverService: ServerService, |
b1d40cff | 28 | private i18n: I18n |
fd206f0b C |
29 | ) { |
30 | super() | |
3827c3b3 C |
31 | |
32 | this.resolutions = [ | |
00aa1f0d C |
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 | } | |
3827c3b3 C |
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 | ] | |
fd206f0b C |
66 | } |
67 | ||
41a676db | 68 | get videoQuotaOptions () { |
3827c3b3 | 69 | return this.configService.videoQuotaOptions |
41a676db C |
70 | } |
71 | ||
72 | get videoQuotaDailyOptions () { | |
3827c3b3 | 73 | return this.configService.videoQuotaDailyOptions |
41a676db C |
74 | } |
75 | ||
7cd4d2ba C |
76 | get availableThemes () { |
77 | return this.serverService.getConfig().theme.registered | |
78 | } | |
79 | ||
fd206f0b | 80 | getResolutionKey (resolution: string) { |
3866f1a0 | 81 | return 'transcoding.resolutions.' + resolution |
fd206f0b C |
82 | } |
83 | ||
d18d6478 | 84 | ngOnInit () { |
3866f1a0 C |
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, | |
f8802489 | 92 | isNSFW: false, |
3866f1a0 C |
93 | defaultNSFWPolicy: null, |
94 | customizations: { | |
95 | javascript: null, | |
96 | css: null | |
97 | } | |
98 | }, | |
7cd4d2ba C |
99 | theme: { |
100 | default: null | |
101 | }, | |
3866f1a0 C |
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, | |
536598cf | 145 | allowAudioFiles: null, |
3866f1a0 | 146 | resolutions: {} |
7ccddd7b JM |
147 | }, |
148 | autoBlacklist: { | |
149 | videos: { | |
150 | ofUsers: { | |
151 | enabled: null | |
152 | } | |
153 | } | |
0dc64777 C |
154 | }, |
155 | followers: { | |
156 | instance: { | |
157 | enabled: null, | |
158 | manualApproval: null | |
159 | } | |
3866f1a0 | 160 | } |
fd206f0b C |
161 | } |
162 | ||
3866f1a0 C |
163 | const defaultValues = { |
164 | transcoding: { | |
165 | resolutions: {} | |
166 | } | |
167 | } | |
fd206f0b | 168 | for (const resolution of this.resolutions) { |
00aa1f0d C |
169 | defaultValues.transcoding.resolutions[resolution.id] = 'false' |
170 | formGroupData.transcoding.resolutions[resolution.id] = null | |
fd206f0b C |
171 | } |
172 | ||
d18d6478 | 173 | this.buildForm(formGroupData) |
fd206f0b C |
174 | |
175 | this.configService.getCustomConfig() | |
176 | .subscribe( | |
177 | res => { | |
178 | this.customConfig = res | |
179 | ||
180 | this.updateForm() | |
d63fd4f7 C |
181 | // Force form validation |
182 | this.forceCheck() | |
fd206f0b C |
183 | }, |
184 | ||
f8b2c1b4 | 185 | err => this.notifier.error(err.message) |
fd206f0b C |
186 | ) |
187 | } | |
188 | ||
189 | isTranscodingEnabled () { | |
3866f1a0 | 190 | return this.form.value['transcoding']['enabled'] === true |
fd206f0b C |
191 | } |
192 | ||
193 | isSignupEnabled () { | |
3866f1a0 | 194 | return this.form.value['signup']['enabled'] === true |
fd206f0b C |
195 | } |
196 | ||
1f30a185 | 197 | async formValidated () { |
3866f1a0 | 198 | this.configService.updateCustomConfig(this.form.value) |
fd206f0b C |
199 | .subscribe( |
200 | res => { | |
201 | this.customConfig = res | |
202 | ||
203 | // Reload general configuration | |
204 | this.serverService.loadConfig() | |
205 | ||
206 | this.updateForm() | |
66b16caf | 207 | |
f8b2c1b4 | 208 | this.notifier.success(this.i18n('Configuration updated.')) |
fd206f0b C |
209 | }, |
210 | ||
f8b2c1b4 | 211 | err => this.notifier.error(err.message) |
fd206f0b C |
212 | ) |
213 | } | |
214 | ||
215 | private updateForm () { | |
3866f1a0 | 216 | this.form.patchValue(this.customConfig) |
fd206f0b C |
217 | } |
218 | ||
219 | } |