]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/extra-utils/server/config.ts
Refactor server errors handler
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / server / config.ts
CommitLineData
d175a6f7 1import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../requests/requests'
d4681c00 2import { CustomConfig } from '../../models/server/custom-config.model'
2d53be02 3import { DeepPartial, HttpStatusCode } from '@shared/core-utils'
8424c402 4import { merge } from 'lodash'
0e1dc3e7
C
5
6function getConfig (url: string) {
7 const path = '/api/v1/config'
8
36f9424f
C
9 return makeGetRequest({
10 url,
11 path,
2d53be02 12 statusCodeExpected: HttpStatusCode.OK_200
36f9424f
C
13 })
14}
15
16function getAbout (url: string) {
17 const path = '/api/v1/config/about'
18
19 return makeGetRequest({
20 url,
21 path,
2d53be02 22 statusCodeExpected: HttpStatusCode.OK_200
36f9424f 23 })
0e1dc3e7
C
24}
25
2d53be02 26function getCustomConfig (url: string, token: string, statusCodeExpected = HttpStatusCode.OK_200) {
fd206f0b
C
27 const path = '/api/v1/config/custom'
28
29 return makeGetRequest({
30 url,
31 token,
32 path,
33 statusCodeExpected
34 })
35}
36
2d53be02 37function updateCustomConfig (url: string, token: string, newCustomConfig: CustomConfig, statusCodeExpected = HttpStatusCode.OK_200) {
fd206f0b
C
38 const path = '/api/v1/config/custom'
39
40 return makePutBodyRequest({
41 url,
42 token,
43 path,
44 fields: newCustomConfig,
45 statusCodeExpected
46 })
47}
48
8424c402 49function updateCustomSubConfig (url: string, token: string, newConfig: DeepPartial<CustomConfig>) {
590fb506
C
50 const updateParams: CustomConfig = {
51 instance: {
52 name: 'PeerTube updated',
53 shortDescription: 'my short description',
54 description: 'my super description',
55 terms: 'my super terms',
ccc00cb2
C
56 codeOfConduct: 'my super coc',
57
8ae03c37 58 creationReason: 'my super creation reason',
ccc00cb2
C
59 moderationInformation: 'my super moderation information',
60 administrator: 'Kuja',
61 maintenanceLifetime: 'forever',
62 businessModel: 'my super business model',
be04c6fd 63 hardwareInformation: '2vCore 3GB RAM',
ccc00cb2
C
64
65 languages: [ 'en', 'es' ],
66 categories: [ 1, 2 ],
67
f8802489 68 isNSFW: true,
590fb506 69 defaultNSFWPolicy: 'blur',
3da68f0a
RK
70
71 defaultClientRoute: '/videos/recently-added',
3da68f0a 72
590fb506
C
73 customizations: {
74 javascript: 'alert("coucou")',
75 css: 'body { background-color: red; }'
76 }
77 },
7cd4d2ba
C
78 theme: {
79 default: 'default'
80 },
590fb506
C
81 services: {
82 twitter: {
83 username: '@MySuperUsername',
84 whitelisted: true
85 }
86 },
87 cache: {
88 previews: {
89 size: 2
90 },
91 captions: {
92 size: 3
b3d5cb92
C
93 },
94 torrents: {
95 size: 4
590fb506
C
96 }
97 },
98 signup: {
99 enabled: false,
d9eaee39 100 limit: 5,
1f256e7d
P
101 requiresEmailVerification: false,
102 minimumAge: 16
590fb506
C
103 },
104 admin: {
105 email: 'superadmin1@example.com'
106 },
a4101923
C
107 contactForm: {
108 enabled: true
109 },
590fb506 110 user: {
bee0abff
FA
111 videoQuota: 5242881,
112 videoQuotaDaily: 318742
590fb506
C
113 },
114 transcoding: {
115 enabled: true,
14e2014a 116 allowAdditionalExtensions: true,
536598cf 117 allowAudioFiles: true,
590fb506 118 threads: 1,
9129b769 119 concurrency: 3,
1896bca0 120 profile: 'default',
590fb506 121 resolutions: {
5c7d6508 122 '0p': false,
590fb506
C
123 '240p': false,
124 '360p': true,
125 '480p': true,
126 '720p': false,
db714ab4 127 '1080p': false,
b7085c71 128 '1440p': false,
db714ab4 129 '2160p': false
09209296 130 },
d7a25329
C
131 webtorrent: {
132 enabled: true
133 },
09209296
C
134 hls: {
135 enabled: false
590fb506
C
136 }
137 },
c6c0fa6c
C
138 live: {
139 enabled: true,
fb719404 140 allowReplay: false,
c9bc850e 141 maxDuration: -1,
a056ca48
C
142 maxInstanceLives: -1,
143 maxUserLives: 50,
c6c0fa6c
C
144 transcoding: {
145 enabled: true,
146 threads: 4,
1896bca0 147 profile: 'default',
c6c0fa6c
C
148 resolutions: {
149 '240p': true,
150 '360p': true,
151 '480p': true,
152 '720p': true,
153 '1080p': true,
b7085c71 154 '1440p': true,
c6c0fa6c
C
155 '2160p': true
156 }
157 }
158 },
590fb506
C
159 import: {
160 videos: {
9129b769 161 concurrency: 3,
590fb506
C
162 http: {
163 enabled: false
a84b8fa5
C
164 },
165 torrent: {
166 enabled: false
590fb506
C
167 }
168 }
7ccddd7b 169 },
ba5d4a84
RK
170 trending: {
171 videos: {
172 algorithms: {
3d4e112d 173 enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
ba5d4a84
RK
174 default: 'hot'
175 }
176 }
177 },
7ccddd7b
JM
178 autoBlacklist: {
179 videos: {
180 ofUsers: {
181 enabled: false
182 }
183 }
5b9c965d
C
184 },
185 followers: {
186 instance: {
14893eb7
C
187 enabled: true,
188 manualApproval: false
5b9c965d 189 }
8424c402
C
190 },
191 followings: {
192 instance: {
193 autoFollowBack: {
194 enabled: false
195 },
196 autoFollowIndex: {
a06581f2 197 indexUrl: 'https://instances.joinpeertube.org/api/v1/instances/hosts',
8424c402
C
198 enabled: false
199 }
200 }
72c33e71
C
201 },
202 broadcastMessage: {
203 enabled: true,
204 level: 'warning',
205 message: 'hello',
206 dismissable: true
5fb2e288
C
207 },
208 search: {
209 remoteUri: {
210 users: true,
211 anonymous: true
212 },
213 searchIndex: {
214 enabled: true,
215 url: 'https://search.joinpeertube.org',
216 disableLocalSearch: true,
217 isDefaultSearch: true
218 }
590fb506
C
219 }
220 }
221
8424c402 222 merge(updateParams, newConfig)
590fb506
C
223
224 return updateCustomConfig(url, token, updateParams)
225}
226
a1bb73f9
C
227function getCustomConfigResolutions (enabled: boolean) {
228 return {
229 '240p': enabled,
230 '360p': enabled,
231 '480p': enabled,
232 '720p': enabled,
233 '1080p': enabled,
234 '1440p': enabled,
235 '2160p': enabled
236 }
237}
238
2d53be02 239function deleteCustomConfig (url: string, token: string, statusCodeExpected = HttpStatusCode.OK_200) {
fd206f0b
C
240 const path = '/api/v1/config/custom'
241
242 return makeDeleteRequest({
243 url,
244 token,
245 path,
246 statusCodeExpected
247 })
248}
249
0e1dc3e7
C
250// ---------------------------------------------------------------------------
251
252export {
fd206f0b
C
253 getConfig,
254 getCustomConfig,
255 updateCustomConfig,
36f9424f 256 getAbout,
590fb506 257 deleteCustomConfig,
a1bb73f9
C
258 updateCustomSubConfig,
259 getCustomConfigResolutions
0e1dc3e7 260}