]>
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 | |
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 | ||
126 | getAbout (options: OverrideCommandOptions = {}) { | |
127 | const path = '/api/v1/config/about' | |
128 | ||
129 | return this.getRequestBody<About>({ | |
130 | ...options, | |
131 | ||
65e6e260 | 132 | path, |
a1637fa1 | 133 | implicitToken: false, |
65e6e260 C |
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, | |
a1637fa1 | 145 | implicitToken: true, |
65e6e260 C |
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, | |
a1637fa1 | 160 | implicitToken: true, |
65e6e260 C |
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, | |
a1637fa1 | 172 | implicitToken: true, |
65e6e260 C |
173 | defaultExpectedStatus: HttpStatusCode.OK_200 |
174 | }) | |
175 | } | |
176 | ||
0305db28 JB |
177 | async updateExistingSubConfig (options: OverrideCommandOptions & { |
178 | newConfig: DeepPartial<CustomConfig> | |
179 | }) { | |
c729caf6 | 180 | const existing = await this.getCustomConfig({ ...options, expectedStatus: HttpStatusCode.OK_200 }) |
0305db28 JB |
181 | |
182 | return this.updateCustomConfig({ ...options, newCustomConfig: merge({}, existing, options.newConfig) }) | |
183 | } | |
184 | ||
65e6e260 C |
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 | }, | |
0bc53e20 C |
225 | client: { |
226 | videos: { | |
227 | miniature: { | |
228 | preferAuthorDisplayName: false | |
229 | } | |
230 | }, | |
231 | menu: { | |
232 | login: { | |
233 | redirectOnSingleExternalAuth: false | |
234 | } | |
235 | } | |
236 | }, | |
65e6e260 C |
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 | }, | |
754b6f5f FC |
264 | videoChannels: { |
265 | maxPerUser: 20 | |
266 | }, | |
65e6e260 C |
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, | |
8dd754c7 | 276 | '144p': false, |
65e6e260 C |
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 | maxDuration: -1, | |
296 | maxInstanceLives: -1, | |
297 | maxUserLives: 50, | |
298 | transcoding: { | |
299 | enabled: true, | |
300 | threads: 4, | |
301 | profile: 'default', | |
302 | resolutions: { | |
8dd754c7 | 303 | '144p': true, |
65e6e260 C |
304 | '240p': true, |
305 | '360p': true, | |
306 | '480p': true, | |
307 | '720p': true, | |
308 | '1080p': true, | |
309 | '1440p': true, | |
310 | '2160p': true | |
311 | } | |
312 | } | |
313 | }, | |
c729caf6 C |
314 | videoEditor: { |
315 | enabled: false | |
316 | }, | |
65e6e260 C |
317 | import: { |
318 | videos: { | |
319 | concurrency: 3, | |
320 | http: { | |
321 | enabled: false | |
322 | }, | |
323 | torrent: { | |
324 | enabled: false | |
325 | } | |
326 | } | |
327 | }, | |
328 | trending: { | |
329 | videos: { | |
330 | algorithms: { | |
331 | enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ], | |
332 | default: 'hot' | |
333 | } | |
334 | } | |
335 | }, | |
336 | autoBlacklist: { | |
337 | videos: { | |
338 | ofUsers: { | |
339 | enabled: false | |
340 | } | |
341 | } | |
342 | }, | |
343 | followers: { | |
344 | instance: { | |
345 | enabled: true, | |
346 | manualApproval: false | |
347 | } | |
348 | }, | |
349 | followings: { | |
350 | instance: { | |
351 | autoFollowBack: { | |
352 | enabled: false | |
353 | }, | |
354 | autoFollowIndex: { | |
355 | indexUrl: 'https://instances.joinpeertube.org/api/v1/instances/hosts', | |
356 | enabled: false | |
357 | } | |
358 | } | |
359 | }, | |
360 | broadcastMessage: { | |
361 | enabled: true, | |
362 | level: 'warning', | |
363 | message: 'hello', | |
364 | dismissable: true | |
365 | }, | |
366 | search: { | |
367 | remoteUri: { | |
368 | users: true, | |
369 | anonymous: true | |
370 | }, | |
371 | searchIndex: { | |
372 | enabled: true, | |
373 | url: 'https://search.joinpeertube.org', | |
374 | disableLocalSearch: true, | |
375 | isDefaultSearch: true | |
376 | } | |
377 | } | |
378 | } | |
379 | ||
380 | merge(newCustomConfig, options.newConfig) | |
381 | ||
382 | return this.updateCustomConfig({ ...options, newCustomConfig }) | |
383 | } | |
384 | } |