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