diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-07 11:51:09 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-20 15:27:17 +0200 |
commit | 65e6e2602c0d5521f3a6740f7469bb92830ecb53 (patch) | |
tree | f89024ffff1dafb0281ee2fe028e89b95101bd44 /shared | |
parent | bc8090411ddaa8d742ce4de3c83f9dba7bc18e2a (diff) | |
download | PeerTube-65e6e2602c0d5521f3a6740f7469bb92830ecb53.tar.gz PeerTube-65e6e2602c0d5521f3a6740f7469bb92830ecb53.tar.zst PeerTube-65e6e2602c0d5521f3a6740f7469bb92830ecb53.zip |
Introduce config command
Diffstat (limited to 'shared')
-rw-r--r-- | shared/extra-utils/server/config-command.ts | 260 | ||||
-rw-r--r-- | shared/extra-utils/server/config.ts | 260 | ||||
-rw-r--r-- | shared/extra-utils/server/index.ts | 2 | ||||
-rw-r--r-- | shared/extra-utils/server/servers.ts | 3 |
4 files changed, 264 insertions, 261 deletions
diff --git a/shared/extra-utils/server/config-command.ts b/shared/extra-utils/server/config-command.ts new file mode 100644 index 000000000..959848706 --- /dev/null +++ b/shared/extra-utils/server/config-command.ts | |||
@@ -0,0 +1,260 @@ | |||
1 | import { merge } from 'lodash' | ||
2 | import { DeepPartial, HttpStatusCode } from '@shared/core-utils' | ||
3 | import { About, ServerConfig } from '@shared/models' | ||
4 | import { CustomConfig } from '../../models/server/custom-config.model' | ||
5 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
6 | |||
7 | export class ConfigCommand extends AbstractCommand { | ||
8 | |||
9 | static getCustomConfigResolutions (enabled: boolean) { | ||
10 | return { | ||
11 | '240p': enabled, | ||
12 | '360p': enabled, | ||
13 | '480p': enabled, | ||
14 | '720p': enabled, | ||
15 | '1080p': enabled, | ||
16 | '1440p': enabled, | ||
17 | '2160p': enabled | ||
18 | } | ||
19 | } | ||
20 | |||
21 | getConfig (options: OverrideCommandOptions = {}) { | ||
22 | const path = '/api/v1/config' | ||
23 | |||
24 | return this.getRequestBody<ServerConfig>({ | ||
25 | ...options, | ||
26 | |||
27 | token: null, | ||
28 | path, | ||
29 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
30 | }) | ||
31 | } | ||
32 | |||
33 | getAbout (options: OverrideCommandOptions = {}) { | ||
34 | const path = '/api/v1/config/about' | ||
35 | |||
36 | return this.getRequestBody<About>({ | ||
37 | ...options, | ||
38 | |||
39 | token: null, | ||
40 | path, | ||
41 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
42 | }) | ||
43 | } | ||
44 | |||
45 | getCustomConfig (options: OverrideCommandOptions = {}) { | ||
46 | const path = '/api/v1/config/custom' | ||
47 | |||
48 | return this.getRequestBody<CustomConfig>({ | ||
49 | ...options, | ||
50 | |||
51 | path, | ||
52 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
53 | }) | ||
54 | } | ||
55 | |||
56 | updateCustomConfig (options: OverrideCommandOptions & { | ||
57 | newCustomConfig: CustomConfig | ||
58 | }) { | ||
59 | const path = '/api/v1/config/custom' | ||
60 | |||
61 | return this.putBodyRequest({ | ||
62 | ...options, | ||
63 | |||
64 | path, | ||
65 | fields: options.newCustomConfig, | ||
66 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
67 | }) | ||
68 | } | ||
69 | |||
70 | deleteCustomConfig (options: OverrideCommandOptions = {}) { | ||
71 | const path = '/api/v1/config/custom' | ||
72 | |||
73 | return this.deleteRequest({ | ||
74 | ...options, | ||
75 | |||
76 | path, | ||
77 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
78 | }) | ||
79 | } | ||
80 | |||
81 | updateCustomSubConfig (options: OverrideCommandOptions & { | ||
82 | newConfig: DeepPartial<CustomConfig> | ||
83 | }) { | ||
84 | const newCustomConfig: CustomConfig = { | ||
85 | instance: { | ||
86 | name: 'PeerTube updated', | ||
87 | shortDescription: 'my short description', | ||
88 | description: 'my super description', | ||
89 | terms: 'my super terms', | ||
90 | codeOfConduct: 'my super coc', | ||
91 | |||
92 | creationReason: 'my super creation reason', | ||
93 | moderationInformation: 'my super moderation information', | ||
94 | administrator: 'Kuja', | ||
95 | maintenanceLifetime: 'forever', | ||
96 | businessModel: 'my super business model', | ||
97 | hardwareInformation: '2vCore 3GB RAM', | ||
98 | |||
99 | languages: [ 'en', 'es' ], | ||
100 | categories: [ 1, 2 ], | ||
101 | |||
102 | isNSFW: true, | ||
103 | defaultNSFWPolicy: 'blur', | ||
104 | |||
105 | defaultClientRoute: '/videos/recently-added', | ||
106 | |||
107 | customizations: { | ||
108 | javascript: 'alert("coucou")', | ||
109 | css: 'body { background-color: red; }' | ||
110 | } | ||
111 | }, | ||
112 | theme: { | ||
113 | default: 'default' | ||
114 | }, | ||
115 | services: { | ||
116 | twitter: { | ||
117 | username: '@MySuperUsername', | ||
118 | whitelisted: true | ||
119 | } | ||
120 | }, | ||
121 | cache: { | ||
122 | previews: { | ||
123 | size: 2 | ||
124 | }, | ||
125 | captions: { | ||
126 | size: 3 | ||
127 | }, | ||
128 | torrents: { | ||
129 | size: 4 | ||
130 | } | ||
131 | }, | ||
132 | signup: { | ||
133 | enabled: false, | ||
134 | limit: 5, | ||
135 | requiresEmailVerification: false, | ||
136 | minimumAge: 16 | ||
137 | }, | ||
138 | admin: { | ||
139 | email: 'superadmin1@example.com' | ||
140 | }, | ||
141 | contactForm: { | ||
142 | enabled: true | ||
143 | }, | ||
144 | user: { | ||
145 | videoQuota: 5242881, | ||
146 | videoQuotaDaily: 318742 | ||
147 | }, | ||
148 | transcoding: { | ||
149 | enabled: true, | ||
150 | allowAdditionalExtensions: true, | ||
151 | allowAudioFiles: true, | ||
152 | threads: 1, | ||
153 | concurrency: 3, | ||
154 | profile: 'default', | ||
155 | resolutions: { | ||
156 | '0p': false, | ||
157 | '240p': false, | ||
158 | '360p': true, | ||
159 | '480p': true, | ||
160 | '720p': false, | ||
161 | '1080p': false, | ||
162 | '1440p': false, | ||
163 | '2160p': false | ||
164 | }, | ||
165 | webtorrent: { | ||
166 | enabled: true | ||
167 | }, | ||
168 | hls: { | ||
169 | enabled: false | ||
170 | } | ||
171 | }, | ||
172 | live: { | ||
173 | enabled: true, | ||
174 | allowReplay: false, | ||
175 | maxDuration: -1, | ||
176 | maxInstanceLives: -1, | ||
177 | maxUserLives: 50, | ||
178 | transcoding: { | ||
179 | enabled: true, | ||
180 | threads: 4, | ||
181 | profile: 'default', | ||
182 | resolutions: { | ||
183 | '240p': true, | ||
184 | '360p': true, | ||
185 | '480p': true, | ||
186 | '720p': true, | ||
187 | '1080p': true, | ||
188 | '1440p': true, | ||
189 | '2160p': true | ||
190 | } | ||
191 | } | ||
192 | }, | ||
193 | import: { | ||
194 | videos: { | ||
195 | concurrency: 3, | ||
196 | http: { | ||
197 | enabled: false | ||
198 | }, | ||
199 | torrent: { | ||
200 | enabled: false | ||
201 | } | ||
202 | } | ||
203 | }, | ||
204 | trending: { | ||
205 | videos: { | ||
206 | algorithms: { | ||
207 | enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ], | ||
208 | default: 'hot' | ||
209 | } | ||
210 | } | ||
211 | }, | ||
212 | autoBlacklist: { | ||
213 | videos: { | ||
214 | ofUsers: { | ||
215 | enabled: false | ||
216 | } | ||
217 | } | ||
218 | }, | ||
219 | followers: { | ||
220 | instance: { | ||
221 | enabled: true, | ||
222 | manualApproval: false | ||
223 | } | ||
224 | }, | ||
225 | followings: { | ||
226 | instance: { | ||
227 | autoFollowBack: { | ||
228 | enabled: false | ||
229 | }, | ||
230 | autoFollowIndex: { | ||
231 | indexUrl: 'https://instances.joinpeertube.org/api/v1/instances/hosts', | ||
232 | enabled: false | ||
233 | } | ||
234 | } | ||
235 | }, | ||
236 | broadcastMessage: { | ||
237 | enabled: true, | ||
238 | level: 'warning', | ||
239 | message: 'hello', | ||
240 | dismissable: true | ||
241 | }, | ||
242 | search: { | ||
243 | remoteUri: { | ||
244 | users: true, | ||
245 | anonymous: true | ||
246 | }, | ||
247 | searchIndex: { | ||
248 | enabled: true, | ||
249 | url: 'https://search.joinpeertube.org', | ||
250 | disableLocalSearch: true, | ||
251 | isDefaultSearch: true | ||
252 | } | ||
253 | } | ||
254 | } | ||
255 | |||
256 | merge(newCustomConfig, options.newConfig) | ||
257 | |||
258 | return this.updateCustomConfig({ ...options, newCustomConfig }) | ||
259 | } | ||
260 | } | ||
diff --git a/shared/extra-utils/server/config.ts b/shared/extra-utils/server/config.ts deleted file mode 100644 index 9fcfb31fd..000000000 --- a/shared/extra-utils/server/config.ts +++ /dev/null | |||
@@ -1,260 +0,0 @@ | |||
1 | import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../requests/requests' | ||
2 | import { CustomConfig } from '../../models/server/custom-config.model' | ||
3 | import { DeepPartial, HttpStatusCode } from '@shared/core-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: HttpStatusCode.OK_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: HttpStatusCode.OK_200 | ||
23 | }) | ||
24 | } | ||
25 | |||
26 | function getCustomConfig (url: string, token: string, statusCodeExpected = HttpStatusCode.OK_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 = HttpStatusCode.OK_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 | hardwareInformation: '2vCore 3GB RAM', | ||
64 | |||
65 | languages: [ 'en', 'es' ], | ||
66 | categories: [ 1, 2 ], | ||
67 | |||
68 | isNSFW: true, | ||
69 | defaultNSFWPolicy: 'blur', | ||
70 | |||
71 | defaultClientRoute: '/videos/recently-added', | ||
72 | |||
73 | customizations: { | ||
74 | javascript: 'alert("coucou")', | ||
75 | css: 'body { background-color: red; }' | ||
76 | } | ||
77 | }, | ||
78 | theme: { | ||
79 | default: 'default' | ||
80 | }, | ||
81 | services: { | ||
82 | twitter: { | ||
83 | username: '@MySuperUsername', | ||
84 | whitelisted: true | ||
85 | } | ||
86 | }, | ||
87 | cache: { | ||
88 | previews: { | ||
89 | size: 2 | ||
90 | }, | ||
91 | captions: { | ||
92 | size: 3 | ||
93 | }, | ||
94 | torrents: { | ||
95 | size: 4 | ||
96 | } | ||
97 | }, | ||
98 | signup: { | ||
99 | enabled: false, | ||
100 | limit: 5, | ||
101 | requiresEmailVerification: false, | ||
102 | minimumAge: 16 | ||
103 | }, | ||
104 | admin: { | ||
105 | email: 'superadmin1@example.com' | ||
106 | }, | ||
107 | contactForm: { | ||
108 | enabled: true | ||
109 | }, | ||
110 | user: { | ||
111 | videoQuota: 5242881, | ||
112 | videoQuotaDaily: 318742 | ||
113 | }, | ||
114 | transcoding: { | ||
115 | enabled: true, | ||
116 | allowAdditionalExtensions: true, | ||
117 | allowAudioFiles: true, | ||
118 | threads: 1, | ||
119 | concurrency: 3, | ||
120 | profile: 'default', | ||
121 | resolutions: { | ||
122 | '0p': false, | ||
123 | '240p': false, | ||
124 | '360p': true, | ||
125 | '480p': true, | ||
126 | '720p': false, | ||
127 | '1080p': false, | ||
128 | '1440p': false, | ||
129 | '2160p': false | ||
130 | }, | ||
131 | webtorrent: { | ||
132 | enabled: true | ||
133 | }, | ||
134 | hls: { | ||
135 | enabled: false | ||
136 | } | ||
137 | }, | ||
138 | live: { | ||
139 | enabled: true, | ||
140 | allowReplay: false, | ||
141 | maxDuration: -1, | ||
142 | maxInstanceLives: -1, | ||
143 | maxUserLives: 50, | ||
144 | transcoding: { | ||
145 | enabled: true, | ||
146 | threads: 4, | ||
147 | profile: 'default', | ||
148 | resolutions: { | ||
149 | '240p': true, | ||
150 | '360p': true, | ||
151 | '480p': true, | ||
152 | '720p': true, | ||
153 | '1080p': true, | ||
154 | '1440p': true, | ||
155 | '2160p': true | ||
156 | } | ||
157 | } | ||
158 | }, | ||
159 | import: { | ||
160 | videos: { | ||
161 | concurrency: 3, | ||
162 | http: { | ||
163 | enabled: false | ||
164 | }, | ||
165 | torrent: { | ||
166 | enabled: false | ||
167 | } | ||
168 | } | ||
169 | }, | ||
170 | trending: { | ||
171 | videos: { | ||
172 | algorithms: { | ||
173 | enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ], | ||
174 | default: 'hot' | ||
175 | } | ||
176 | } | ||
177 | }, | ||
178 | autoBlacklist: { | ||
179 | videos: { | ||
180 | ofUsers: { | ||
181 | enabled: false | ||
182 | } | ||
183 | } | ||
184 | }, | ||
185 | followers: { | ||
186 | instance: { | ||
187 | enabled: true, | ||
188 | manualApproval: false | ||
189 | } | ||
190 | }, | ||
191 | followings: { | ||
192 | instance: { | ||
193 | autoFollowBack: { | ||
194 | enabled: false | ||
195 | }, | ||
196 | autoFollowIndex: { | ||
197 | indexUrl: 'https://instances.joinpeertube.org/api/v1/instances/hosts', | ||
198 | enabled: false | ||
199 | } | ||
200 | } | ||
201 | }, | ||
202 | broadcastMessage: { | ||
203 | enabled: true, | ||
204 | level: 'warning', | ||
205 | message: 'hello', | ||
206 | dismissable: true | ||
207 | }, | ||
208 | search: { | ||
209 | remoteUri: { | ||
210 | users: true, | ||
211 | anonymous: true | ||
212 | }, | ||
213 | searchIndex: { | ||
214 | enabled: true, | ||
215 | url: 'https://search.joinpeertube.org', | ||
216 | disableLocalSearch: true, | ||
217 | isDefaultSearch: true | ||
218 | } | ||
219 | } | ||
220 | } | ||
221 | |||
222 | merge(updateParams, newConfig) | ||
223 | |||
224 | return updateCustomConfig(url, token, updateParams) | ||
225 | } | ||
226 | |||
227 | function getCustomConfigResolutions (enabled: boolean) { | ||
228 | return { | ||
229 | '240p': enabled, | ||
230 | '360p': enabled, | ||
231 | '480p': enabled, | ||
232 | '720p': enabled, | ||
233 | '1080p': enabled, | ||
234 | '1440p': enabled, | ||
235 | '2160p': enabled | ||
236 | } | ||
237 | } | ||
238 | |||
239 | function deleteCustomConfig (url: string, token: string, statusCodeExpected = HttpStatusCode.OK_200) { | ||
240 | const path = '/api/v1/config/custom' | ||
241 | |||
242 | return makeDeleteRequest({ | ||
243 | url, | ||
244 | token, | ||
245 | path, | ||
246 | statusCodeExpected | ||
247 | }) | ||
248 | } | ||
249 | |||
250 | // --------------------------------------------------------------------------- | ||
251 | |||
252 | export { | ||
253 | getConfig, | ||
254 | getCustomConfig, | ||
255 | updateCustomConfig, | ||
256 | getAbout, | ||
257 | deleteCustomConfig, | ||
258 | updateCustomSubConfig, | ||
259 | getCustomConfigResolutions | ||
260 | } | ||
diff --git a/shared/extra-utils/server/index.ts b/shared/extra-utils/server/index.ts index d37f46321..03c3b0123 100644 --- a/shared/extra-utils/server/index.ts +++ b/shared/extra-utils/server/index.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | export * from './config' | 1 | export * from './config-command' |
2 | export * from './contact-form-command' | 2 | export * from './contact-form-command' |
3 | export * from './debug-command' | 3 | export * from './debug-command' |
4 | export * from './follows-command' | 4 | export * from './follows-command' |
diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index 4603cf62e..c33b68316 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts | |||
@@ -16,6 +16,7 @@ import { AbusesCommand } from '../moderation' | |||
16 | import { OverviewsCommand } from '../overviews' | 16 | import { OverviewsCommand } from '../overviews' |
17 | import { makeGetRequest } from '../requests/requests' | 17 | import { makeGetRequest } from '../requests/requests' |
18 | import { SearchCommand } from '../search' | 18 | import { SearchCommand } from '../search' |
19 | import { ConfigCommand } from './config-command' | ||
19 | import { ContactFormCommand } from './contact-form-command' | 20 | import { ContactFormCommand } from './contact-form-command' |
20 | import { DebugCommand } from './debug-command' | 21 | import { DebugCommand } from './debug-command' |
21 | import { FollowsCommand } from './follows-command' | 22 | import { FollowsCommand } from './follows-command' |
@@ -91,6 +92,7 @@ interface ServerInfo { | |||
91 | pluginsCommand?: PluginsCommand | 92 | pluginsCommand?: PluginsCommand |
92 | redundancyCommand?: RedundancyCommand | 93 | redundancyCommand?: RedundancyCommand |
93 | statsCommand?: StatsCommand | 94 | statsCommand?: StatsCommand |
95 | configCommand?: ConfigCommand | ||
94 | } | 96 | } |
95 | 97 | ||
96 | function parallelTests () { | 98 | function parallelTests () { |
@@ -311,6 +313,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] | |||
311 | server.pluginsCommand = new PluginsCommand(server) | 313 | server.pluginsCommand = new PluginsCommand(server) |
312 | server.redundancyCommand = new RedundancyCommand(server) | 314 | server.redundancyCommand = new RedundancyCommand(server) |
313 | server.statsCommand = new StatsCommand(server) | 315 | server.statsCommand = new StatsCommand(server) |
316 | server.configCommand = new ConfigCommand(server) | ||
314 | 317 | ||
315 | res(server) | 318 | res(server) |
316 | }) | 319 | }) |