]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - shared/extra-utils/server/config.ts
efe569243b01d47324f943041f3ca039a333afbc
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / server / config.ts
1 import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../requests/requests'
2 import { CustomConfig } from '../../models/server/custom-config.model'
3 import { DeepPartial, HttpStatusCode } from '@shared/core-utils'
4 import { merge } from 'lodash'
5
6 function getConfig (url: string) {
7 const path = '/api/v1/config'
8
9 return makeGetRequest({
10 url,
11 path,
12 statusCodeExpected: HttpStatusCode.OK_200
13 })
14 }
15
16 function getAbout (url: string) {
17 const path = '/api/v1/config/about'
18
19 return makeGetRequest({
20 url,
21 path,
22 statusCodeExpected: HttpStatusCode.OK_200
23 })
24 }
25
26 function getCustomConfig (url: string, token: string, statusCodeExpected = HttpStatusCode.OK_200) {
27 const path = '/api/v1/config/custom'
28
29 return makeGetRequest({
30 url,
31 token,
32 path,
33 statusCodeExpected
34 })
35 }
36
37 function updateCustomConfig (url: string, token: string, newCustomConfig: CustomConfig, statusCodeExpected = HttpStatusCode.OK_200) {
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
49 function updateCustomSubConfig (url: string, token: string, newConfig: DeepPartial<CustomConfig>) {
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',
56 codeOfConduct: 'my super coc',
57
58 creationReason: 'my super creation reason',
59 moderationInformation: 'my super moderation information',
60 administrator: 'Kuja',
61 maintenanceLifetime: 'forever',
62 businessModel: 'my super business model',
63 hardwareInformation: '2vCore 3GB RAM',
64
65 languages: [ 'en', 'es' ],
66 categories: [ 1, 2 ],
67
68 isNSFW: true,
69 defaultNSFWPolicy: 'blur',
70
71 defaultClientRoute: '/videos/recently-added',
72
73 customizations: {
74 javascript: 'alert("coucou")',
75 css: 'body { background-color: red; }'
76 }
77 },
78 theme: {
79 default: 'default'
80 },
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,
97 limit: 5,
98 requiresEmailVerification: false
99 },
100 admin: {
101 email: 'superadmin1@example.com'
102 },
103 contactForm: {
104 enabled: true
105 },
106 user: {
107 videoQuota: 5242881,
108 videoQuotaDaily: 318742
109 },
110 transcoding: {
111 enabled: true,
112 allowAdditionalExtensions: true,
113 allowAudioFiles: true,
114 threads: 1,
115 concurrency: 3,
116 profile: 'default',
117 resolutions: {
118 '0p': false,
119 '240p': false,
120 '360p': true,
121 '480p': true,
122 '720p': false,
123 '1080p': false,
124 '1440p': false,
125 '2160p': false
126 },
127 webtorrent: {
128 enabled: true
129 },
130 hls: {
131 enabled: false
132 }
133 },
134 live: {
135 enabled: true,
136 allowReplay: false,
137 maxDuration: -1,
138 maxInstanceLives: -1,
139 maxUserLives: 50,
140 transcoding: {
141 enabled: true,
142 threads: 4,
143 profile: 'default',
144 resolutions: {
145 '240p': true,
146 '360p': true,
147 '480p': true,
148 '720p': true,
149 '1080p': true,
150 '1440p': true,
151 '2160p': true
152 }
153 }
154 },
155 import: {
156 videos: {
157 concurrency: 3,
158 http: {
159 enabled: false
160 },
161 torrent: {
162 enabled: false
163 }
164 }
165 },
166 trending: {
167 videos: {
168 algorithms: {
169 enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
170 default: 'hot'
171 }
172 }
173 },
174 autoBlacklist: {
175 videos: {
176 ofUsers: {
177 enabled: false
178 }
179 }
180 },
181 followers: {
182 instance: {
183 enabled: true,
184 manualApproval: false
185 }
186 },
187 followings: {
188 instance: {
189 autoFollowBack: {
190 enabled: false
191 },
192 autoFollowIndex: {
193 indexUrl: 'https://instances.joinpeertube.org/api/v1/instances/hosts',
194 enabled: false
195 }
196 }
197 },
198 broadcastMessage: {
199 enabled: true,
200 level: 'warning',
201 message: 'hello',
202 dismissable: true
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 }
215 }
216 }
217
218 merge(updateParams, newConfig)
219
220 return updateCustomConfig(url, token, updateParams)
221 }
222
223 function deleteCustomConfig (url: string, token: string, statusCodeExpected = HttpStatusCode.OK_200) {
224 const path = '/api/v1/config/custom'
225
226 return makeDeleteRequest({
227 url,
228 token,
229 path,
230 statusCodeExpected
231 })
232 }
233
234 // ---------------------------------------------------------------------------
235
236 export {
237 getConfig,
238 getCustomConfig,
239 updateCustomConfig,
240 getAbout,
241 deleteCustomConfig,
242 updateCustomSubConfig
243 }