]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/extra-utils/server/config.ts
modularize abstract video list header and implement video hotness recommendation...
[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
590fb506 68 defaultClientRoute: '/videos/recently-added',
f8802489 69 isNSFW: true,
590fb506
C
70 defaultNSFWPolicy: 'blur',
71 customizations: {
72 javascript: 'alert("coucou")',
73 css: 'body { background-color: red; }'
74 }
75 },
7cd4d2ba
C
76 theme: {
77 default: 'default'
78 },
590fb506
C
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,
d9eaee39
JM
95 limit: 5,
96 requiresEmailVerification: false
590fb506
C
97 },
98 admin: {
99 email: 'superadmin1@example.com'
100 },
a4101923
C
101 contactForm: {
102 enabled: true
103 },
590fb506 104 user: {
bee0abff
FA
105 videoQuota: 5242881,
106 videoQuotaDaily: 318742
590fb506
C
107 },
108 transcoding: {
109 enabled: true,
14e2014a 110 allowAdditionalExtensions: true,
536598cf 111 allowAudioFiles: true,
590fb506
C
112 threads: 1,
113 resolutions: {
5c7d6508 114 '0p': false,
590fb506
C
115 '240p': false,
116 '360p': true,
117 '480p': true,
118 '720p': false,
db714ab4 119 '1080p': false,
b7085c71 120 '1440p': false,
db714ab4 121 '2160p': false
09209296 122 },
d7a25329
C
123 webtorrent: {
124 enabled: true
125 },
09209296
C
126 hls: {
127 enabled: false
590fb506
C
128 }
129 },
c6c0fa6c
C
130 live: {
131 enabled: true,
fb719404 132 allowReplay: false,
c9bc850e 133 maxDuration: -1,
a056ca48
C
134 maxInstanceLives: -1,
135 maxUserLives: 50,
c6c0fa6c
C
136 transcoding: {
137 enabled: true,
138 threads: 4,
139 resolutions: {
140 '240p': true,
141 '360p': true,
142 '480p': true,
143 '720p': true,
144 '1080p': true,
b7085c71 145 '1440p': true,
c6c0fa6c
C
146 '2160p': true
147 }
148 }
149 },
590fb506
C
150 import: {
151 videos: {
152 http: {
153 enabled: false
a84b8fa5
C
154 },
155 torrent: {
156 enabled: false
590fb506
C
157 }
158 }
7ccddd7b
JM
159 },
160 autoBlacklist: {
161 videos: {
162 ofUsers: {
163 enabled: false
164 }
165 }
5b9c965d
C
166 },
167 followers: {
168 instance: {
14893eb7
C
169 enabled: true,
170 manualApproval: false
5b9c965d 171 }
8424c402
C
172 },
173 followings: {
174 instance: {
175 autoFollowBack: {
176 enabled: false
177 },
178 autoFollowIndex: {
a06581f2 179 indexUrl: 'https://instances.joinpeertube.org/api/v1/instances/hosts',
8424c402
C
180 enabled: false
181 }
182 }
72c33e71
C
183 },
184 broadcastMessage: {
185 enabled: true,
186 level: 'warning',
187 message: 'hello',
188 dismissable: true
5fb2e288
C
189 },
190 search: {
191 remoteUri: {
192 users: true,
193 anonymous: true
194 },
195 searchIndex: {
196 enabled: true,
197 url: 'https://search.joinpeertube.org',
198 disableLocalSearch: true,
199 isDefaultSearch: true
200 }
590fb506
C
201 }
202 }
203
8424c402 204 merge(updateParams, newConfig)
590fb506
C
205
206 return updateCustomConfig(url, token, updateParams)
207}
208
2d53be02 209function deleteCustomConfig (url: string, token: string, statusCodeExpected = HttpStatusCode.OK_200) {
fd206f0b
C
210 const path = '/api/v1/config/custom'
211
212 return makeDeleteRequest({
213 url,
214 token,
215 path,
216 statusCodeExpected
217 })
218}
219
0e1dc3e7
C
220// ---------------------------------------------------------------------------
221
222export {
fd206f0b
C
223 getConfig,
224 getCustomConfig,
225 updateCustomConfig,
36f9424f 226 getAbout,
590fb506
C
227 deleteCustomConfig,
228 updateCustomSubConfig
0e1dc3e7 229}