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