]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/server-commands/server/config-command.ts
Fix print transcode command test
[github/Chocobozzz/PeerTube.git] / shared / server-commands / server / config-command.ts
CommitLineData
65e6e260 1import { merge } from 'lodash'
c55e3d72 2import { About, CustomConfig, HttpStatusCode, ServerConfig } from '@shared/models'
6b5f72be 3import { DeepPartial } from '@shared/typescript-utils'
c55e3d72 4import { AbstractCommand, OverrideCommandOptions } from '../shared/abstract-command'
65e6e260
C
5
6export 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 },
84cae54e 313 alwaysTranscodeOriginalResolution: true,
65e6e260
C
314 webtorrent: {
315 enabled: true
316 },
317 hls: {
318 enabled: false
319 }
320 },
321 live: {
322 enabled: true,
323 allowReplay: false,
f443a746
C
324 latencySetting: {
325 enabled: false
326 },
65e6e260
C
327 maxDuration: -1,
328 maxInstanceLives: -1,
329 maxUserLives: 50,
330 transcoding: {
331 enabled: true,
332 threads: 4,
333 profile: 'default',
334 resolutions: {
8dd754c7 335 '144p': true,
65e6e260
C
336 '240p': true,
337 '360p': true,
338 '480p': true,
339 '720p': true,
340 '1080p': true,
341 '1440p': true,
342 '2160p': true
84cae54e
C
343 },
344 alwaysTranscodeOriginalResolution: true
65e6e260
C
345 }
346 },
92e66e04 347 videoStudio: {
c729caf6
C
348 enabled: false
349 },
65e6e260
C
350 import: {
351 videos: {
352 concurrency: 3,
353 http: {
354 enabled: false
355 },
356 torrent: {
357 enabled: false
358 }
359 }
360 },
361 trending: {
362 videos: {
363 algorithms: {
010382b6 364 enabled: [ 'hot', 'most-viewed', 'most-liked' ],
65e6e260
C
365 default: 'hot'
366 }
367 }
368 },
369 autoBlacklist: {
370 videos: {
371 ofUsers: {
372 enabled: false
373 }
374 }
375 },
376 followers: {
377 instance: {
378 enabled: true,
379 manualApproval: false
380 }
381 },
382 followings: {
383 instance: {
384 autoFollowBack: {
385 enabled: false
386 },
387 autoFollowIndex: {
388 indexUrl: 'https://instances.joinpeertube.org/api/v1/instances/hosts',
389 enabled: false
390 }
391 }
392 },
393 broadcastMessage: {
394 enabled: true,
395 level: 'warning',
396 message: 'hello',
397 dismissable: true
398 },
399 search: {
400 remoteUri: {
401 users: true,
402 anonymous: true
403 },
404 searchIndex: {
405 enabled: true,
406 url: 'https://search.joinpeertube.org',
407 disableLocalSearch: true,
408 isDefaultSearch: true
409 }
410 }
411 }
412
413 merge(newCustomConfig, options.newConfig)
414
415 return this.updateCustomConfig({ ...options, newCustomConfig })
416 }
417}