]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - shared/extra-utils/server/config.ts
4e09e041233c6923dff840422995bab3fa3163cf
[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 resolutions: {
116 '0p': false,
117 '240p': false,
118 '360p': true,
119 '480p': true,
120 '720p': false,
121 '1080p': false,
122 '1440p': false,
123 '2160p': false
124 },
125 webtorrent: {
126 enabled: true
127 },
128 hls: {
129 enabled: false
130 }
131 },
132 live: {
133 enabled: true,
134 allowReplay: false,
135 maxDuration: -1,
136 maxInstanceLives: -1,
137 maxUserLives: 50,
138 transcoding: {
139 enabled: true,
140 threads: 4,
141 resolutions: {
142 '240p': true,
143 '360p': true,
144 '480p': true,
145 '720p': true,
146 '1080p': true,
147 '1440p': true,
148 '2160p': true
149 }
150 }
151 },
152 import: {
153 videos: {
154 http: {
155 enabled: false
156 },
157 torrent: {
158 enabled: false
159 }
160 }
161 },
162 trending: {
163 videos: {
164 algorithms: {
165 enabled: [ 'hot', 'most-viewed', 'most-liked' ],
166 default: 'hot'
167 }
168 }
169 },
170 autoBlacklist: {
171 videos: {
172 ofUsers: {
173 enabled: false
174 }
175 }
176 },
177 followers: {
178 instance: {
179 enabled: true,
180 manualApproval: false
181 }
182 },
183 followings: {
184 instance: {
185 autoFollowBack: {
186 enabled: false
187 },
188 autoFollowIndex: {
189 indexUrl: 'https://instances.joinpeertube.org/api/v1/instances/hosts',
190 enabled: false
191 }
192 }
193 },
194 broadcastMessage: {
195 enabled: true,
196 level: 'warning',
197 message: 'hello',
198 dismissable: true
199 },
200 search: {
201 remoteUri: {
202 users: true,
203 anonymous: true
204 },
205 searchIndex: {
206 enabled: true,
207 url: 'https://search.joinpeertube.org',
208 disableLocalSearch: true,
209 isDefaultSearch: true
210 }
211 }
212 }
213
214 merge(updateParams, newConfig)
215
216 return updateCustomConfig(url, token, updateParams)
217 }
218
219 function deleteCustomConfig (url: string, token: string, statusCodeExpected = HttpStatusCode.OK_200) {
220 const path = '/api/v1/config/custom'
221
222 return makeDeleteRequest({
223 url,
224 token,
225 path,
226 statusCodeExpected
227 })
228 }
229
230 // ---------------------------------------------------------------------------
231
232 export {
233 getConfig,
234 getCustomConfig,
235 updateCustomConfig,
236 getAbout,
237 deleteCustomConfig,
238 updateCustomSubConfig
239 }