]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - shared/extra-utils/server/config.ts
8736f083f55ea8e6c6245a1ac3abf2c77fd6fed5
[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 theme: {
63 default: 'default'
64 },
65 services: {
66 twitter: {
67 username: '@MySuperUsername',
68 whitelisted: true
69 }
70 },
71 cache: {
72 previews: {
73 size: 2
74 },
75 captions: {
76 size: 3
77 }
78 },
79 signup: {
80 enabled: false,
81 limit: 5,
82 requiresEmailVerification: false
83 },
84 admin: {
85 email: 'superadmin1@example.com'
86 },
87 contactForm: {
88 enabled: true
89 },
90 user: {
91 videoQuota: 5242881,
92 videoQuotaDaily: 318742
93 },
94 transcoding: {
95 enabled: true,
96 allowAdditionalExtensions: true,
97 allowAudioFiles: true,
98 threads: 1,
99 resolutions: {
100 '240p': false,
101 '360p': true,
102 '480p': true,
103 '720p': false,
104 '1080p': false,
105 '2160p': false
106 },
107 hls: {
108 enabled: false
109 }
110 },
111 import: {
112 videos: {
113 http: {
114 enabled: false
115 },
116 torrent: {
117 enabled: false
118 }
119 }
120 },
121 autoBlacklist: {
122 videos: {
123 ofUsers: {
124 enabled: false
125 }
126 }
127 },
128 followers: {
129 instance: {
130 enabled: true,
131 manualApproval: false
132 }
133 }
134 }
135
136 Object.assign(updateParams, newConfig)
137
138 return updateCustomConfig(url, token, updateParams)
139 }
140
141 function deleteCustomConfig (url: string, token: string, statusCodeExpected = 200) {
142 const path = '/api/v1/config/custom'
143
144 return makeDeleteRequest({
145 url,
146 token,
147 path,
148 statusCodeExpected
149 })
150 }
151
152 // ---------------------------------------------------------------------------
153
154 export {
155 getConfig,
156 getCustomConfig,
157 updateCustomConfig,
158 getAbout,
159 deleteCustomConfig,
160 updateCustomSubConfig
161 }