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