From abb2c7927ca1640a755e0ec32c51bcc9c873b34c Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Sat, 29 Sep 2018 19:53:49 +0200 Subject: [PATCH] show last commit hash alongside server version in footer --- client/src/app/app.component.html | 2 +- client/src/app/app.component.ts | 5 +++++ server/controllers/api/config.ts | 5 +++++ server/helpers/utils.ts | 13 +++++++++++++ server/tools/cli.ts | 13 ++----------- shared/models/server/server-config.model.ts | 1 + 6 files changed, 27 insertions(+), 12 deletions(-) diff --git a/client/src/app/app.component.html b/client/src/app/app.component.html index 958c131f7..03f7e88ed 100644 --- a/client/src/app/app.component.html +++ b/client/src/app/app.component.html @@ -29,7 +29,7 @@ diff --git a/client/src/app/app.component.ts b/client/src/app/app.component.ts index 907bc583b..29b02032f 100644 --- a/client/src/app/app.component.ts +++ b/client/src/app/app.component.ts @@ -45,6 +45,11 @@ export class AppComponent implements OnInit { return this.serverService.getConfig().serverVersion } + get serverCommit () { + const commit = this.serverService.getConfig().serverCommit || '' + return (commit !== '') ? '...' + commit : commit + } + get instanceName () { return this.serverService.getConfig().instance.name } 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: [], diff --git a/shared/models/server/server-config.model.ts b/shared/models/server/server-config.model.ts index e0ff8c07d..91196c1eb 100644 --- a/shared/models/server/server-config.model.ts +++ b/shared/models/server/server-config.model.ts @@ -2,6 +2,7 @@ import { NSFWPolicyType } from '../videos/nsfw-policy.type' export interface ServerConfig { serverVersion: string + serverCommit?: string instance: { name: string -- 2.41.0