diff options
Diffstat (limited to 'server/controllers/api/config.ts')
-rw-r--r-- | server/controllers/api/config.ts | 91 |
1 files changed, 67 insertions, 24 deletions
diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts index ae4e00248..edcb0b99e 100644 --- a/server/controllers/api/config.ts +++ b/server/controllers/api/config.ts | |||
@@ -1,23 +1,22 @@ | |||
1 | import { Hooks } from '@server/lib/plugins/hooks' | ||
1 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import { remove, writeJSON } from 'fs-extra' | ||
2 | import { snakeCase } from 'lodash' | 4 | import { snakeCase } from 'lodash' |
3 | import { ServerConfig, UserRight } from '../../../shared' | 5 | import validator from 'validator' |
6 | import { RegisteredExternalAuthConfig, RegisteredIdAndPassAuthConfig, ServerConfig, UserRight } from '../../../shared' | ||
4 | import { About } from '../../../shared/models/server/about.model' | 7 | import { About } from '../../../shared/models/server/about.model' |
5 | 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' | ||
10 | import { objectConverter } from '../../helpers/core-utils' | ||
6 | import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/signup' | 11 | import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/signup' |
12 | import { getServerCommit } from '../../helpers/utils' | ||
13 | import { CONFIG, isEmailEnabled, reloadConfig } from '../../initializers/config' | ||
7 | import { CONSTRAINTS_FIELDS, DEFAULT_THEME_NAME, PEERTUBE_VERSION } from '../../initializers/constants' | 14 | import { CONSTRAINTS_FIELDS, DEFAULT_THEME_NAME, PEERTUBE_VERSION } from '../../initializers/constants' |
8 | import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares' | ||
9 | import { customConfigUpdateValidator } from '../../middlewares/validators/config' | ||
10 | import { ClientHtml } from '../../lib/client-html' | 15 | import { ClientHtml } from '../../lib/client-html' |
11 | import { auditLoggerFactory, CustomConfigAuditView, getAuditIdFromRes } from '../../helpers/audit-logger' | ||
12 | import { remove, writeJSON } from 'fs-extra' | ||
13 | import { getServerCommit } from '../../helpers/utils' | ||
14 | import { Emailer } from '../../lib/emailer' | ||
15 | import validator from 'validator' | ||
16 | import { objectConverter } from '../../helpers/core-utils' | ||
17 | import { CONFIG, reloadConfig } from '../../initializers/config' | ||
18 | import { PluginManager } from '../../lib/plugins/plugin-manager' | 16 | import { PluginManager } from '../../lib/plugins/plugin-manager' |
19 | import { getThemeOrDefault } from '../../lib/plugins/theme-utils' | 17 | import { getThemeOrDefault } from '../../lib/plugins/theme-utils' |
20 | import { Hooks } from '@server/lib/plugins/hooks' | 18 | import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares' |
19 | import { customConfigUpdateValidator } from '../../middlewares/validators/config' | ||
21 | 20 | ||
22 | const configRouter = express.Router() | 21 | const configRouter = express.Router() |
23 | 22 | ||
@@ -31,12 +30,12 @@ configRouter.get('/', | |||
31 | configRouter.get('/custom', | 30 | configRouter.get('/custom', |
32 | authenticate, | 31 | authenticate, |
33 | ensureUserHasRight(UserRight.MANAGE_CONFIGURATION), | 32 | ensureUserHasRight(UserRight.MANAGE_CONFIGURATION), |
34 | asyncMiddleware(getCustomConfig) | 33 | getCustomConfig |
35 | ) | 34 | ) |
36 | configRouter.put('/custom', | 35 | configRouter.put('/custom', |
37 | authenticate, | 36 | authenticate, |
38 | ensureUserHasRight(UserRight.MANAGE_CONFIGURATION), | 37 | ensureUserHasRight(UserRight.MANAGE_CONFIGURATION), |
39 | asyncMiddleware(customConfigUpdateValidator), | 38 | customConfigUpdateValidator, |
40 | asyncMiddleware(updateCustomConfig) | 39 | asyncMiddleware(updateCustomConfig) |
41 | ) | 40 | ) |
42 | configRouter.delete('/custom', | 41 | configRouter.delete('/custom', |
@@ -73,15 +72,23 @@ async function getConfig (req: express.Request, res: express.Response) { | |||
73 | css: CONFIG.INSTANCE.CUSTOMIZATIONS.CSS | 72 | css: CONFIG.INSTANCE.CUSTOMIZATIONS.CSS |
74 | } | 73 | } |
75 | }, | 74 | }, |
75 | search: { | ||
76 | remoteUri: { | ||
77 | users: CONFIG.SEARCH.REMOTE_URI.USERS, | ||
78 | anonymous: CONFIG.SEARCH.REMOTE_URI.ANONYMOUS | ||
79 | } | ||
80 | }, | ||
76 | plugin: { | 81 | plugin: { |
77 | registered: getRegisteredPlugins() | 82 | registered: getRegisteredPlugins(), |
83 | registeredExternalAuths: getExternalAuthsPlugins(), | ||
84 | registeredIdAndPassAuths: getIdAndPassAuthPlugins() | ||
78 | }, | 85 | }, |
79 | theme: { | 86 | theme: { |
80 | registered: getRegisteredThemes(), | 87 | registered: getRegisteredThemes(), |
81 | default: defaultTheme | 88 | default: defaultTheme |
82 | }, | 89 | }, |
83 | email: { | 90 | email: { |
84 | enabled: Emailer.isEnabled() | 91 | enabled: isEmailEnabled() |
85 | }, | 92 | }, |
86 | contactForm: { | 93 | contactForm: { |
87 | enabled: CONFIG.CONTACT_FORM.ENABLED | 94 | enabled: CONFIG.CONTACT_FORM.ENABLED |
@@ -196,7 +203,7 @@ function getAbout (req: express.Request, res: express.Response) { | |||
196 | return res.json(about).end() | 203 | return res.json(about).end() |
197 | } | 204 | } |
198 | 205 | ||
199 | async function getCustomConfig (req: express.Request, res: express.Response) { | 206 | function getCustomConfig (req: express.Request, res: express.Response) { |
200 | const data = customConfig() | 207 | const data = customConfig() |
201 | 208 | ||
202 | return res.json(data).end() | 209 | return res.json(data).end() |
@@ -250,7 +257,7 @@ function getRegisteredThemes () { | |||
250 | 257 | ||
251 | function getEnabledResolutions () { | 258 | function getEnabledResolutions () { |
252 | return Object.keys(CONFIG.TRANSCODING.RESOLUTIONS) | 259 | return Object.keys(CONFIG.TRANSCODING.RESOLUTIONS) |
253 | .filter(key => CONFIG.TRANSCODING.ENABLED && CONFIG.TRANSCODING.RESOLUTIONS[ key ] === true) | 260 | .filter(key => CONFIG.TRANSCODING.ENABLED && CONFIG.TRANSCODING.RESOLUTIONS[key] === true) |
254 | .map(r => parseInt(r, 10)) | 261 | .map(r => parseInt(r, 10)) |
255 | } | 262 | } |
256 | 263 | ||
@@ -264,6 +271,42 @@ function getRegisteredPlugins () { | |||
264 | })) | 271 | })) |
265 | } | 272 | } |
266 | 273 | ||
274 | function getIdAndPassAuthPlugins () { | ||
275 | const result: RegisteredIdAndPassAuthConfig[] = [] | ||
276 | |||
277 | for (const p of PluginManager.Instance.getIdAndPassAuths()) { | ||
278 | for (const auth of p.idAndPassAuths) { | ||
279 | result.push({ | ||
280 | npmName: p.npmName, | ||
281 | name: p.name, | ||
282 | version: p.version, | ||
283 | authName: auth.authName, | ||
284 | weight: auth.getWeight() | ||
285 | }) | ||
286 | } | ||
287 | } | ||
288 | |||
289 | return result | ||
290 | } | ||
291 | |||
292 | function getExternalAuthsPlugins () { | ||
293 | const result: RegisteredExternalAuthConfig[] = [] | ||
294 | |||
295 | for (const p of PluginManager.Instance.getExternalAuths()) { | ||
296 | for (const auth of p.externalAuths) { | ||
297 | result.push({ | ||
298 | npmName: p.npmName, | ||
299 | name: p.name, | ||
300 | version: p.version, | ||
301 | authName: auth.authName, | ||
302 | authDisplayName: auth.authDisplayName() | ||
303 | }) | ||
304 | } | ||
305 | } | ||
306 | |||
307 | return result | ||
308 | } | ||
309 | |||
267 | // --------------------------------------------------------------------------- | 310 | // --------------------------------------------------------------------------- |
268 | 311 | ||
269 | export { | 312 | export { |
@@ -340,13 +383,13 @@ function customConfig (): CustomConfig { | |||
340 | allowAudioFiles: CONFIG.TRANSCODING.ALLOW_AUDIO_FILES, | 383 | allowAudioFiles: CONFIG.TRANSCODING.ALLOW_AUDIO_FILES, |
341 | threads: CONFIG.TRANSCODING.THREADS, | 384 | threads: CONFIG.TRANSCODING.THREADS, |
342 | resolutions: { | 385 | resolutions: { |
343 | '0p': CONFIG.TRANSCODING.RESOLUTIONS[ '0p' ], | 386 | '0p': CONFIG.TRANSCODING.RESOLUTIONS['0p'], |
344 | '240p': CONFIG.TRANSCODING.RESOLUTIONS[ '240p' ], | 387 | '240p': CONFIG.TRANSCODING.RESOLUTIONS['240p'], |
345 | '360p': CONFIG.TRANSCODING.RESOLUTIONS[ '360p' ], | 388 | '360p': CONFIG.TRANSCODING.RESOLUTIONS['360p'], |
346 | '480p': CONFIG.TRANSCODING.RESOLUTIONS[ '480p' ], | 389 | '480p': CONFIG.TRANSCODING.RESOLUTIONS['480p'], |
347 | '720p': CONFIG.TRANSCODING.RESOLUTIONS[ '720p' ], | 390 | '720p': CONFIG.TRANSCODING.RESOLUTIONS['720p'], |
348 | '1080p': CONFIG.TRANSCODING.RESOLUTIONS[ '1080p' ], | 391 | '1080p': CONFIG.TRANSCODING.RESOLUTIONS['1080p'], |
349 | '2160p': CONFIG.TRANSCODING.RESOLUTIONS[ '2160p' ] | 392 | '2160p': CONFIG.TRANSCODING.RESOLUTIONS['2160p'] |
350 | }, | 393 | }, |
351 | webtorrent: { | 394 | webtorrent: { |
352 | enabled: CONFIG.TRANSCODING.WEBTORRENT.ENABLED | 395 | enabled: CONFIG.TRANSCODING.WEBTORRENT.ENABLED |