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