aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/server-commands/server/config-command.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-12-17 09:29:23 +0100
committerChocobozzz <me@florianbigard.com>2021-12-17 09:29:23 +0100
commitbf54587a3e2ad9c2c186828f2a5682b91ee2cc00 (patch)
tree54b40aaf01bae210632473285c3c7571d51e4f89 /shared/server-commands/server/config-command.ts
parent6b5f72beda96d8b7e4d6329c4001827334de27dd (diff)
downloadPeerTube-bf54587a3e2ad9c2c186828f2a5682b91ee2cc00.tar.gz
PeerTube-bf54587a3e2ad9c2c186828f2a5682b91ee2cc00.tar.zst
PeerTube-bf54587a3e2ad9c2c186828f2a5682b91ee2cc00.zip
shared/ typescript types dir server-commands
Diffstat (limited to 'shared/server-commands/server/config-command.ts')
-rw-r--r--shared/server-commands/server/config-command.ts353
1 files changed, 353 insertions, 0 deletions
diff --git a/shared/server-commands/server/config-command.ts b/shared/server-commands/server/config-command.ts
new file mode 100644
index 000000000..89ae8eb4f
--- /dev/null
+++ b/shared/server-commands/server/config-command.ts
@@ -0,0 +1,353 @@
1import { merge } from 'lodash'
2import { DeepPartial } from '@shared/typescript-utils'
3import { About, HttpStatusCode, ServerConfig } from '@shared/models'
4import { CustomConfig } from '../../models/server/custom-config.model'
5import { AbstractCommand, OverrideCommandOptions } from '../shared'
6
7export 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 client: {
198 videos: {
199 miniature: {
200 preferAuthorDisplayName: false
201 }
202 },
203 menu: {
204 login: {
205 redirectOnSingleExternalAuth: false
206 }
207 }
208 },
209 cache: {
210 previews: {
211 size: 2
212 },
213 captions: {
214 size: 3
215 },
216 torrents: {
217 size: 4
218 }
219 },
220 signup: {
221 enabled: false,
222 limit: 5,
223 requiresEmailVerification: false,
224 minimumAge: 16
225 },
226 admin: {
227 email: 'superadmin1@example.com'
228 },
229 contactForm: {
230 enabled: true
231 },
232 user: {
233 videoQuota: 5242881,
234 videoQuotaDaily: 318742
235 },
236 videoChannels: {
237 maxPerUser: 20
238 },
239 transcoding: {
240 enabled: true,
241 allowAdditionalExtensions: true,
242 allowAudioFiles: true,
243 threads: 1,
244 concurrency: 3,
245 profile: 'default',
246 resolutions: {
247 '0p': false,
248 '144p': false,
249 '240p': false,
250 '360p': true,
251 '480p': true,
252 '720p': false,
253 '1080p': false,
254 '1440p': false,
255 '2160p': false
256 },
257 webtorrent: {
258 enabled: true
259 },
260 hls: {
261 enabled: false
262 }
263 },
264 live: {
265 enabled: true,
266 allowReplay: false,
267 maxDuration: -1,
268 maxInstanceLives: -1,
269 maxUserLives: 50,
270 transcoding: {
271 enabled: true,
272 threads: 4,
273 profile: 'default',
274 resolutions: {
275 '144p': true,
276 '240p': true,
277 '360p': true,
278 '480p': true,
279 '720p': true,
280 '1080p': true,
281 '1440p': true,
282 '2160p': true
283 }
284 }
285 },
286 import: {
287 videos: {
288 concurrency: 3,
289 http: {
290 enabled: false
291 },
292 torrent: {
293 enabled: false
294 }
295 }
296 },
297 trending: {
298 videos: {
299 algorithms: {
300 enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
301 default: 'hot'
302 }
303 }
304 },
305 autoBlacklist: {
306 videos: {
307 ofUsers: {
308 enabled: false
309 }
310 }
311 },
312 followers: {
313 instance: {
314 enabled: true,
315 manualApproval: false
316 }
317 },
318 followings: {
319 instance: {
320 autoFollowBack: {
321 enabled: false
322 },
323 autoFollowIndex: {
324 indexUrl: 'https://instances.joinpeertube.org/api/v1/instances/hosts',
325 enabled: false
326 }
327 }
328 },
329 broadcastMessage: {
330 enabled: true,
331 level: 'warning',
332 message: 'hello',
333 dismissable: true
334 },
335 search: {
336 remoteUri: {
337 users: true,
338 anonymous: true
339 },
340 searchIndex: {
341 enabled: true,
342 url: 'https://search.joinpeertube.org',
343 disableLocalSearch: true,
344 isDefaultSearch: true
345 }
346 }
347 }
348
349 merge(newCustomConfig, options.newConfig)
350
351 return this.updateCustomConfig({ ...options, newCustomConfig })
352 }
353}