diff options
Diffstat (limited to 'shared/extra-utils/server/config-command.ts')
-rw-r--r-- | shared/extra-utils/server/config-command.ts | 341 |
1 files changed, 0 insertions, 341 deletions
diff --git a/shared/extra-utils/server/config-command.ts b/shared/extra-utils/server/config-command.ts deleted file mode 100644 index 7a768b4df..000000000 --- a/shared/extra-utils/server/config-command.ts +++ /dev/null | |||
@@ -1,341 +0,0 @@ | |||
1 | import { merge } from 'lodash' | ||
2 | import { DeepPartial } from '@shared/core-utils' | ||
3 | import { About, HttpStatusCode, ServerConfig } from '@shared/models' | ||
4 | import { CustomConfig } from '../../models/server/custom-config.model' | ||
5 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
6 | |||
7 | export class ConfigCommand extends AbstractCommand { | ||
8 | |||
9 | static getCustomConfigResolutions (enabled: boolean) { | ||
10 | return { | ||
11 | '144p': enabled, | ||
12 | '240p': enabled, | ||
13 | '360p': enabled, | ||
14 | '480p': enabled, | ||
15 | '720p': enabled, | ||
16 | '1080p': enabled, | ||
17 | '1440p': enabled, | ||
18 | '2160p': enabled | ||
19 | } | ||
20 | } | ||
21 | |||
22 | enableImports () { | ||
23 | return this.updateExistingSubConfig({ | ||
24 | newConfig: { | ||
25 | import: { | ||
26 | videos: { | ||
27 | http: { | ||
28 | enabled: true | ||
29 | }, | ||
30 | |||
31 | torrent: { | ||
32 | enabled: true | ||
33 | } | ||
34 | } | ||
35 | } | ||
36 | } | ||
37 | }) | ||
38 | } | ||
39 | |||
40 | enableLive (options: { | ||
41 | allowReplay?: boolean | ||
42 | transcoding?: boolean | ||
43 | } = {}) { | ||
44 | return this.updateExistingSubConfig({ | ||
45 | newConfig: { | ||
46 | live: { | ||
47 | enabled: true, | ||
48 | allowReplay: options.allowReplay ?? true, | ||
49 | transcoding: { | ||
50 | enabled: options.transcoding ?? true, | ||
51 | resolutions: ConfigCommand.getCustomConfigResolutions(true) | ||
52 | } | ||
53 | } | ||
54 | } | ||
55 | }) | ||
56 | } | ||
57 | |||
58 | disableTranscoding () { | ||
59 | return this.updateExistingSubConfig({ | ||
60 | newConfig: { | ||
61 | transcoding: { | ||
62 | enabled: false | ||
63 | } | ||
64 | } | ||
65 | }) | ||
66 | } | ||
67 | |||
68 | enableTranscoding (webtorrent = true, hls = true) { | ||
69 | return this.updateExistingSubConfig({ | ||
70 | newConfig: { | ||
71 | transcoding: { | ||
72 | enabled: true, | ||
73 | resolutions: ConfigCommand.getCustomConfigResolutions(true), | ||
74 | |||
75 | webtorrent: { | ||
76 | enabled: webtorrent | ||
77 | }, | ||
78 | hls: { | ||
79 | enabled: hls | ||
80 | } | ||
81 | } | ||
82 | } | ||
83 | }) | ||
84 | } | ||
85 | |||
86 | getConfig (options: OverrideCommandOptions = {}) { | ||
87 | const path = '/api/v1/config' | ||
88 | |||
89 | return this.getRequestBody<ServerConfig>({ | ||
90 | ...options, | ||
91 | |||
92 | path, | ||
93 | implicitToken: false, | ||
94 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
95 | }) | ||
96 | } | ||
97 | |||
98 | getAbout (options: OverrideCommandOptions = {}) { | ||
99 | const path = '/api/v1/config/about' | ||
100 | |||
101 | return this.getRequestBody<About>({ | ||
102 | ...options, | ||
103 | |||
104 | path, | ||
105 | implicitToken: false, | ||
106 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
107 | }) | ||
108 | } | ||
109 | |||
110 | getCustomConfig (options: OverrideCommandOptions = {}) { | ||
111 | const path = '/api/v1/config/custom' | ||
112 | |||
113 | return this.getRequestBody<CustomConfig>({ | ||
114 | ...options, | ||
115 | |||
116 | path, | ||
117 | implicitToken: true, | ||
118 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
119 | }) | ||
120 | } | ||
121 | |||
122 | updateCustomConfig (options: OverrideCommandOptions & { | ||
123 | newCustomConfig: CustomConfig | ||
124 | }) { | ||
125 | const path = '/api/v1/config/custom' | ||
126 | |||
127 | return this.putBodyRequest({ | ||
128 | ...options, | ||
129 | |||
130 | path, | ||
131 | fields: options.newCustomConfig, | ||
132 | implicitToken: true, | ||
133 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
134 | }) | ||
135 | } | ||
136 | |||
137 | deleteCustomConfig (options: OverrideCommandOptions = {}) { | ||
138 | const path = '/api/v1/config/custom' | ||
139 | |||
140 | return this.deleteRequest({ | ||
141 | ...options, | ||
142 | |||
143 | path, | ||
144 | implicitToken: true, | ||
145 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
146 | }) | ||
147 | } | ||
148 | |||
149 | async updateExistingSubConfig (options: OverrideCommandOptions & { | ||
150 | newConfig: DeepPartial<CustomConfig> | ||
151 | }) { | ||
152 | const existing = await this.getCustomConfig(options) | ||
153 | |||
154 | return this.updateCustomConfig({ ...options, newCustomConfig: merge({}, existing, options.newConfig) }) | ||
155 | } | ||
156 | |||
157 | updateCustomSubConfig (options: OverrideCommandOptions & { | ||
158 | newConfig: DeepPartial<CustomConfig> | ||
159 | }) { | ||
160 | const newCustomConfig: CustomConfig = { | ||
161 | instance: { | ||
162 | name: 'PeerTube updated', | ||
163 | shortDescription: 'my short description', | ||
164 | description: 'my super description', | ||
165 | terms: 'my super terms', | ||
166 | codeOfConduct: 'my super coc', | ||
167 | |||
168 | creationReason: 'my super creation reason', | ||
169 | moderationInformation: 'my super moderation information', | ||
170 | administrator: 'Kuja', | ||
171 | maintenanceLifetime: 'forever', | ||
172 | businessModel: 'my super business model', | ||
173 | hardwareInformation: '2vCore 3GB RAM', | ||
174 | |||
175 | languages: [ 'en', 'es' ], | ||
176 | categories: [ 1, 2 ], | ||
177 | |||
178 | isNSFW: true, | ||
179 | defaultNSFWPolicy: 'blur', | ||
180 | |||
181 | defaultClientRoute: '/videos/recently-added', | ||
182 | |||
183 | customizations: { | ||
184 | javascript: 'alert("coucou")', | ||
185 | css: 'body { background-color: red; }' | ||
186 | } | ||
187 | }, | ||
188 | theme: { | ||
189 | default: 'default' | ||
190 | }, | ||
191 | services: { | ||
192 | twitter: { | ||
193 | username: '@MySuperUsername', | ||
194 | whitelisted: true | ||
195 | } | ||
196 | }, | ||
197 | cache: { | ||
198 | previews: { | ||
199 | size: 2 | ||
200 | }, | ||
201 | captions: { | ||
202 | size: 3 | ||
203 | }, | ||
204 | torrents: { | ||
205 | size: 4 | ||
206 | } | ||
207 | }, | ||
208 | signup: { | ||
209 | enabled: false, | ||
210 | limit: 5, | ||
211 | requiresEmailVerification: false, | ||
212 | minimumAge: 16 | ||
213 | }, | ||
214 | admin: { | ||
215 | email: 'superadmin1@example.com' | ||
216 | }, | ||
217 | contactForm: { | ||
218 | enabled: true | ||
219 | }, | ||
220 | user: { | ||
221 | videoQuota: 5242881, | ||
222 | videoQuotaDaily: 318742 | ||
223 | }, | ||
224 | videoChannels: { | ||
225 | maxPerUser: 20 | ||
226 | }, | ||
227 | transcoding: { | ||
228 | enabled: true, | ||
229 | allowAdditionalExtensions: true, | ||
230 | allowAudioFiles: true, | ||
231 | threads: 1, | ||
232 | concurrency: 3, | ||
233 | profile: 'default', | ||
234 | resolutions: { | ||
235 | '0p': false, | ||
236 | '144p': false, | ||
237 | '240p': false, | ||
238 | '360p': true, | ||
239 | '480p': true, | ||
240 | '720p': false, | ||
241 | '1080p': false, | ||
242 | '1440p': false, | ||
243 | '2160p': false | ||
244 | }, | ||
245 | webtorrent: { | ||
246 | enabled: true | ||
247 | }, | ||
248 | hls: { | ||
249 | enabled: false | ||
250 | } | ||
251 | }, | ||
252 | live: { | ||
253 | enabled: true, | ||
254 | allowReplay: false, | ||
255 | maxDuration: -1, | ||
256 | maxInstanceLives: -1, | ||
257 | maxUserLives: 50, | ||
258 | transcoding: { | ||
259 | enabled: true, | ||
260 | threads: 4, | ||
261 | profile: 'default', | ||
262 | resolutions: { | ||
263 | '144p': true, | ||
264 | '240p': true, | ||
265 | '360p': true, | ||
266 | '480p': true, | ||
267 | '720p': true, | ||
268 | '1080p': true, | ||
269 | '1440p': true, | ||
270 | '2160p': true | ||
271 | } | ||
272 | } | ||
273 | }, | ||
274 | import: { | ||
275 | videos: { | ||
276 | concurrency: 3, | ||
277 | http: { | ||
278 | enabled: false | ||
279 | }, | ||
280 | torrent: { | ||
281 | enabled: false | ||
282 | } | ||
283 | } | ||
284 | }, | ||
285 | trending: { | ||
286 | videos: { | ||
287 | algorithms: { | ||
288 | enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ], | ||
289 | default: 'hot' | ||
290 | } | ||
291 | } | ||
292 | }, | ||
293 | autoBlacklist: { | ||
294 | videos: { | ||
295 | ofUsers: { | ||
296 | enabled: false | ||
297 | } | ||
298 | } | ||
299 | }, | ||
300 | followers: { | ||
301 | instance: { | ||
302 | enabled: true, | ||
303 | manualApproval: false | ||
304 | } | ||
305 | }, | ||
306 | followings: { | ||
307 | instance: { | ||
308 | autoFollowBack: { | ||
309 | enabled: false | ||
310 | }, | ||
311 | autoFollowIndex: { | ||
312 | indexUrl: 'https://instances.joinpeertube.org/api/v1/instances/hosts', | ||
313 | enabled: false | ||
314 | } | ||
315 | } | ||
316 | }, | ||
317 | broadcastMessage: { | ||
318 | enabled: true, | ||
319 | level: 'warning', | ||
320 | message: 'hello', | ||
321 | dismissable: true | ||
322 | }, | ||
323 | search: { | ||
324 | remoteUri: { | ||
325 | users: true, | ||
326 | anonymous: true | ||
327 | }, | ||
328 | searchIndex: { | ||
329 | enabled: true, | ||
330 | url: 'https://search.joinpeertube.org', | ||
331 | disableLocalSearch: true, | ||
332 | isDefaultSearch: true | ||
333 | } | ||
334 | } | ||
335 | } | ||
336 | |||
337 | merge(newCustomConfig, options.newConfig) | ||
338 | |||
339 | return this.updateCustomConfig({ ...options, newCustomConfig }) | ||
340 | } | ||
341 | } | ||