]>
Commit | Line | Data |
---|---|---|
1 | import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../requests/requests' | |
2 | import { CustomConfig } from '../../models/server/custom-config.model' | |
3 | import { DeepPartial } from '@server/typings/utils' | |
4 | import { merge } from 'lodash' | |
5 | ||
6 | function getConfig (url: string) { | |
7 | const path = '/api/v1/config' | |
8 | ||
9 | return makeGetRequest({ | |
10 | url, | |
11 | path, | |
12 | statusCodeExpected: 200 | |
13 | }) | |
14 | } | |
15 | ||
16 | function getAbout (url: string) { | |
17 | const path = '/api/v1/config/about' | |
18 | ||
19 | return makeGetRequest({ | |
20 | url, | |
21 | path, | |
22 | statusCodeExpected: 200 | |
23 | }) | |
24 | } | |
25 | ||
26 | function getCustomConfig (url: string, token: string, statusCodeExpected = 200) { | |
27 | const path = '/api/v1/config/custom' | |
28 | ||
29 | return makeGetRequest({ | |
30 | url, | |
31 | token, | |
32 | path, | |
33 | statusCodeExpected | |
34 | }) | |
35 | } | |
36 | ||
37 | function updateCustomConfig (url: string, token: string, newCustomConfig: CustomConfig, statusCodeExpected = 200) { | |
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 | ||
49 | function updateCustomSubConfig (url: string, token: string, newConfig: DeepPartial<CustomConfig>) { | |
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', | |
56 | codeOfConduct: 'my super coc', | |
57 | ||
58 | creationReason: 'my super creation reason', | |
59 | moderationInformation: 'my super moderation information', | |
60 | administrator: 'Kuja', | |
61 | maintenanceLifetime: 'forever', | |
62 | businessModel: 'my super business model', | |
63 | ||
64 | languages: [ 'en', 'es' ], | |
65 | categories: [ 1, 2 ], | |
66 | ||
67 | defaultClientRoute: '/videos/recently-added', | |
68 | isNSFW: true, | |
69 | defaultNSFWPolicy: 'blur', | |
70 | customizations: { | |
71 | javascript: 'alert("coucou")', | |
72 | css: 'body { background-color: red; }' | |
73 | } | |
74 | }, | |
75 | theme: { | |
76 | default: 'default' | |
77 | }, | |
78 | services: { | |
79 | twitter: { | |
80 | username: '@MySuperUsername', | |
81 | whitelisted: true | |
82 | } | |
83 | }, | |
84 | cache: { | |
85 | previews: { | |
86 | size: 2 | |
87 | }, | |
88 | captions: { | |
89 | size: 3 | |
90 | } | |
91 | }, | |
92 | signup: { | |
93 | enabled: false, | |
94 | limit: 5, | |
95 | requiresEmailVerification: false | |
96 | }, | |
97 | admin: { | |
98 | email: 'superadmin1@example.com' | |
99 | }, | |
100 | contactForm: { | |
101 | enabled: true | |
102 | }, | |
103 | user: { | |
104 | videoQuota: 5242881, | |
105 | videoQuotaDaily: 318742 | |
106 | }, | |
107 | transcoding: { | |
108 | enabled: true, | |
109 | allowAdditionalExtensions: true, | |
110 | allowAudioFiles: true, | |
111 | threads: 1, | |
112 | resolutions: { | |
113 | '240p': false, | |
114 | '360p': true, | |
115 | '480p': true, | |
116 | '720p': false, | |
117 | '1080p': false, | |
118 | '2160p': false | |
119 | }, | |
120 | hls: { | |
121 | enabled: false | |
122 | } | |
123 | }, | |
124 | import: { | |
125 | videos: { | |
126 | http: { | |
127 | enabled: false | |
128 | }, | |
129 | torrent: { | |
130 | enabled: false | |
131 | } | |
132 | } | |
133 | }, | |
134 | autoBlacklist: { | |
135 | videos: { | |
136 | ofUsers: { | |
137 | enabled: false | |
138 | } | |
139 | } | |
140 | }, | |
141 | followers: { | |
142 | instance: { | |
143 | enabled: true, | |
144 | manualApproval: false | |
145 | } | |
146 | }, | |
147 | followings: { | |
148 | instance: { | |
149 | autoFollowBack: { | |
150 | enabled: false | |
151 | }, | |
152 | autoFollowIndex: { | |
153 | indexUrl: 'https://instances.joinpeertube.org', | |
154 | enabled: false | |
155 | } | |
156 | } | |
157 | } | |
158 | } | |
159 | ||
160 | merge(updateParams, newConfig) | |
161 | ||
162 | return updateCustomConfig(url, token, updateParams) | |
163 | } | |
164 | ||
165 | function deleteCustomConfig (url: string, token: string, statusCodeExpected = 200) { | |
166 | const path = '/api/v1/config/custom' | |
167 | ||
168 | return makeDeleteRequest({ | |
169 | url, | |
170 | token, | |
171 | path, | |
172 | statusCodeExpected | |
173 | }) | |
174 | } | |
175 | ||
176 | // --------------------------------------------------------------------------- | |
177 | ||
178 | export { | |
179 | getConfig, | |
180 | getCustomConfig, | |
181 | updateCustomConfig, | |
182 | getAbout, | |
183 | deleteCustomConfig, | |
184 | updateCustomSubConfig | |
185 | } |