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 | |
parent | 109d893ff5353c3061af3062cf9443bcba39aafc (diff) | |
download | PeerTube-66170ca8c64fa4e76f3830e4a02a11345a03093b.tar.gz PeerTube-66170ca8c64fa4e76f3830e4a02a11345a03093b.tar.zst PeerTube-66170ca8c64fa4e76f3830e4a02a11345a03093b.zip |
Use process.env.npm_package_version
-rw-r--r-- | server/controllers/api/config.ts | 63 | ||||
-rw-r--r-- | server/controllers/static.ts | 5 | ||||
-rw-r--r-- | server/helpers/requests.ts | 6 | ||||
-rw-r--r-- | server/initializers/constants.ts | 3 | ||||
-rw-r--r-- | server/lib/plugins/plugin-index.ts | 7 |
5 files changed, 43 insertions, 41 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 | } | ||
diff --git a/server/controllers/static.ts b/server/controllers/static.ts index a6b462443..af7de562a 100644 --- a/server/controllers/static.ts +++ b/server/controllers/static.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as cors from 'cors' | 1 | import * as cors from 'cors' |
2 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import { | 3 | import { |
4 | HLS_STREAMING_PLAYLIST_DIRECTORY, | 4 | HLS_STREAMING_PLAYLIST_DIRECTORY, PEERTUBE_VERSION, |
5 | ROUTE_CACHE_LIFETIME, | 5 | ROUTE_CACHE_LIFETIME, |
6 | STATIC_DOWNLOAD_PATHS, | 6 | STATIC_DOWNLOAD_PATHS, |
7 | STATIC_MAX_AGE, | 7 | STATIC_MAX_AGE, |
@@ -19,7 +19,6 @@ import { join } from 'path' | |||
19 | import { root } from '../helpers/core-utils' | 19 | import { root } from '../helpers/core-utils' |
20 | import { CONFIG } from '../initializers/config' | 20 | import { CONFIG } from '../initializers/config' |
21 | 21 | ||
22 | const packageJSON = require('../../../package.json') | ||
23 | const staticRouter = express.Router() | 22 | const staticRouter = express.Router() |
24 | 23 | ||
25 | staticRouter.use(cors()) | 24 | staticRouter.use(cors()) |
@@ -205,7 +204,7 @@ async function generateNodeinfo (req: express.Request, res: express.Response) { | |||
205 | version: '2.0', | 204 | version: '2.0', |
206 | software: { | 205 | software: { |
207 | name: 'peertube', | 206 | name: 'peertube', |
208 | version: packageJSON.version | 207 | version: PEERTUBE_VERSION |
209 | }, | 208 | }, |
210 | protocols: [ | 209 | protocols: [ |
211 | 'activitypub' | 210 | 'activitypub' |
diff --git a/server/helpers/requests.ts b/server/helpers/requests.ts index 80476d649..b556c392e 100644 --- a/server/helpers/requests.ts +++ b/server/helpers/requests.ts | |||
@@ -1,14 +1,12 @@ | |||
1 | import * as Bluebird from 'bluebird' | 1 | import * as Bluebird from 'bluebird' |
2 | import { createWriteStream, remove } from 'fs-extra' | 2 | import { createWriteStream, remove } from 'fs-extra' |
3 | import * as request from 'request' | 3 | import * as request from 'request' |
4 | import { ACTIVITY_PUB, WEBSERVER } from '../initializers/constants' | 4 | import { ACTIVITY_PUB, PEERTUBE_VERSION, WEBSERVER } from '../initializers/constants' |
5 | import { processImage } from './image-utils' | 5 | import { processImage } from './image-utils' |
6 | import { join } from 'path' | 6 | import { join } from 'path' |
7 | import { logger } from './logger' | 7 | import { logger } from './logger' |
8 | import { CONFIG } from '../initializers/config' | 8 | import { CONFIG } from '../initializers/config' |
9 | 9 | ||
10 | const packageJSON = require('../../../package.json') | ||
11 | |||
12 | function doRequest <T> ( | 10 | function doRequest <T> ( |
13 | requestOptions: request.CoreOptions & request.UriOptions & { activityPub?: boolean }, | 11 | requestOptions: request.CoreOptions & request.UriOptions & { activityPub?: boolean }, |
14 | bodyKBLimit = 1000 // 1MB | 12 | bodyKBLimit = 1000 // 1MB |
@@ -68,7 +66,7 @@ async function downloadImage (url: string, destDir: string, destName: string, si | |||
68 | } | 66 | } |
69 | 67 | ||
70 | function getUserAgent () { | 68 | function getUserAgent () { |
71 | return `PeerTube/${packageJSON.version} (+${WEBSERVER.URL})` | 69 | return `PeerTube/${PEERTUBE_VERSION} (+${WEBSERVER.URL})` |
72 | } | 70 | } |
73 | 71 | ||
74 | // --------------------------------------------------------------------------- | 72 | // --------------------------------------------------------------------------- |
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index cd4d4e847..93ccb7da8 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts | |||
@@ -18,8 +18,8 @@ const LAST_MIGRATION_VERSION = 400 | |||
18 | 18 | ||
19 | // --------------------------------------------------------------------------- | 19 | // --------------------------------------------------------------------------- |
20 | 20 | ||
21 | // API version | ||
22 | const API_VERSION = 'v1' | 21 | const API_VERSION = 'v1' |
22 | const PEERTUBE_VERSION = process.env.npm_package_version || 'unknown' | ||
23 | 23 | ||
24 | const PAGINATION = { | 24 | const PAGINATION = { |
25 | COUNT: { | 25 | COUNT: { |
@@ -645,6 +645,7 @@ registerConfigChangedHandler(() => { | |||
645 | export { | 645 | export { |
646 | WEBSERVER, | 646 | WEBSERVER, |
647 | API_VERSION, | 647 | API_VERSION, |
648 | PEERTUBE_VERSION, | ||
648 | HLS_REDUNDANCY_DIRECTORY, | 649 | HLS_REDUNDANCY_DIRECTORY, |
649 | P2P_MEDIA_LOADER_PEER_VERSION, | 650 | P2P_MEDIA_LOADER_PEER_VERSION, |
650 | AVATARS_SIZE, | 651 | AVATARS_SIZE, |
diff --git a/server/lib/plugins/plugin-index.ts b/server/lib/plugins/plugin-index.ts index 63cd47e63..6b7810618 100644 --- a/server/lib/plugins/plugin-index.ts +++ b/server/lib/plugins/plugin-index.ts | |||
@@ -10,8 +10,7 @@ import { PeerTubePluginIndex } from '../../../shared/models/plugins/peertube-plu | |||
10 | import { PluginModel } from '../../models/server/plugin' | 10 | import { PluginModel } from '../../models/server/plugin' |
11 | import { PluginManager } from './plugin-manager' | 11 | import { PluginManager } from './plugin-manager' |
12 | import { logger } from '../../helpers/logger' | 12 | import { logger } from '../../helpers/logger' |
13 | 13 | import { PEERTUBE_VERSION } from '../../initializers/constants' | |
14 | const packageJSON = require('../../../../package.json') | ||
15 | 14 | ||
16 | async function listAvailablePluginsFromIndex (options: PeertubePluginIndexList) { | 15 | async function listAvailablePluginsFromIndex (options: PeertubePluginIndexList) { |
17 | const { start = 0, count = 20, search, sort = 'npmName', pluginType } = options | 16 | const { start = 0, count = 20, search, sort = 'npmName', pluginType } = options |
@@ -22,7 +21,7 @@ async function listAvailablePluginsFromIndex (options: PeertubePluginIndexList) | |||
22 | sort, | 21 | sort, |
23 | pluginType, | 22 | pluginType, |
24 | search, | 23 | search, |
25 | currentPeerTubeEngine: packageJSON.version | 24 | currentPeerTubeEngine: PEERTUBE_VERSION |
26 | } | 25 | } |
27 | 26 | ||
28 | const uri = CONFIG.PLUGINS.INDEX.URL + '/api/v1/plugins' | 27 | const uri = CONFIG.PLUGINS.INDEX.URL + '/api/v1/plugins' |
@@ -53,7 +52,7 @@ async function addInstanceInformation (result: ResultList<PeerTubePluginIndex>) | |||
53 | async function getLatestPluginsVersion (npmNames: string[]): Promise<PeertubePluginLatestVersionResponse> { | 52 | async function getLatestPluginsVersion (npmNames: string[]): Promise<PeertubePluginLatestVersionResponse> { |
54 | const bodyRequest: PeertubePluginLatestVersionRequest = { | 53 | const bodyRequest: PeertubePluginLatestVersionRequest = { |
55 | npmNames, | 54 | npmNames, |
56 | currentPeerTubeEngine: packageJSON.version | 55 | currentPeerTubeEngine: PEERTUBE_VERSION |
57 | } | 56 | } |
58 | 57 | ||
59 | const uri = CONFIG.PLUGINS.INDEX.URL + '/api/v1/plugins/latest-version' | 58 | const uri = CONFIG.PLUGINS.INDEX.URL + '/api/v1/plugins/latest-version' |