]>
Commit | Line | Data |
---|---|---|
65e6e260 | 1 | import { merge } from 'lodash' |
c55e3d72 | 2 | import { About, CustomConfig, HttpStatusCode, ServerConfig } from '@shared/models' |
6b5f72be | 3 | import { DeepPartial } from '@shared/typescript-utils' |
c55e3d72 | 4 | import { AbstractCommand, OverrideCommandOptions } from '../shared/abstract-command' |
65e6e260 C |
5 | |
6 | export class ConfigCommand extends AbstractCommand { | |
7 | ||
8 | static getCustomConfigResolutions (enabled: boolean) { | |
9 | return { | |
8dd754c7 | 10 | '144p': enabled, |
65e6e260 C |
11 | '240p': enabled, |
12 | '360p': enabled, | |
13 | '480p': enabled, | |
14 | '720p': enabled, | |
15 | '1080p': enabled, | |
16 | '1440p': enabled, | |
17 | '2160p': enabled | |
18 | } | |
19 | } | |
20 | ||
b379759f C |
21 | // --------------------------------------------------------------------------- |
22 | ||
23 | static getEmailOverrideConfig (emailPort: number) { | |
24 | return { | |
25 | smtp: { | |
26 | hostname: '127.0.0.1', | |
27 | port: emailPort | |
28 | } | |
29 | } | |
30 | } | |
31 | ||
32 | // --------------------------------------------------------------------------- | |
33 | ||
9436936c | 34 | enableSignup (requiresApproval: boolean, limit = -1) { |
b379759f C |
35 | return this.updateExistingSubConfig({ |
36 | newConfig: { | |
37 | signup: { | |
38 | enabled: true, | |
39 | requiresApproval, | |
9436936c | 40 | limit |
b379759f C |
41 | } |
42 | } | |
43 | }) | |
44 | } | |
45 | ||
46 | // --------------------------------------------------------------------------- | |
47 | ||
2a491182 F |
48 | disableImports () { |
49 | return this.setImportsEnabled(false) | |
50 | } | |
51 | ||
0305db28 | 52 | enableImports () { |
2a491182 F |
53 | return this.setImportsEnabled(true) |
54 | } | |
55 | ||
56 | private setImportsEnabled (enabled: boolean) { | |
0305db28 JB |
57 | return this.updateExistingSubConfig({ |
58 | newConfig: { | |
59 | import: { | |
60 | videos: { | |
61 | http: { | |
2a491182 | 62 | enabled |
0305db28 JB |
63 | }, |
64 | ||
65 | torrent: { | |
2a491182 | 66 | enabled |
0305db28 JB |
67 | } |
68 | } | |
69 | } | |
70 | } | |
71 | }) | |
72 | } | |
73 | ||
b379759f C |
74 | // --------------------------------------------------------------------------- |
75 | ||
76 | enableChannelSync () { | |
77 | return this.setChannelSyncEnabled(true) | |
78 | } | |
79 | ||
80 | disableChannelSync () { | |
81 | return this.setChannelSyncEnabled(false) | |
82 | } | |
83 | ||
2a491182 F |
84 | private setChannelSyncEnabled (enabled: boolean) { |
85 | return this.updateExistingSubConfig({ | |
86 | newConfig: { | |
87 | import: { | |
88 | videoChannelSynchronization: { | |
89 | enabled | |
90 | } | |
91 | } | |
92 | } | |
93 | }) | |
94 | } | |
95 | ||
b379759f | 96 | // --------------------------------------------------------------------------- |
2a491182 | 97 | |
0305db28 JB |
98 | enableLive (options: { |
99 | allowReplay?: boolean | |
100 | transcoding?: boolean | |
53023be3 | 101 | resolutions?: 'min' | 'max' // Default max |
0305db28 | 102 | } = {}) { |
53023be3 C |
103 | const { allowReplay, transcoding, resolutions = 'max' } = options |
104 | ||
0305db28 JB |
105 | return this.updateExistingSubConfig({ |
106 | newConfig: { | |
107 | live: { | |
108 | enabled: true, | |
53023be3 | 109 | allowReplay: allowReplay ?? true, |
0305db28 | 110 | transcoding: { |
53023be3 C |
111 | enabled: transcoding ?? true, |
112 | resolutions: ConfigCommand.getCustomConfigResolutions(resolutions === 'max') | |
0305db28 JB |
113 | } |
114 | } | |
115 | } | |
116 | }) | |
117 | } | |
118 | ||
119 | disableTranscoding () { | |
120 | return this.updateExistingSubConfig({ | |
121 | newConfig: { | |
122 | transcoding: { | |
123 | enabled: false | |
c729caf6 | 124 | }, |
92e66e04 | 125 | videoStudio: { |
c729caf6 | 126 | enabled: false |
0305db28 JB |
127 | } |
128 | } | |
129 | }) | |
130 | } | |
131 | ||
132 | enableTranscoding (webtorrent = true, hls = true) { | |
133 | return this.updateExistingSubConfig({ | |
134 | newConfig: { | |
135 | transcoding: { | |
136 | enabled: true, | |
c729caf6 C |
137 | |
138 | allowAudioFiles: true, | |
139 | allowAdditionalExtensions: true, | |
140 | ||
0305db28 JB |
141 | resolutions: ConfigCommand.getCustomConfigResolutions(true), |
142 | ||
143 | webtorrent: { | |
144 | enabled: webtorrent | |
145 | }, | |
146 | hls: { | |
147 | enabled: hls | |
148 | } | |
149 | } | |
150 | } | |
151 | }) | |
152 | } | |
153 | ||
c729caf6 C |
154 | enableMinimumTranscoding (webtorrent = true, hls = true) { |
155 | return this.updateExistingSubConfig({ | |
156 | newConfig: { | |
157 | transcoding: { | |
158 | enabled: true, | |
159 | resolutions: { | |
160 | ...ConfigCommand.getCustomConfigResolutions(false), | |
161 | ||
162 | '240p': true | |
163 | }, | |
164 | ||
165 | webtorrent: { | |
166 | enabled: webtorrent | |
167 | }, | |
168 | hls: { | |
169 | enabled: hls | |
170 | } | |
171 | } | |
172 | } | |
173 | }) | |
174 | } | |
175 | ||
b379759f C |
176 | // --------------------------------------------------------------------------- |
177 | ||
92e66e04 | 178 | enableStudio () { |
1808a1f8 C |
179 | return this.updateExistingSubConfig({ |
180 | newConfig: { | |
92e66e04 | 181 | videoStudio: { |
1808a1f8 C |
182 | enabled: true |
183 | } | |
184 | } | |
185 | }) | |
186 | } | |
187 | ||
b379759f C |
188 | // --------------------------------------------------------------------------- |
189 | ||
65e6e260 C |
190 | getConfig (options: OverrideCommandOptions = {}) { |
191 | const path = '/api/v1/config' | |
192 | ||
193 | return this.getRequestBody<ServerConfig>({ | |
194 | ...options, | |
195 | ||
65e6e260 | 196 | path, |
a1637fa1 | 197 | implicitToken: false, |
65e6e260 C |
198 | defaultExpectedStatus: HttpStatusCode.OK_200 |
199 | }) | |
200 | } | |
201 | ||
2769876f C |
202 | async getIndexHTMLConfig (options: OverrideCommandOptions = {}) { |
203 | const text = await this.getRequestText({ | |
204 | ...options, | |
205 | ||
206 | path: '/', | |
207 | implicitToken: false, | |
208 | defaultExpectedStatus: HttpStatusCode.OK_200 | |
209 | }) | |
210 | ||
211 | const match = text.match('<script type="application/javascript">window.PeerTubeServerConfig = (".+?")</script>') | |
212 | ||
213 | // We parse the string twice, first to extract the string and then to extract the JSON | |
214 | return JSON.parse(JSON.parse(match[1])) as ServerConfig | |
215 | } | |
216 | ||
65e6e260 C |
217 | getAbout (options: OverrideCommandOptions = {}) { |
218 | const path = '/api/v1/config/about' | |
219 | ||
220 | return this.getRequestBody<About>({ | |
221 | ...options, | |
222 | ||
65e6e260 | 223 | path, |
a1637fa1 | 224 | implicitToken: false, |
65e6e260 C |
225 | defaultExpectedStatus: HttpStatusCode.OK_200 |
226 | }) | |
227 | } | |
228 | ||
229 | getCustomConfig (options: OverrideCommandOptions = {}) { | |
230 | const path = '/api/v1/config/custom' | |
231 | ||
232 | return this.getRequestBody<CustomConfig>({ | |
233 | ...options, | |
234 | ||
235 | path, | |
a1637fa1 | 236 | implicitToken: true, |
65e6e260 C |
237 | defaultExpectedStatus: HttpStatusCode.OK_200 |
238 | }) | |
239 | } | |
240 | ||
241 | updateCustomConfig (options: OverrideCommandOptions & { | |
242 | newCustomConfig: CustomConfig | |
243 | }) { | |
244 | const path = '/api/v1/config/custom' | |
245 | ||
246 | return this.putBodyRequest({ | |
247 | ...options, | |
248 | ||
249 | path, | |
250 | fields: options.newCustomConfig, | |
a1637fa1 | 251 | implicitToken: true, |
65e6e260 C |
252 | defaultExpectedStatus: HttpStatusCode.OK_200 |
253 | }) | |
254 | } | |
255 | ||
256 | deleteCustomConfig (options: OverrideCommandOptions = {}) { | |
257 | const path = '/api/v1/config/custom' | |
258 | ||
259 | return this.deleteRequest({ | |
260 | ...options, | |
261 | ||
262 | path, | |
a1637fa1 | 263 | implicitToken: true, |
65e6e260 C |
264 | defaultExpectedStatus: HttpStatusCode.OK_200 |
265 | }) | |
266 | } | |
267 | ||
0305db28 JB |
268 | async updateExistingSubConfig (options: OverrideCommandOptions & { |
269 | newConfig: DeepPartial<CustomConfig> | |
270 | }) { | |
c729caf6 | 271 | const existing = await this.getCustomConfig({ ...options, expectedStatus: HttpStatusCode.OK_200 }) |
0305db28 JB |
272 | |
273 | return this.updateCustomConfig({ ...options, newCustomConfig: merge({}, existing, options.newConfig) }) | |
274 | } | |
275 | ||
65e6e260 C |
276 | updateCustomSubConfig (options: OverrideCommandOptions & { |
277 | newConfig: DeepPartial<CustomConfig> | |
278 | }) { | |
279 | const newCustomConfig: CustomConfig = { | |
280 | instance: { | |
281 | name: 'PeerTube updated', | |
282 | shortDescription: 'my short description', | |
283 | description: 'my super description', | |
284 | terms: 'my super terms', | |
285 | codeOfConduct: 'my super coc', | |
286 | ||
287 | creationReason: 'my super creation reason', | |
288 | moderationInformation: 'my super moderation information', | |
289 | administrator: 'Kuja', | |
290 | maintenanceLifetime: 'forever', | |
291 | businessModel: 'my super business model', | |
292 | hardwareInformation: '2vCore 3GB RAM', | |
293 | ||
294 | languages: [ 'en', 'es' ], | |
295 | categories: [ 1, 2 ], | |
296 | ||
297 | isNSFW: true, | |
298 | defaultNSFWPolicy: 'blur', | |
299 | ||
300 | defaultClientRoute: '/videos/recently-added', | |
301 | ||
302 | customizations: { | |
303 | javascript: 'alert("coucou")', | |
304 | css: 'body { background-color: red; }' | |
305 | } | |
306 | }, | |
307 | theme: { | |
308 | default: 'default' | |
309 | }, | |
310 | services: { | |
311 | twitter: { | |
312 | username: '@MySuperUsername', | |
313 | whitelisted: true | |
314 | } | |
315 | }, | |
0bc53e20 C |
316 | client: { |
317 | videos: { | |
318 | miniature: { | |
319 | preferAuthorDisplayName: false | |
320 | } | |
321 | }, | |
322 | menu: { | |
323 | login: { | |
324 | redirectOnSingleExternalAuth: false | |
325 | } | |
326 | } | |
327 | }, | |
65e6e260 C |
328 | cache: { |
329 | previews: { | |
330 | size: 2 | |
331 | }, | |
332 | captions: { | |
333 | size: 3 | |
334 | }, | |
335 | torrents: { | |
336 | size: 4 | |
337 | } | |
338 | }, | |
339 | signup: { | |
340 | enabled: false, | |
341 | limit: 5, | |
b379759f | 342 | requiresApproval: true, |
65e6e260 C |
343 | requiresEmailVerification: false, |
344 | minimumAge: 16 | |
345 | }, | |
346 | admin: { | |
347 | email: 'superadmin1@example.com' | |
348 | }, | |
349 | contactForm: { | |
350 | enabled: true | |
351 | }, | |
352 | user: { | |
353 | videoQuota: 5242881, | |
354 | videoQuotaDaily: 318742 | |
355 | }, | |
754b6f5f FC |
356 | videoChannels: { |
357 | maxPerUser: 20 | |
358 | }, | |
65e6e260 C |
359 | transcoding: { |
360 | enabled: true, | |
361 | allowAdditionalExtensions: true, | |
362 | allowAudioFiles: true, | |
363 | threads: 1, | |
364 | concurrency: 3, | |
365 | profile: 'default', | |
366 | resolutions: { | |
367 | '0p': false, | |
8dd754c7 | 368 | '144p': false, |
65e6e260 C |
369 | '240p': false, |
370 | '360p': true, | |
371 | '480p': true, | |
372 | '720p': false, | |
373 | '1080p': false, | |
374 | '1440p': false, | |
375 | '2160p': false | |
376 | }, | |
84cae54e | 377 | alwaysTranscodeOriginalResolution: true, |
65e6e260 C |
378 | webtorrent: { |
379 | enabled: true | |
380 | }, | |
381 | hls: { | |
382 | enabled: false | |
383 | } | |
384 | }, | |
385 | live: { | |
386 | enabled: true, | |
387 | allowReplay: false, | |
f443a746 C |
388 | latencySetting: { |
389 | enabled: false | |
390 | }, | |
65e6e260 C |
391 | maxDuration: -1, |
392 | maxInstanceLives: -1, | |
393 | maxUserLives: 50, | |
394 | transcoding: { | |
395 | enabled: true, | |
396 | threads: 4, | |
397 | profile: 'default', | |
398 | resolutions: { | |
8dd754c7 | 399 | '144p': true, |
65e6e260 C |
400 | '240p': true, |
401 | '360p': true, | |
402 | '480p': true, | |
403 | '720p': true, | |
404 | '1080p': true, | |
405 | '1440p': true, | |
406 | '2160p': true | |
84cae54e C |
407 | }, |
408 | alwaysTranscodeOriginalResolution: true | |
65e6e260 C |
409 | } |
410 | }, | |
92e66e04 | 411 | videoStudio: { |
c729caf6 C |
412 | enabled: false |
413 | }, | |
65e6e260 C |
414 | import: { |
415 | videos: { | |
416 | concurrency: 3, | |
417 | http: { | |
418 | enabled: false | |
419 | }, | |
420 | torrent: { | |
421 | enabled: false | |
422 | } | |
2a491182 F |
423 | }, |
424 | videoChannelSynchronization: { | |
425 | enabled: false, | |
426 | maxPerUser: 10 | |
65e6e260 C |
427 | } |
428 | }, | |
429 | trending: { | |
430 | videos: { | |
431 | algorithms: { | |
010382b6 | 432 | enabled: [ 'hot', 'most-viewed', 'most-liked' ], |
65e6e260 C |
433 | default: 'hot' |
434 | } | |
435 | } | |
436 | }, | |
437 | autoBlacklist: { | |
438 | videos: { | |
439 | ofUsers: { | |
440 | enabled: false | |
441 | } | |
442 | } | |
443 | }, | |
444 | followers: { | |
445 | instance: { | |
446 | enabled: true, | |
447 | manualApproval: false | |
448 | } | |
449 | }, | |
450 | followings: { | |
451 | instance: { | |
452 | autoFollowBack: { | |
453 | enabled: false | |
454 | }, | |
455 | autoFollowIndex: { | |
456 | indexUrl: 'https://instances.joinpeertube.org/api/v1/instances/hosts', | |
457 | enabled: false | |
458 | } | |
459 | } | |
460 | }, | |
461 | broadcastMessage: { | |
462 | enabled: true, | |
463 | level: 'warning', | |
464 | message: 'hello', | |
465 | dismissable: true | |
466 | }, | |
467 | search: { | |
468 | remoteUri: { | |
469 | users: true, | |
470 | anonymous: true | |
471 | }, | |
472 | searchIndex: { | |
473 | enabled: true, | |
474 | url: 'https://search.joinpeertube.org', | |
475 | disableLocalSearch: true, | |
476 | isDefaultSearch: true | |
477 | } | |
478 | } | |
479 | } | |
480 | ||
481 | merge(newCustomConfig, options.newConfig) | |
482 | ||
483 | return this.updateCustomConfig({ ...options, newCustomConfig }) | |
484 | } | |
485 | } |