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