]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - shared/extra-utils/server/config.ts
5152ec693218499fa43cdf9e6be2ad3e8f4145d1
[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 defaultTrendingRoute: '/videos/trending',
73 pages: {
74 hot: {
75 enabled: true
76 }
77 },
78
79 customizations: {
80 javascript: 'alert("coucou")',
81 css: 'body { background-color: red; }'
82 }
83 },
84 theme: {
85 default: 'default'
86 },
87 services: {
88 twitter: {
89 username: '@MySuperUsername',
90 whitelisted: true
91 }
92 },
93 cache: {
94 previews: {
95 size: 2
96 },
97 captions: {
98 size: 3
99 }
100 },
101 signup: {
102 enabled: false,
103 limit: 5,
104 requiresEmailVerification: false
105 },
106 admin: {
107 email: 'superadmin1@example.com'
108 },
109 contactForm: {
110 enabled: true
111 },
112 user: {
113 videoQuota: 5242881,
114 videoQuotaDaily: 318742
115 },
116 transcoding: {
117 enabled: true,
118 allowAdditionalExtensions: true,
119 allowAudioFiles: true,
120 threads: 1,
121 resolutions: {
122 '0p': false,
123 '240p': false,
124 '360p': true,
125 '480p': true,
126 '720p': false,
127 '1080p': false,
128 '1440p': false,
129 '2160p': false
130 },
131 webtorrent: {
132 enabled: true
133 },
134 hls: {
135 enabled: false
136 }
137 },
138 live: {
139 enabled: true,
140 allowReplay: false,
141 maxDuration: -1,
142 maxInstanceLives: -1,
143 maxUserLives: 50,
144 transcoding: {
145 enabled: true,
146 threads: 4,
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 http: {
161 enabled: false
162 },
163 torrent: {
164 enabled: false
165 }
166 }
167 },
168 autoBlacklist: {
169 videos: {
170 ofUsers: {
171 enabled: false
172 }
173 }
174 },
175 followers: {
176 instance: {
177 enabled: true,
178 manualApproval: false
179 }
180 },
181 followings: {
182 instance: {
183 autoFollowBack: {
184 enabled: false
185 },
186 autoFollowIndex: {
187 indexUrl: 'https://instances.joinpeertube.org/api/v1/instances/hosts',
188 enabled: false
189 }
190 }
191 },
192 broadcastMessage: {
193 enabled: true,
194 level: 'warning',
195 message: 'hello',
196 dismissable: true
197 },
198 search: {
199 remoteUri: {
200 users: true,
201 anonymous: true
202 },
203 searchIndex: {
204 enabled: true,
205 url: 'https://search.joinpeertube.org',
206 disableLocalSearch: true,
207 isDefaultSearch: true
208 }
209 }
210 }
211
212 merge(updateParams, newConfig)
213
214 return updateCustomConfig(url, token, updateParams)
215 }
216
217 function deleteCustomConfig (url: string, token: string, statusCodeExpected = HttpStatusCode.OK_200) {
218 const path = '/api/v1/config/custom'
219
220 return makeDeleteRequest({
221 url,
222 token,
223 path,
224 statusCodeExpected
225 })
226 }
227
228 // ---------------------------------------------------------------------------
229
230 export {
231 getConfig,
232 getCustomConfig,
233 updateCustomConfig,
234 getAbout,
235 deleteCustomConfig,
236 updateCustomSubConfig
237 }