]>
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 | |
ffb321be | 78 | .map(t => t.name) |
7cd4d2ba C |
79 | } |
80 | ||
fd206f0b | 81 | getResolutionKey (resolution: string) { |
3866f1a0 | 82 | return 'transcoding.resolutions.' + resolution |
fd206f0b C |
83 | } |
84 | ||
d18d6478 | 85 | ngOnInit () { |
3866f1a0 C |
86 | const formGroupData: { [key in keyof CustomConfig ]: any } = { |
87 | instance: { | |
88 | name: this.customConfigValidatorsService.INSTANCE_NAME, | |
89 | shortDescription: this.customConfigValidatorsService.INSTANCE_SHORT_DESCRIPTION, | |
90 | description: null, | |
91 | terms: null, | |
92 | defaultClientRoute: null, | |
f8802489 | 93 | isNSFW: false, |
3866f1a0 C |
94 | defaultNSFWPolicy: null, |
95 | customizations: { | |
96 | javascript: null, | |
97 | css: null | |
98 | } | |
99 | }, | |
7cd4d2ba C |
100 | theme: { |
101 | default: null | |
102 | }, | |
3866f1a0 C |
103 | services: { |
104 | twitter: { | |
105 | username: this.customConfigValidatorsService.SERVICES_TWITTER_USERNAME, | |
106 | whitelisted: null | |
107 | } | |
108 | }, | |
109 | cache: { | |
110 | previews: { | |
111 | size: this.customConfigValidatorsService.CACHE_PREVIEWS_SIZE | |
112 | }, | |
113 | captions: { | |
114 | size: this.customConfigValidatorsService.CACHE_CAPTIONS_SIZE | |
115 | } | |
116 | }, | |
117 | signup: { | |
118 | enabled: null, | |
119 | limit: this.customConfigValidatorsService.SIGNUP_LIMIT, | |
120 | requiresEmailVerification: null | |
121 | }, | |
122 | import: { | |
123 | videos: { | |
124 | http: { | |
125 | enabled: null | |
126 | }, | |
127 | torrent: { | |
128 | enabled: null | |
129 | } | |
130 | } | |
131 | }, | |
132 | admin: { | |
133 | email: this.customConfigValidatorsService.ADMIN_EMAIL | |
134 | }, | |
135 | contactForm: { | |
136 | enabled: null | |
137 | }, | |
138 | user: { | |
139 | videoQuota: this.userValidatorsService.USER_VIDEO_QUOTA, | |
140 | videoQuotaDaily: this.userValidatorsService.USER_VIDEO_QUOTA_DAILY | |
141 | }, | |
142 | transcoding: { | |
143 | enabled: null, | |
144 | threads: this.customConfigValidatorsService.TRANSCODING_THREADS, | |
145 | allowAdditionalExtensions: null, | |
536598cf | 146 | allowAudioFiles: null, |
3866f1a0 | 147 | resolutions: {} |
7ccddd7b JM |
148 | }, |
149 | autoBlacklist: { | |
150 | videos: { | |
151 | ofUsers: { | |
152 | enabled: null | |
153 | } | |
154 | } | |
0dc64777 C |
155 | }, |
156 | followers: { | |
157 | instance: { | |
158 | enabled: null, | |
159 | manualApproval: null | |
160 | } | |
3866f1a0 | 161 | } |
fd206f0b C |
162 | } |
163 | ||
3866f1a0 C |
164 | const defaultValues = { |
165 | transcoding: { | |
166 | resolutions: {} | |
167 | } | |
168 | } | |
fd206f0b | 169 | for (const resolution of this.resolutions) { |
00aa1f0d C |
170 | defaultValues.transcoding.resolutions[resolution.id] = 'false' |
171 | formGroupData.transcoding.resolutions[resolution.id] = null | |
fd206f0b C |
172 | } |
173 | ||
d18d6478 | 174 | this.buildForm(formGroupData) |
fd206f0b C |
175 | |
176 | this.configService.getCustomConfig() | |
177 | .subscribe( | |
178 | res => { | |
179 | this.customConfig = res | |
180 | ||
181 | this.updateForm() | |
d63fd4f7 C |
182 | // Force form validation |
183 | this.forceCheck() | |
fd206f0b C |
184 | }, |
185 | ||
f8b2c1b4 | 186 | err => this.notifier.error(err.message) |
fd206f0b C |
187 | ) |
188 | } | |
189 | ||
190 | isTranscodingEnabled () { | |
3866f1a0 | 191 | return this.form.value['transcoding']['enabled'] === true |
fd206f0b C |
192 | } |
193 | ||
194 | isSignupEnabled () { | |
3866f1a0 | 195 | return this.form.value['signup']['enabled'] === true |
fd206f0b C |
196 | } |
197 | ||
1f30a185 | 198 | async formValidated () { |
3866f1a0 | 199 | this.configService.updateCustomConfig(this.form.value) |
fd206f0b C |
200 | .subscribe( |
201 | res => { | |
202 | this.customConfig = res | |
203 | ||
204 | // Reload general configuration | |
205 | this.serverService.loadConfig() | |
206 | ||
207 | this.updateForm() | |
66b16caf | 208 | |
f8b2c1b4 | 209 | this.notifier.success(this.i18n('Configuration updated.')) |
fd206f0b C |
210 | }, |
211 | ||
f8b2c1b4 | 212 | err => this.notifier.error(err.message) |
fd206f0b C |
213 | ) |
214 | } | |
215 | ||
216 | private updateForm () { | |
3866f1a0 | 217 | this.form.patchValue(this.customConfig) |
fd206f0b C |
218 | } |
219 | ||
220 | } |