]>
Commit | Line | Data |
---|---|---|
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 | torrents: { | |
95 | size: 4 | |
96 | } | |
97 | }, | |
98 | signup: { | |
99 | enabled: false, | |
100 | limit: 5, | |
101 | requiresEmailVerification: false | |
102 | }, | |
103 | admin: { | |
104 | email: 'superadmin1@example.com' | |
105 | }, | |
106 | contactForm: { | |
107 | enabled: true | |
108 | }, | |
109 | user: { | |
110 | videoQuota: 5242881, | |
111 | videoQuotaDaily: 318742 | |
112 | }, | |
113 | transcoding: { | |
114 | enabled: true, | |
115 | allowAdditionalExtensions: true, | |
116 | allowAudioFiles: true, | |
117 | threads: 1, | |
118 | concurrency: 3, | |
119 | profile: 'default', | |
120 | resolutions: { | |
121 | '0p': false, | |
122 | '240p': false, | |
123 | '360p': true, | |
124 | '480p': true, | |
125 | '720p': false, | |
126 | '1080p': false, | |
127 | '1440p': false, | |
128 | '2160p': false | |
129 | }, | |
130 | webtorrent: { | |
131 | enabled: true | |
132 | }, | |
133 | hls: { | |
134 | enabled: false | |
135 | } | |
136 | }, | |
137 | live: { | |
138 | enabled: true, | |
139 | allowReplay: false, | |
140 | maxDuration: -1, | |
141 | maxInstanceLives: -1, | |
142 | maxUserLives: 50, | |
143 | transcoding: { | |
144 | enabled: true, | |
145 | threads: 4, | |
146 | profile: 'default', | |
147 | resolutions: { | |
148 | '240p': true, | |
149 | '360p': true, | |
150 | '480p': true, | |
151 | '720p': true, | |
152 | '1080p': true, | |
153 | '1440p': true, | |
154 | '2160p': true | |
155 | } | |
156 | } | |
157 | }, | |
158 | import: { | |
159 | videos: { | |
160 | concurrency: 3, | |
161 | http: { | |
162 | enabled: false | |
163 | }, | |
164 | torrent: { | |
165 | enabled: false | |
166 | } | |
167 | } | |
168 | }, | |
169 | trending: { | |
170 | videos: { | |
171 | algorithms: { | |
172 | enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ], | |
173 | default: 'hot' | |
174 | } | |
175 | } | |
176 | }, | |
177 | autoBlacklist: { | |
178 | videos: { | |
179 | ofUsers: { | |
180 | enabled: false | |
181 | } | |
182 | } | |
183 | }, | |
184 | followers: { | |
185 | instance: { | |
186 | enabled: true, | |
187 | manualApproval: false | |
188 | } | |
189 | }, | |
190 | followings: { | |
191 | instance: { | |
192 | autoFollowBack: { | |
193 | enabled: false | |
194 | }, | |
195 | autoFollowIndex: { | |
196 | indexUrl: 'https://instances.joinpeertube.org/api/v1/instances/hosts', | |
197 | enabled: false | |
198 | } | |
199 | } | |
200 | }, | |
201 | broadcastMessage: { | |
202 | enabled: true, | |
203 | level: 'warning', | |
204 | message: 'hello', | |
205 | dismissable: true | |
206 | }, | |
207 | search: { | |
208 | remoteUri: { | |
209 | users: true, | |
210 | anonymous: true | |
211 | }, | |
212 | searchIndex: { | |
213 | enabled: true, | |
214 | url: 'https://search.joinpeertube.org', | |
215 | disableLocalSearch: true, | |
216 | isDefaultSearch: true | |
217 | } | |
218 | } | |
219 | } | |
220 | ||
221 | merge(updateParams, newConfig) | |
222 | ||
223 | return updateCustomConfig(url, token, updateParams) | |
224 | } | |
225 | ||
226 | function getCustomConfigResolutions (enabled: boolean) { | |
227 | return { | |
228 | '240p': enabled, | |
229 | '360p': enabled, | |
230 | '480p': enabled, | |
231 | '720p': enabled, | |
232 | '1080p': enabled, | |
233 | '1440p': enabled, | |
234 | '2160p': enabled | |
235 | } | |
236 | } | |
237 | ||
238 | function deleteCustomConfig (url: string, token: string, statusCodeExpected = HttpStatusCode.OK_200) { | |
239 | const path = '/api/v1/config/custom' | |
240 | ||
241 | return makeDeleteRequest({ | |
242 | url, | |
243 | token, | |
244 | path, | |
245 | statusCodeExpected | |
246 | }) | |
247 | } | |
248 | ||
249 | // --------------------------------------------------------------------------- | |
250 | ||
251 | export { | |
252 | getConfig, | |
253 | getCustomConfig, | |
254 | updateCustomConfig, | |
255 | getAbout, | |
256 | deleteCustomConfig, | |
257 | updateCustomSubConfig, | |
258 | getCustomConfigResolutions | |
259 | } |