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