]>
Commit | Line | Data |
---|---|---|
1 | import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../requests/requests' | |
2 | import { CustomConfig } from '../../models/server/custom-config.model' | |
3 | import { DeepPartial } 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: 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: 200 | |
23 | }) | |
24 | } | |
25 | ||
26 | function getCustomConfig (url: string, token: string, statusCodeExpected = 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 = 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 | defaultClientRoute: '/videos/recently-added', | |
69 | isNSFW: true, | |
70 | defaultNSFWPolicy: 'blur', | |
71 | customizations: { | |
72 | javascript: 'alert("coucou")', | |
73 | css: 'body { background-color: red; }' | |
74 | } | |
75 | }, | |
76 | theme: { | |
77 | default: 'default' | |
78 | }, | |
79 | services: { | |
80 | twitter: { | |
81 | username: '@MySuperUsername', | |
82 | whitelisted: true | |
83 | } | |
84 | }, | |
85 | cache: { | |
86 | previews: { | |
87 | size: 2 | |
88 | }, | |
89 | captions: { | |
90 | size: 3 | |
91 | } | |
92 | }, | |
93 | signup: { | |
94 | enabled: false, | |
95 | limit: 5, | |
96 | requiresEmailVerification: false | |
97 | }, | |
98 | admin: { | |
99 | email: 'superadmin1@example.com' | |
100 | }, | |
101 | contactForm: { | |
102 | enabled: true | |
103 | }, | |
104 | user: { | |
105 | videoQuota: 5242881, | |
106 | videoQuotaDaily: 318742 | |
107 | }, | |
108 | transcoding: { | |
109 | enabled: true, | |
110 | allowAdditionalExtensions: true, | |
111 | allowAudioFiles: true, | |
112 | threads: 1, | |
113 | resolutions: { | |
114 | '0p': false, | |
115 | '240p': false, | |
116 | '360p': true, | |
117 | '480p': true, | |
118 | '720p': false, | |
119 | '1080p': false, | |
120 | '2160p': false | |
121 | }, | |
122 | webtorrent: { | |
123 | enabled: true | |
124 | }, | |
125 | hls: { | |
126 | enabled: false | |
127 | } | |
128 | }, | |
129 | live: { | |
130 | enabled: true, | |
131 | allowReplay: false, | |
132 | maxDuration: null, | |
133 | maxInstanceLives: -1, | |
134 | maxUserLives: 50, | |
135 | transcoding: { | |
136 | enabled: true, | |
137 | threads: 4, | |
138 | resolutions: { | |
139 | '240p': true, | |
140 | '360p': true, | |
141 | '480p': true, | |
142 | '720p': true, | |
143 | '1080p': true, | |
144 | '2160p': true | |
145 | } | |
146 | } | |
147 | }, | |
148 | import: { | |
149 | videos: { | |
150 | http: { | |
151 | enabled: false | |
152 | }, | |
153 | torrent: { | |
154 | enabled: false | |
155 | } | |
156 | } | |
157 | }, | |
158 | autoBlacklist: { | |
159 | videos: { | |
160 | ofUsers: { | |
161 | enabled: false | |
162 | } | |
163 | } | |
164 | }, | |
165 | followers: { | |
166 | instance: { | |
167 | enabled: true, | |
168 | manualApproval: false | |
169 | } | |
170 | }, | |
171 | followings: { | |
172 | instance: { | |
173 | autoFollowBack: { | |
174 | enabled: false | |
175 | }, | |
176 | autoFollowIndex: { | |
177 | indexUrl: 'https://instances.joinpeertube.org/api/v1/instances/hosts', | |
178 | enabled: false | |
179 | } | |
180 | } | |
181 | }, | |
182 | broadcastMessage: { | |
183 | enabled: true, | |
184 | level: 'warning', | |
185 | message: 'hello', | |
186 | dismissable: true | |
187 | }, | |
188 | search: { | |
189 | remoteUri: { | |
190 | users: true, | |
191 | anonymous: true | |
192 | }, | |
193 | searchIndex: { | |
194 | enabled: true, | |
195 | url: 'https://search.joinpeertube.org', | |
196 | disableLocalSearch: true, | |
197 | isDefaultSearch: true | |
198 | } | |
199 | } | |
200 | } | |
201 | ||
202 | merge(updateParams, newConfig) | |
203 | ||
204 | return updateCustomConfig(url, token, updateParams) | |
205 | } | |
206 | ||
207 | function deleteCustomConfig (url: string, token: string, statusCodeExpected = 200) { | |
208 | const path = '/api/v1/config/custom' | |
209 | ||
210 | return makeDeleteRequest({ | |
211 | url, | |
212 | token, | |
213 | path, | |
214 | statusCodeExpected | |
215 | }) | |
216 | } | |
217 | ||
218 | // --------------------------------------------------------------------------- | |
219 | ||
220 | export { | |
221 | getConfig, | |
222 | getCustomConfig, | |
223 | updateCustomConfig, | |
224 | getAbout, | |
225 | deleteCustomConfig, | |
226 | updateCustomSubConfig | |
227 | } |