]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/utils/server/config.ts
Move utils to /shared
[github/Chocobozzz/PeerTube.git] / shared / utils / server / config.ts
CommitLineData
fd206f0b 1import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../'
09cababd 2import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
0e1dc3e7
C
3
4function getConfig (url: string) {
5 const path = '/api/v1/config'
6
36f9424f
C
7 return makeGetRequest({
8 url,
9 path,
10 statusCodeExpected: 200
11 })
12}
13
14function getAbout (url: string) {
15 const path = '/api/v1/config/about'
16
17 return makeGetRequest({
18 url,
19 path,
20 statusCodeExpected: 200
21 })
0e1dc3e7
C
22}
23
fd206f0b
C
24function getCustomConfig (url: string, token: string, statusCodeExpected = 200) {
25 const path = '/api/v1/config/custom'
26
27 return makeGetRequest({
28 url,
29 token,
30 path,
31 statusCodeExpected
32 })
33}
34
35function updateCustomConfig (url: string, token: string, newCustomConfig: CustomConfig, statusCodeExpected = 200) {
36 const path = '/api/v1/config/custom'
37
38 return makePutBodyRequest({
39 url,
40 token,
41 path,
42 fields: newCustomConfig,
43 statusCodeExpected
44 })
45}
46
590fb506
C
47function updateCustomSubConfig (url: string, token: string, newConfig: any) {
48 const updateParams: CustomConfig = {
49 instance: {
50 name: 'PeerTube updated',
51 shortDescription: 'my short description',
52 description: 'my super description',
53 terms: 'my super terms',
54 defaultClientRoute: '/videos/recently-added',
55 defaultNSFWPolicy: 'blur',
56 customizations: {
57 javascript: 'alert("coucou")',
58 css: 'body { background-color: red; }'
59 }
60 },
61 services: {
62 twitter: {
63 username: '@MySuperUsername',
64 whitelisted: true
65 }
66 },
67 cache: {
68 previews: {
69 size: 2
70 },
71 captions: {
72 size: 3
73 }
74 },
75 signup: {
76 enabled: false,
d9eaee39
JM
77 limit: 5,
78 requiresEmailVerification: false
590fb506
C
79 },
80 admin: {
81 email: 'superadmin1@example.com'
82 },
83 user: {
bee0abff
FA
84 videoQuota: 5242881,
85 videoQuotaDaily: 318742
590fb506
C
86 },
87 transcoding: {
88 enabled: true,
89 threads: 1,
90 resolutions: {
91 '240p': false,
92 '360p': true,
93 '480p': true,
94 '720p': false,
95 '1080p': false
96 }
97 },
98 import: {
99 videos: {
100 http: {
101 enabled: false
a84b8fa5
C
102 },
103 torrent: {
104 enabled: false
590fb506
C
105 }
106 }
107 }
108 }
109
110 Object.assign(updateParams, newConfig)
111
112 return updateCustomConfig(url, token, updateParams)
113}
114
fd206f0b
C
115function deleteCustomConfig (url: string, token: string, statusCodeExpected = 200) {
116 const path = '/api/v1/config/custom'
117
118 return makeDeleteRequest({
119 url,
120 token,
121 path,
122 statusCodeExpected
123 })
124}
125
0e1dc3e7
C
126// ---------------------------------------------------------------------------
127
128export {
fd206f0b
C
129 getConfig,
130 getCustomConfig,
131 updateCustomConfig,
36f9424f 132 getAbout,
590fb506
C
133 deleteCustomConfig,
134 updateCustomSubConfig
0e1dc3e7 135}