]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/extra-utils/server/config-command.ts
Rename jobs list command
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / server / config-command.ts
CommitLineData
65e6e260 1import { merge } from 'lodash'
c0e8b12e 2import { DeepPartial } from '@shared/core-utils'
4c7e60bc 3import { About, HttpStatusCode, ServerConfig } from '@shared/models'
65e6e260
C
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
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 },
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 transcoding: {
224 enabled: true,
225 allowAdditionalExtensions: true,
226 allowAudioFiles: true,
227 threads: 1,
228 concurrency: 3,
229 profile: 'default',
230 resolutions: {
231 '0p': false,
232 '240p': false,
233 '360p': true,
234 '480p': true,
235 '720p': false,
236 '1080p': false,
237 '1440p': false,
238 '2160p': false
239 },
240 webtorrent: {
241 enabled: true
242 },
243 hls: {
244 enabled: false
245 }
246 },
247 live: {
248 enabled: true,
249 allowReplay: false,
250 maxDuration: -1,
251 maxInstanceLives: -1,
252 maxUserLives: 50,
253 transcoding: {
254 enabled: true,
255 threads: 4,
256 profile: 'default',
257 resolutions: {
258 '240p': true,
259 '360p': true,
260 '480p': true,
261 '720p': true,
262 '1080p': true,
263 '1440p': true,
264 '2160p': true
265 }
266 }
267 },
268 import: {
269 videos: {
270 concurrency: 3,
271 http: {
272 enabled: false
273 },
274 torrent: {
275 enabled: false
276 }
277 }
278 },
279 trending: {
280 videos: {
281 algorithms: {
282 enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
283 default: 'hot'
284 }
285 }
286 },
287 autoBlacklist: {
288 videos: {
289 ofUsers: {
290 enabled: false
291 }
292 }
293 },
294 followers: {
295 instance: {
296 enabled: true,
297 manualApproval: false
298 }
299 },
300 followings: {
301 instance: {
302 autoFollowBack: {
303 enabled: false
304 },
305 autoFollowIndex: {
306 indexUrl: 'https://instances.joinpeertube.org/api/v1/instances/hosts',
307 enabled: false
308 }
309 }
310 },
311 broadcastMessage: {
312 enabled: true,
313 level: 'warning',
314 message: 'hello',
315 dismissable: true
316 },
317 search: {
318 remoteUri: {
319 users: true,
320 anonymous: true
321 },
322 searchIndex: {
323 enabled: true,
324 url: 'https://search.joinpeertube.org',
325 disableLocalSearch: true,
326 isDefaultSearch: true
327 }
328 }
329 }
330
331 merge(newCustomConfig, options.newConfig)
332
333 return this.updateCustomConfig({ ...options, newCustomConfig })
334 }
335}