]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - shared/extra-utils/server/config-command.ts
Made the video channels limit (per user) server-wide configurable (#4491)
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / server / config-command.ts
... / ...
CommitLineData
1import { merge } from 'lodash'
2import { DeepPartial } from '@shared/core-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 '240p': enabled,
12 '360p': enabled,
13 '480p': enabled,
14 '720p': enabled,
15 '1080p': enabled,
16 '1440p': enabled,
17 '2160p': enabled
18 }
19 }
20
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
85 getConfig (options: OverrideCommandOptions = {}) {
86 const path = '/api/v1/config'
87
88 return this.getRequestBody<ServerConfig>({
89 ...options,
90
91 path,
92 implicitToken: false,
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
103 path,
104 implicitToken: false,
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,
116 implicitToken: true,
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,
131 implicitToken: true,
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,
143 implicitToken: true,
144 defaultExpectedStatus: HttpStatusCode.OK_200
145 })
146 }
147
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
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 },
196 cache: {
197 previews: {
198 size: 2
199 },
200 captions: {
201 size: 3
202 },
203 torrents: {
204 size: 4
205 }
206 },
207 signup: {
208 enabled: false,
209 limit: 5,
210 requiresEmailVerification: false,
211 minimumAge: 16
212 },
213 admin: {
214 email: 'superadmin1@example.com'
215 },
216 contactForm: {
217 enabled: true
218 },
219 user: {
220 videoQuota: 5242881,
221 videoQuotaDaily: 318742
222 },
223 videoChannels: {
224 maxPerUser: 20
225 },
226 transcoding: {
227 enabled: true,
228 allowAdditionalExtensions: true,
229 allowAudioFiles: true,
230 threads: 1,
231 concurrency: 3,
232 profile: 'default',
233 resolutions: {
234 '0p': false,
235 '240p': false,
236 '360p': true,
237 '480p': true,
238 '720p': false,
239 '1080p': false,
240 '1440p': false,
241 '2160p': false
242 },
243 webtorrent: {
244 enabled: true
245 },
246 hls: {
247 enabled: false
248 }
249 },
250 live: {
251 enabled: true,
252 allowReplay: false,
253 maxDuration: -1,
254 maxInstanceLives: -1,
255 maxUserLives: 50,
256 transcoding: {
257 enabled: true,
258 threads: 4,
259 profile: 'default',
260 resolutions: {
261 '240p': true,
262 '360p': true,
263 '480p': true,
264 '720p': true,
265 '1080p': true,
266 '1440p': true,
267 '2160p': true
268 }
269 }
270 },
271 import: {
272 videos: {
273 concurrency: 3,
274 http: {
275 enabled: false
276 },
277 torrent: {
278 enabled: false
279 }
280 }
281 },
282 trending: {
283 videos: {
284 algorithms: {
285 enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
286 default: 'hot'
287 }
288 }
289 },
290 autoBlacklist: {
291 videos: {
292 ofUsers: {
293 enabled: false
294 }
295 }
296 },
297 followers: {
298 instance: {
299 enabled: true,
300 manualApproval: false
301 }
302 },
303 followings: {
304 instance: {
305 autoFollowBack: {
306 enabled: false
307 },
308 autoFollowIndex: {
309 indexUrl: 'https://instances.joinpeertube.org/api/v1/instances/hosts',
310 enabled: false
311 }
312 }
313 },
314 broadcastMessage: {
315 enabled: true,
316 level: 'warning',
317 message: 'hello',
318 dismissable: true
319 },
320 search: {
321 remoteUri: {
322 users: true,
323 anonymous: true
324 },
325 searchIndex: {
326 enabled: true,
327 url: 'https://search.joinpeertube.org',
328 disableLocalSearch: true,
329 isDefaultSearch: true
330 }
331 }
332 }
333
334 merge(newCustomConfig, options.newConfig)
335
336 return this.updateCustomConfig({ ...options, newCustomConfig })
337 }
338}