diff options
Diffstat (limited to 'server/controllers/api/config.ts')
-rw-r--r-- | server/controllers/api/config.ts | 250 |
1 files changed, 5 insertions, 245 deletions
diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts index e28f7502d..2ddb73519 100644 --- a/server/controllers/api/config.ts +++ b/server/controllers/api/config.ts | |||
@@ -1,24 +1,17 @@ | |||
1 | import { Hooks } from '@server/lib/plugins/hooks' | ||
2 | import * as express from 'express' | 1 | import * as express from 'express' |
3 | import { remove, writeJSON } from 'fs-extra' | 2 | import { remove, writeJSON } from 'fs-extra' |
4 | import { snakeCase } from 'lodash' | 3 | import { snakeCase } from 'lodash' |
5 | import validator from 'validator' | 4 | import validator from 'validator' |
6 | import { RegisteredExternalAuthConfig, RegisteredIdAndPassAuthConfig, ServerConfig, UserRight } from '../../../shared' | 5 | import { getServerConfig } from '@server/lib/config' |
6 | import { UserRight } from '../../../shared' | ||
7 | import { About } from '../../../shared/models/server/about.model' | 7 | import { About } from '../../../shared/models/server/about.model' |
8 | import { CustomConfig } from '../../../shared/models/server/custom-config.model' | 8 | import { CustomConfig } from '../../../shared/models/server/custom-config.model' |
9 | import { auditLoggerFactory, CustomConfigAuditView, getAuditIdFromRes } from '../../helpers/audit-logger' | 9 | import { auditLoggerFactory, CustomConfigAuditView, getAuditIdFromRes } from '../../helpers/audit-logger' |
10 | import { objectConverter } from '../../helpers/core-utils' | 10 | import { objectConverter } from '../../helpers/core-utils' |
11 | import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/signup' | 11 | import { CONFIG, reloadConfig } from '../../initializers/config' |
12 | import { getServerCommit } from '../../helpers/utils' | ||
13 | import { getEnabledResolutions } from '../../lib/video-transcoding' | ||
14 | import { CONFIG, isEmailEnabled, reloadConfig } from '../../initializers/config' | ||
15 | import { CONSTRAINTS_FIELDS, DEFAULT_THEME_NAME, PEERTUBE_VERSION } from '../../initializers/constants' | ||
16 | import { ClientHtml } from '../../lib/client-html' | 12 | import { ClientHtml } from '../../lib/client-html' |
17 | import { PluginManager } from '../../lib/plugins/plugin-manager' | ||
18 | import { getThemeOrDefault } from '../../lib/plugins/theme-utils' | ||
19 | import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares' | 13 | import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares' |
20 | import { customConfigUpdateValidator } from '../../middlewares/validators/config' | 14 | import { customConfigUpdateValidator } from '../../middlewares/validators/config' |
21 | import { VideoTranscodingProfilesManager } from '@server/lib/video-transcoding-profiles' | ||
22 | 15 | ||
23 | const configRouter = express.Router() | 16 | const configRouter = express.Router() |
24 | 17 | ||
@@ -46,182 +39,8 @@ configRouter.delete('/custom', | |||
46 | asyncMiddleware(deleteCustomConfig) | 39 | asyncMiddleware(deleteCustomConfig) |
47 | ) | 40 | ) |
48 | 41 | ||
49 | let serverCommit: string | ||
50 | |||
51 | async function getConfig (req: express.Request, res: express.Response) { | 42 | async function getConfig (req: express.Request, res: express.Response) { |
52 | const { allowed } = await Hooks.wrapPromiseFun( | 43 | const json = await getServerConfig(req.ip) |
53 | isSignupAllowed, | ||
54 | { | ||
55 | ip: req.ip | ||
56 | }, | ||
57 | 'filter:api.user.signup.allowed.result' | ||
58 | ) | ||
59 | |||
60 | const allowedForCurrentIP = isSignupAllowedForCurrentIP(req.ip) | ||
61 | const defaultTheme = getThemeOrDefault(CONFIG.THEME.DEFAULT, DEFAULT_THEME_NAME) | ||
62 | |||
63 | if (serverCommit === undefined) serverCommit = await getServerCommit() | ||
64 | |||
65 | const json: ServerConfig = { | ||
66 | instance: { | ||
67 | name: CONFIG.INSTANCE.NAME, | ||
68 | shortDescription: CONFIG.INSTANCE.SHORT_DESCRIPTION, | ||
69 | isNSFW: CONFIG.INSTANCE.IS_NSFW, | ||
70 | defaultNSFWPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, | ||
71 | defaultClientRoute: CONFIG.INSTANCE.DEFAULT_CLIENT_ROUTE, | ||
72 | customizations: { | ||
73 | javascript: CONFIG.INSTANCE.CUSTOMIZATIONS.JAVASCRIPT, | ||
74 | css: CONFIG.INSTANCE.CUSTOMIZATIONS.CSS | ||
75 | } | ||
76 | }, | ||
77 | search: { | ||
78 | remoteUri: { | ||
79 | users: CONFIG.SEARCH.REMOTE_URI.USERS, | ||
80 | anonymous: CONFIG.SEARCH.REMOTE_URI.ANONYMOUS | ||
81 | }, | ||
82 | searchIndex: { | ||
83 | enabled: CONFIG.SEARCH.SEARCH_INDEX.ENABLED, | ||
84 | url: CONFIG.SEARCH.SEARCH_INDEX.URL, | ||
85 | disableLocalSearch: CONFIG.SEARCH.SEARCH_INDEX.DISABLE_LOCAL_SEARCH, | ||
86 | isDefaultSearch: CONFIG.SEARCH.SEARCH_INDEX.IS_DEFAULT_SEARCH | ||
87 | } | ||
88 | }, | ||
89 | plugin: { | ||
90 | registered: getRegisteredPlugins(), | ||
91 | registeredExternalAuths: getExternalAuthsPlugins(), | ||
92 | registeredIdAndPassAuths: getIdAndPassAuthPlugins() | ||
93 | }, | ||
94 | theme: { | ||
95 | registered: getRegisteredThemes(), | ||
96 | default: defaultTheme | ||
97 | }, | ||
98 | email: { | ||
99 | enabled: isEmailEnabled() | ||
100 | }, | ||
101 | contactForm: { | ||
102 | enabled: CONFIG.CONTACT_FORM.ENABLED | ||
103 | }, | ||
104 | serverVersion: PEERTUBE_VERSION, | ||
105 | serverCommit, | ||
106 | signup: { | ||
107 | allowed, | ||
108 | allowedForCurrentIP, | ||
109 | requiresEmailVerification: CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION | ||
110 | }, | ||
111 | transcoding: { | ||
112 | hls: { | ||
113 | enabled: CONFIG.TRANSCODING.HLS.ENABLED | ||
114 | }, | ||
115 | webtorrent: { | ||
116 | enabled: CONFIG.TRANSCODING.WEBTORRENT.ENABLED | ||
117 | }, | ||
118 | enabledResolutions: getEnabledResolutions('vod'), | ||
119 | profile: CONFIG.TRANSCODING.PROFILE, | ||
120 | availableProfiles: VideoTranscodingProfilesManager.Instance.getAvailableProfiles('vod') | ||
121 | }, | ||
122 | live: { | ||
123 | enabled: CONFIG.LIVE.ENABLED, | ||
124 | |||
125 | allowReplay: CONFIG.LIVE.ALLOW_REPLAY, | ||
126 | maxDuration: CONFIG.LIVE.MAX_DURATION, | ||
127 | maxInstanceLives: CONFIG.LIVE.MAX_INSTANCE_LIVES, | ||
128 | maxUserLives: CONFIG.LIVE.MAX_USER_LIVES, | ||
129 | |||
130 | transcoding: { | ||
131 | enabled: CONFIG.LIVE.TRANSCODING.ENABLED, | ||
132 | enabledResolutions: getEnabledResolutions('live'), | ||
133 | profile: CONFIG.LIVE.TRANSCODING.PROFILE, | ||
134 | availableProfiles: VideoTranscodingProfilesManager.Instance.getAvailableProfiles('live') | ||
135 | }, | ||
136 | |||
137 | rtmp: { | ||
138 | port: CONFIG.LIVE.RTMP.PORT | ||
139 | } | ||
140 | }, | ||
141 | import: { | ||
142 | videos: { | ||
143 | http: { | ||
144 | enabled: CONFIG.IMPORT.VIDEOS.HTTP.ENABLED | ||
145 | }, | ||
146 | torrent: { | ||
147 | enabled: CONFIG.IMPORT.VIDEOS.TORRENT.ENABLED | ||
148 | } | ||
149 | } | ||
150 | }, | ||
151 | autoBlacklist: { | ||
152 | videos: { | ||
153 | ofUsers: { | ||
154 | enabled: CONFIG.AUTO_BLACKLIST.VIDEOS.OF_USERS.ENABLED | ||
155 | } | ||
156 | } | ||
157 | }, | ||
158 | avatar: { | ||
159 | file: { | ||
160 | size: { | ||
161 | max: CONSTRAINTS_FIELDS.ACTORS.IMAGE.FILE_SIZE.max | ||
162 | }, | ||
163 | extensions: CONSTRAINTS_FIELDS.ACTORS.IMAGE.EXTNAME | ||
164 | } | ||
165 | }, | ||
166 | banner: { | ||
167 | file: { | ||
168 | size: { | ||
169 | max: CONSTRAINTS_FIELDS.ACTORS.IMAGE.FILE_SIZE.max | ||
170 | }, | ||
171 | extensions: CONSTRAINTS_FIELDS.ACTORS.IMAGE.EXTNAME | ||
172 | } | ||
173 | }, | ||
174 | video: { | ||
175 | image: { | ||
176 | extensions: CONSTRAINTS_FIELDS.VIDEOS.IMAGE.EXTNAME, | ||
177 | size: { | ||
178 | max: CONSTRAINTS_FIELDS.VIDEOS.IMAGE.FILE_SIZE.max | ||
179 | } | ||
180 | }, | ||
181 | file: { | ||
182 | extensions: CONSTRAINTS_FIELDS.VIDEOS.EXTNAME | ||
183 | } | ||
184 | }, | ||
185 | videoCaption: { | ||
186 | file: { | ||
187 | size: { | ||
188 | max: CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max | ||
189 | }, | ||
190 | extensions: CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.EXTNAME | ||
191 | } | ||
192 | }, | ||
193 | user: { | ||
194 | videoQuota: CONFIG.USER.VIDEO_QUOTA, | ||
195 | videoQuotaDaily: CONFIG.USER.VIDEO_QUOTA_DAILY | ||
196 | }, | ||
197 | trending: { | ||
198 | videos: { | ||
199 | intervalDays: CONFIG.TRENDING.VIDEOS.INTERVAL_DAYS, | ||
200 | algorithms: { | ||
201 | enabled: CONFIG.TRENDING.VIDEOS.ALGORITHMS.ENABLED, | ||
202 | default: CONFIG.TRENDING.VIDEOS.ALGORITHMS.DEFAULT | ||
203 | } | ||
204 | } | ||
205 | }, | ||
206 | tracker: { | ||
207 | enabled: CONFIG.TRACKER.ENABLED | ||
208 | }, | ||
209 | |||
210 | followings: { | ||
211 | instance: { | ||
212 | autoFollowIndex: { | ||
213 | indexUrl: CONFIG.FOLLOWINGS.INSTANCE.AUTO_FOLLOW_INDEX.INDEX_URL | ||
214 | } | ||
215 | } | ||
216 | }, | ||
217 | |||
218 | broadcastMessage: { | ||
219 | enabled: CONFIG.BROADCAST_MESSAGE.ENABLED, | ||
220 | message: CONFIG.BROADCAST_MESSAGE.MESSAGE, | ||
221 | level: CONFIG.BROADCAST_MESSAGE.LEVEL, | ||
222 | dismissable: CONFIG.BROADCAST_MESSAGE.DISMISSABLE | ||
223 | } | ||
224 | } | ||
225 | 44 | ||
226 | return res.json(json) | 45 | return res.json(json) |
227 | } | 46 | } |
@@ -292,69 +111,10 @@ async function updateCustomConfig (req: express.Request, res: express.Response) | |||
292 | return res.json(data) | 111 | return res.json(data) |
293 | } | 112 | } |
294 | 113 | ||
295 | function getRegisteredThemes () { | ||
296 | return PluginManager.Instance.getRegisteredThemes() | ||
297 | .map(t => ({ | ||
298 | name: t.name, | ||
299 | version: t.version, | ||
300 | description: t.description, | ||
301 | css: t.css, | ||
302 | clientScripts: t.clientScripts | ||
303 | })) | ||
304 | } | ||
305 | |||
306 | function getRegisteredPlugins () { | ||
307 | return PluginManager.Instance.getRegisteredPlugins() | ||
308 | .map(p => ({ | ||
309 | name: p.name, | ||
310 | version: p.version, | ||
311 | description: p.description, | ||
312 | clientScripts: p.clientScripts | ||
313 | })) | ||
314 | } | ||
315 | |||
316 | function getIdAndPassAuthPlugins () { | ||
317 | const result: RegisteredIdAndPassAuthConfig[] = [] | ||
318 | |||
319 | for (const p of PluginManager.Instance.getIdAndPassAuths()) { | ||
320 | for (const auth of p.idAndPassAuths) { | ||
321 | result.push({ | ||
322 | npmName: p.npmName, | ||
323 | name: p.name, | ||
324 | version: p.version, | ||
325 | authName: auth.authName, | ||
326 | weight: auth.getWeight() | ||
327 | }) | ||
328 | } | ||
329 | } | ||
330 | |||
331 | return result | ||
332 | } | ||
333 | |||
334 | function getExternalAuthsPlugins () { | ||
335 | const result: RegisteredExternalAuthConfig[] = [] | ||
336 | |||
337 | for (const p of PluginManager.Instance.getExternalAuths()) { | ||
338 | for (const auth of p.externalAuths) { | ||
339 | result.push({ | ||
340 | npmName: p.npmName, | ||
341 | name: p.name, | ||
342 | version: p.version, | ||
343 | authName: auth.authName, | ||
344 | authDisplayName: auth.authDisplayName() | ||
345 | }) | ||
346 | } | ||
347 | } | ||
348 | |||
349 | return result | ||
350 | } | ||
351 | |||
352 | // --------------------------------------------------------------------------- | 114 | // --------------------------------------------------------------------------- |
353 | 115 | ||
354 | export { | 116 | export { |
355 | configRouter, | 117 | configRouter |
356 | getRegisteredPlugins, | ||
357 | getRegisteredThemes | ||
358 | } | 118 | } |
359 | 119 | ||
360 | // --------------------------------------------------------------------------- | 120 | // --------------------------------------------------------------------------- |