diff options
author | Chocobozzz <me@florianbigard.com> | 2019-07-17 10:03:55 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-07-24 10:58:16 +0200 |
commit | 66170ca8c64fa4e76f3830e4a02a11345a03093b (patch) | |
tree | d2ef070a8e3cc98badcf6492f4d7db345c157d91 /server/controllers/api/config.ts | |
parent | 109d893ff5353c3061af3062cf9443bcba39aafc (diff) | |
download | PeerTube-66170ca8c64fa4e76f3830e4a02a11345a03093b.tar.gz PeerTube-66170ca8c64fa4e76f3830e4a02a11345a03093b.tar.zst PeerTube-66170ca8c64fa4e76f3830e4a02a11345a03093b.zip |
Use process.env.npm_package_version
Diffstat (limited to 'server/controllers/api/config.ts')
-rw-r--r-- | server/controllers/api/config.ts | 63 |
1 files changed, 34 insertions, 29 deletions
diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts index 81518bbb5..21fa85a08 100644 --- a/server/controllers/api/config.ts +++ b/server/controllers/api/config.ts | |||
@@ -4,7 +4,7 @@ import { ServerConfig, UserRight } from '../../../shared' | |||
4 | import { About } from '../../../shared/models/server/about.model' | 4 | import { About } from '../../../shared/models/server/about.model' |
5 | import { CustomConfig } from '../../../shared/models/server/custom-config.model' | 5 | import { CustomConfig } from '../../../shared/models/server/custom-config.model' |
6 | import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/signup' | 6 | import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/signup' |
7 | import { CONSTRAINTS_FIELDS, DEFAULT_THEME_NAME } from '../../initializers/constants' | 7 | import { CONSTRAINTS_FIELDS, DEFAULT_THEME_NAME, PEERTUBE_VERSION } from '../../initializers/constants' |
8 | import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares' | 8 | import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares' |
9 | import { customConfigUpdateValidator } from '../../middlewares/validators/config' | 9 | import { customConfigUpdateValidator } from '../../middlewares/validators/config' |
10 | import { ClientHtml } from '../../lib/client-html' | 10 | import { ClientHtml } from '../../lib/client-html' |
@@ -18,7 +18,6 @@ import { CONFIG, reloadConfig } from '../../initializers/config' | |||
18 | import { PluginManager } from '../../lib/plugins/plugin-manager' | 18 | import { PluginManager } from '../../lib/plugins/plugin-manager' |
19 | import { getThemeOrDefault } from '../../lib/plugins/theme-utils' | 19 | import { getThemeOrDefault } from '../../lib/plugins/theme-utils' |
20 | 20 | ||
21 | const packageJSON = require('../../../../package.json') | ||
22 | const configRouter = express.Router() | 21 | const configRouter = express.Router() |
23 | 22 | ||
24 | const auditLogger = auditLoggerFactory('config') | 23 | const auditLogger = auditLoggerFactory('config') |
@@ -46,35 +45,14 @@ configRouter.delete('/custom', | |||
46 | ) | 45 | ) |
47 | 46 | ||
48 | let serverCommit: string | 47 | let serverCommit: string |
48 | |||
49 | async function getConfig (req: express.Request, res: express.Response) { | 49 | async function getConfig (req: express.Request, res: express.Response) { |
50 | const allowed = await isSignupAllowed() | 50 | const allowed = await isSignupAllowed() |
51 | const allowedForCurrentIP = isSignupAllowedForCurrentIP(req.ip) | 51 | const allowedForCurrentIP = isSignupAllowedForCurrentIP(req.ip) |
52 | const defaultTheme = getThemeOrDefault(CONFIG.THEME.DEFAULT, DEFAULT_THEME_NAME) | ||
52 | 53 | ||
53 | if (serverCommit === undefined) serverCommit = await getServerCommit() | 54 | if (serverCommit === undefined) serverCommit = await getServerCommit() |
54 | 55 | ||
55 | const enabledResolutions = Object.keys(CONFIG.TRANSCODING.RESOLUTIONS) | ||
56 | .filter(key => CONFIG.TRANSCODING.ENABLED && CONFIG.TRANSCODING.RESOLUTIONS[key] === true) | ||
57 | .map(r => parseInt(r, 10)) | ||
58 | |||
59 | const registeredPlugins = PluginManager.Instance.getRegisteredPlugins() | ||
60 | .map(p => ({ | ||
61 | name: p.name, | ||
62 | version: p.version, | ||
63 | description: p.description, | ||
64 | clientScripts: p.clientScripts | ||
65 | })) | ||
66 | |||
67 | const registeredThemes = PluginManager.Instance.getRegisteredThemes() | ||
68 | .map(t => ({ | ||
69 | name: t.name, | ||
70 | version: t.version, | ||
71 | description: t.description, | ||
72 | css: t.css, | ||
73 | clientScripts: t.clientScripts | ||
74 | })) | ||
75 | |||
76 | const defaultTheme = getThemeOrDefault(CONFIG.THEME.DEFAULT, DEFAULT_THEME_NAME) | ||
77 | |||
78 | const json: ServerConfig = { | 56 | const json: ServerConfig = { |
79 | instance: { | 57 | instance: { |
80 | name: CONFIG.INSTANCE.NAME, | 58 | name: CONFIG.INSTANCE.NAME, |
@@ -88,10 +66,10 @@ async function getConfig (req: express.Request, res: express.Response) { | |||
88 | } | 66 | } |
89 | }, | 67 | }, |
90 | plugin: { | 68 | plugin: { |
91 | registered: registeredPlugins | 69 | registered: getRegisteredPlugins() |
92 | }, | 70 | }, |
93 | theme: { | 71 | theme: { |
94 | registered: registeredThemes, | 72 | registered: getRegisteredThemes(), |
95 | default: defaultTheme | 73 | default: defaultTheme |
96 | }, | 74 | }, |
97 | email: { | 75 | email: { |
@@ -100,7 +78,7 @@ async function getConfig (req: express.Request, res: express.Response) { | |||
100 | contactForm: { | 78 | contactForm: { |
101 | enabled: CONFIG.CONTACT_FORM.ENABLED | 79 | enabled: CONFIG.CONTACT_FORM.ENABLED |
102 | }, | 80 | }, |
103 | serverVersion: packageJSON.version, | 81 | serverVersion: PEERTUBE_VERSION, |
104 | serverCommit, | 82 | serverCommit, |
105 | signup: { | 83 | signup: { |
106 | allowed, | 84 | allowed, |
@@ -111,7 +89,7 @@ async function getConfig (req: express.Request, res: express.Response) { | |||
111 | hls: { | 89 | hls: { |
112 | enabled: CONFIG.TRANSCODING.HLS.ENABLED | 90 | enabled: CONFIG.TRANSCODING.HLS.ENABLED |
113 | }, | 91 | }, |
114 | enabledResolutions | 92 | enabledResolutions: getEnabledResolutions() |
115 | }, | 93 | }, |
116 | import: { | 94 | import: { |
117 | videos: { | 95 | videos: { |
@@ -342,3 +320,30 @@ function convertCustomConfigBody (body: CustomConfig) { | |||
342 | 320 | ||
343 | return objectConverter(body, keyConverter, valueConverter) | 321 | return objectConverter(body, keyConverter, valueConverter) |
344 | } | 322 | } |
323 | |||
324 | function getRegisteredThemes () { | ||
325 | return PluginManager.Instance.getRegisteredThemes() | ||
326 | .map(t => ({ | ||
327 | name: t.name, | ||
328 | version: t.version, | ||
329 | description: t.description, | ||
330 | css: t.css, | ||
331 | clientScripts: t.clientScripts | ||
332 | })) | ||
333 | } | ||
334 | |||
335 | function getEnabledResolutions () { | ||
336 | return Object.keys(CONFIG.TRANSCODING.RESOLUTIONS) | ||
337 | .filter(key => CONFIG.TRANSCODING.ENABLED && CONFIG.TRANSCODING.RESOLUTIONS[ key ] === true) | ||
338 | .map(r => parseInt(r, 10)) | ||
339 | } | ||
340 | |||
341 | function getRegisteredPlugins () { | ||
342 | return PluginManager.Instance.getRegisteredPlugins() | ||
343 | .map(p => ({ | ||
344 | name: p.name, | ||
345 | version: p.version, | ||
346 | description: p.description, | ||
347 | clientScripts: p.clientScripts | ||
348 | })) | ||
349 | } | ||