]>
Commit | Line | Data |
---|---|---|
65e6e260 C |
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 | } |