]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - shared/extra-utils/server/config.ts
deb77e9c0e1067f98a9a73a2b94711022dd3a056
[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
4 function getConfig (url: string) {
5 const path = '/api/v1/config'
6
7 return makeGetRequest({
8 url,
9 path,
10 statusCodeExpected: 200
11 })
12 }
13
14 function getAbout (url: string) {
15 const path = '/api/v1/config/about'
16
17 return makeGetRequest({
18 url,
19 path,
20 statusCodeExpected: 200
21 })
22 }
23
24 function 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
35 function 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
47 function 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 isNSFW: true,
56 defaultNSFWPolicy: 'blur',
57 customizations: {
58 javascript: 'alert("coucou")',
59 css: 'body { background-color: red; }'
60 }
61 },
62 services: {
63 twitter: {
64 username: '@MySuperUsername',
65 whitelisted: true
66 }
67 },
68 cache: {
69 previews: {
70 size: 2
71 },
72 captions: {
73 size: 3
74 }
75 },
76 signup: {
77 enabled: false,
78 limit: 5,
79 requiresEmailVerification: false
80 },
81 admin: {
82 email: 'superadmin1@example.com'
83 },
84 contactForm: {
85 enabled: true
86 },
87 user: {
88 videoQuota: 5242881,
89 videoQuotaDaily: 318742
90 },
91 transcoding: {
92 enabled: true,
93 allowAdditionalExtensions: true,
94 threads: 1,
95 resolutions: {
96 '240p': false,
97 '360p': true,
98 '480p': true,
99 '720p': false,
100 '1080p': false
101 },
102 hls: {
103 enabled: false
104 }
105 },
106 import: {
107 videos: {
108 http: {
109 enabled: false
110 },
111 torrent: {
112 enabled: false
113 }
114 }
115 },
116 autoBlacklist: {
117 videos: {
118 ofUsers: {
119 enabled: false
120 }
121 }
122 },
123 followers: {
124 instance: {
125 enabled: true,
126 manualApproval: false
127 }
128 }
129 }
130
131 Object.assign(updateParams, newConfig)
132
133 return updateCustomConfig(url, token, updateParams)
134 }
135
136 function deleteCustomConfig (url: string, token: string, statusCodeExpected = 200) {
137 const path = '/api/v1/config/custom'
138
139 return makeDeleteRequest({
140 url,
141 token,
142 path,
143 statusCodeExpected
144 })
145 }
146
147 // ---------------------------------------------------------------------------
148
149 export {
150 getConfig,
151 getCustomConfig,
152 updateCustomConfig,
153 getAbout,
154 deleteCustomConfig,
155 updateCustomSubConfig
156 }