]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/extra-utils/server/config.ts
Don't guess remote tracker URL
[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
93 }
94 },
95 signup: {
96 enabled: false,
d9eaee39
JM
97 limit: 5,
98 requiresEmailVerification: false
590fb506
C
99 },
100 admin: {
101 email: 'superadmin1@example.com'
102 },
a4101923
C
103 contactForm: {
104 enabled: true
105 },
590fb506 106 user: {
bee0abff
FA
107 videoQuota: 5242881,
108 videoQuotaDaily: 318742
590fb506
C
109 },
110 transcoding: {
111 enabled: true,
14e2014a 112 allowAdditionalExtensions: true,
536598cf 113 allowAudioFiles: true,
590fb506 114 threads: 1,
9129b769 115 concurrency: 3,
1896bca0 116 profile: 'default',
590fb506 117 resolutions: {
5c7d6508 118 '0p': false,
590fb506
C
119 '240p': false,
120 '360p': true,
121 '480p': true,
122 '720p': false,
db714ab4 123 '1080p': false,
b7085c71 124 '1440p': false,
db714ab4 125 '2160p': false
09209296 126 },
d7a25329
C
127 webtorrent: {
128 enabled: true
129 },
09209296
C
130 hls: {
131 enabled: false
590fb506
C
132 }
133 },
c6c0fa6c
C
134 live: {
135 enabled: true,
fb719404 136 allowReplay: false,
c9bc850e 137 maxDuration: -1,
a056ca48
C
138 maxInstanceLives: -1,
139 maxUserLives: 50,
c6c0fa6c
C
140 transcoding: {
141 enabled: true,
142 threads: 4,
1896bca0 143 profile: 'default',
c6c0fa6c
C
144 resolutions: {
145 '240p': true,
146 '360p': true,
147 '480p': true,
148 '720p': true,
149 '1080p': true,
b7085c71 150 '1440p': true,
c6c0fa6c
C
151 '2160p': true
152 }
153 }
154 },
590fb506
C
155 import: {
156 videos: {
9129b769 157 concurrency: 3,
590fb506
C
158 http: {
159 enabled: false
a84b8fa5
C
160 },
161 torrent: {
162 enabled: false
590fb506
C
163 }
164 }
7ccddd7b 165 },
ba5d4a84
RK
166 trending: {
167 videos: {
168 algorithms: {
3d4e112d 169 enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
ba5d4a84
RK
170 default: 'hot'
171 }
172 }
173 },
7ccddd7b
JM
174 autoBlacklist: {
175 videos: {
176 ofUsers: {
177 enabled: false
178 }
179 }
5b9c965d
C
180 },
181 followers: {
182 instance: {
14893eb7
C
183 enabled: true,
184 manualApproval: false
5b9c965d 185 }
8424c402
C
186 },
187 followings: {
188 instance: {
189 autoFollowBack: {
190 enabled: false
191 },
192 autoFollowIndex: {
a06581f2 193 indexUrl: 'https://instances.joinpeertube.org/api/v1/instances/hosts',
8424c402
C
194 enabled: false
195 }
196 }
72c33e71
C
197 },
198 broadcastMessage: {
199 enabled: true,
200 level: 'warning',
201 message: 'hello',
202 dismissable: true
5fb2e288
C
203 },
204 search: {
205 remoteUri: {
206 users: true,
207 anonymous: true
208 },
209 searchIndex: {
210 enabled: true,
211 url: 'https://search.joinpeertube.org',
212 disableLocalSearch: true,
213 isDefaultSearch: true
214 }
590fb506
C
215 }
216 }
217
8424c402 218 merge(updateParams, newConfig)
590fb506
C
219
220 return updateCustomConfig(url, token, updateParams)
221}
222
2d53be02 223function deleteCustomConfig (url: string, token: string, statusCodeExpected = HttpStatusCode.OK_200) {
fd206f0b
C
224 const path = '/api/v1/config/custom'
225
226 return makeDeleteRequest({
227 url,
228 token,
229 path,
230 statusCodeExpected
231 })
232}
233
0e1dc3e7
C
234// ---------------------------------------------------------------------------
235
236export {
fd206f0b
C
237 getConfig,
238 getCustomConfig,
239 updateCustomConfig,
36f9424f 240 getAbout,
590fb506
C
241 deleteCustomConfig,
242 updateCustomSubConfig
0e1dc3e7 243}