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