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