aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-07-17 10:03:55 +0200
committerChocobozzz <chocobozzz@cpy.re>2019-07-24 10:58:16 +0200
commit66170ca8c64fa4e76f3830e4a02a11345a03093b (patch)
treed2ef070a8e3cc98badcf6492f4d7db345c157d91 /server
parent109d893ff5353c3061af3062cf9443bcba39aafc (diff)
downloadPeerTube-66170ca8c64fa4e76f3830e4a02a11345a03093b.tar.gz
PeerTube-66170ca8c64fa4e76f3830e4a02a11345a03093b.tar.zst
PeerTube-66170ca8c64fa4e76f3830e4a02a11345a03093b.zip
Use process.env.npm_package_version
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/config.ts63
-rw-r--r--server/controllers/static.ts5
-rw-r--r--server/helpers/requests.ts6
-rw-r--r--server/initializers/constants.ts3
-rw-r--r--server/lib/plugins/plugin-index.ts7
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'
4import { About } from '../../../shared/models/server/about.model' 4import { About } from '../../../shared/models/server/about.model'
5import { CustomConfig } from '../../../shared/models/server/custom-config.model' 5import { CustomConfig } from '../../../shared/models/server/custom-config.model'
6import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/signup' 6import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/signup'
7import { CONSTRAINTS_FIELDS, DEFAULT_THEME_NAME } from '../../initializers/constants' 7import { CONSTRAINTS_FIELDS, DEFAULT_THEME_NAME, PEERTUBE_VERSION } from '../../initializers/constants'
8import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares' 8import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares'
9import { customConfigUpdateValidator } from '../../middlewares/validators/config' 9import { customConfigUpdateValidator } from '../../middlewares/validators/config'
10import { ClientHtml } from '../../lib/client-html' 10import { ClientHtml } from '../../lib/client-html'
@@ -18,7 +18,6 @@ import { CONFIG, reloadConfig } from '../../initializers/config'
18import { PluginManager } from '../../lib/plugins/plugin-manager' 18import { PluginManager } from '../../lib/plugins/plugin-manager'
19import { getThemeOrDefault } from '../../lib/plugins/theme-utils' 19import { getThemeOrDefault } from '../../lib/plugins/theme-utils'
20 20
21const packageJSON = require('../../../../package.json')
22const configRouter = express.Router() 21const configRouter = express.Router()
23 22
24const auditLogger = auditLoggerFactory('config') 23const auditLogger = auditLoggerFactory('config')
@@ -46,35 +45,14 @@ configRouter.delete('/custom',
46) 45)
47 46
48let serverCommit: string 47let serverCommit: string
48
49async function getConfig (req: express.Request, res: express.Response) { 49async 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
324function 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
335function 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
341function 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 @@
1import * as cors from 'cors' 1import * as cors from 'cors'
2import * as express from 'express' 2import * as express from 'express'
3import { 3import {
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'
19import { root } from '../helpers/core-utils' 19import { root } from '../helpers/core-utils'
20import { CONFIG } from '../initializers/config' 20import { CONFIG } from '../initializers/config'
21 21
22const packageJSON = require('../../../package.json')
23const staticRouter = express.Router() 22const staticRouter = express.Router()
24 23
25staticRouter.use(cors()) 24staticRouter.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 @@
1import * as Bluebird from 'bluebird' 1import * as Bluebird from 'bluebird'
2import { createWriteStream, remove } from 'fs-extra' 2import { createWriteStream, remove } from 'fs-extra'
3import * as request from 'request' 3import * as request from 'request'
4import { ACTIVITY_PUB, WEBSERVER } from '../initializers/constants' 4import { ACTIVITY_PUB, PEERTUBE_VERSION, WEBSERVER } from '../initializers/constants'
5import { processImage } from './image-utils' 5import { processImage } from './image-utils'
6import { join } from 'path' 6import { join } from 'path'
7import { logger } from './logger' 7import { logger } from './logger'
8import { CONFIG } from '../initializers/config' 8import { CONFIG } from '../initializers/config'
9 9
10const packageJSON = require('../../../package.json')
11
12function doRequest <T> ( 10function 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
70function getUserAgent () { 68function 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
22const API_VERSION = 'v1' 21const API_VERSION = 'v1'
22const PEERTUBE_VERSION = process.env.npm_package_version || 'unknown'
23 23
24const PAGINATION = { 24const PAGINATION = {
25 COUNT: { 25 COUNT: {
@@ -645,6 +645,7 @@ registerConfigChangedHandler(() => {
645export { 645export {
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
10import { PluginModel } from '../../models/server/plugin' 10import { PluginModel } from '../../models/server/plugin'
11import { PluginManager } from './plugin-manager' 11import { PluginManager } from './plugin-manager'
12import { logger } from '../../helpers/logger' 12import { logger } from '../../helpers/logger'
13 13import { PEERTUBE_VERSION } from '../../initializers/constants'
14const packageJSON = require('../../../../package.json')
15 14
16async function listAvailablePluginsFromIndex (options: PeertubePluginIndexList) { 15async 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>)
53async function getLatestPluginsVersion (npmNames: string[]): Promise<PeertubePluginLatestVersionResponse> { 52async 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'