From abb2c7927ca1640a755e0ec32c51bcc9c873b34c Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Sat, 29 Sep 2018 19:53:49 +0200 Subject: show last commit hash alongside server version in footer --- server/controllers/api/config.ts | 5 +++++ server/helpers/utils.ts | 13 +++++++++++++ server/tools/cli.ts | 13 ++----------- 3 files changed, 20 insertions(+), 11 deletions(-) (limited to 'server') diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts index 95549b724..633cf5e34 100644 --- a/server/controllers/api/config.ts +++ b/server/controllers/api/config.ts @@ -10,6 +10,7 @@ import { customConfigUpdateValidator } from '../../middlewares/validators/config import { ClientHtml } from '../../lib/client-html' import { auditLoggerFactory, CustomConfigAuditView, getAuditIdFromRes } from '../../helpers/audit-logger' import { remove, writeJSON } from 'fs-extra' +import { version } from '../../tools/cli' const packageJSON = require('../../../../package.json') const configRouter = express.Router() @@ -38,9 +39,12 @@ configRouter.delete('/custom', asyncMiddleware(deleteCustomConfig) ) +let serverCommit: string async function getConfig (req: express.Request, res: express.Response, next: express.NextFunction) { const allowed = await isSignupAllowed() const allowedForCurrentIP = isSignupAllowedForCurrentIP(req.ip) + serverCommit = (serverCommit) ? serverCommit : version() + if (serverCommit === packageJSON.version) serverCommit = '' const enabledResolutions = Object.keys(CONFIG.TRANSCODING.RESOLUTIONS) .filter(key => CONFIG.TRANSCODING.ENABLED === CONFIG.TRANSCODING.RESOLUTIONS[key] === true) @@ -58,6 +62,7 @@ async function getConfig (req: express.Request, res: express.Response, next: exp } }, serverVersion: packageJSON.version, + serverCommit, signup: { allowed, allowedForCurrentIP, diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts index a42474417..f5bf6de56 100644 --- a/server/helpers/utils.ts +++ b/server/helpers/utils.ts @@ -54,6 +54,18 @@ function getSecureTorrentName (originalName: string) { return sha256(originalName) + '.torrent' } +function getVersion () { + const tag = require('child_process') + .execSync('[[ ! -d .git ]] || git name-rev --name-only --tags --no-undefined HEAD 2>/dev/null || true', { stdio: [0,1,2] }) + if (tag) return tag.replace(/^v/, '') + + const version = require('child_process') + .execSync('[[ ! -d .git ]] || git rev-parse --short HEAD').toString().trim() + if (version) return version + + return require('../../../package.json').version +} + // --------------------------------------------------------------------------- export { @@ -62,5 +74,6 @@ export { getFormattedObjects, getSecureTorrentName, getServerActor, + getVersion, generateVideoTmpPath } diff --git a/server/tools/cli.ts b/server/tools/cli.ts index 9a170d4da..87d1512a3 100644 --- a/server/tools/cli.ts +++ b/server/tools/cli.ts @@ -1,17 +1,8 @@ const config = require('application-config')('PeerTube/CLI') const netrc = require('netrc-parser').default +import { getVersion } from '../helpers/utils' -const version = () => { - const tag = require('child_process') - .execSync('[[ ! -d .git ]] || git name-rev --name-only --tags --no-undefined HEAD 2>/dev/null || true', { stdio: [0,1,2] }) - if (tag) return tag - - const version = require('child_process') - .execSync('[[ ! -d .git ]] || git rev-parse --short HEAD').toString().trim() - if (version) return version - - return require('../../../package.json').version -} +const version = getVersion let settings = { remotes: [], -- cgit v1.2.3