From: Chocobozzz Date: Wed, 3 Oct 2018 12:35:35 +0000 (+0200) Subject: Fix config endpoint X-Git-Tag: v1.0.0-rc.2~2 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=499d9015955c0cedd094fbe814dee6235e639627;p=github%2FChocobozzz%2FPeerTube.git Fix config endpoint --- diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts index f14104d7f..03c1cec7b 100644 --- a/server/controllers/api/config.ts +++ b/server/controllers/api/config.ts @@ -43,7 +43,7 @@ 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 : getVersion() + serverCommit = (serverCommit) ? serverCommit : await getVersion() if (serverCommit === packageJSON.version) serverCommit = '' const enabledResolutions = Object.keys(CONFIG.TRANSCODING.RESOLUTIONS) diff --git a/server/helpers/core-utils.ts b/server/helpers/core-utils.ts index b1a27e089..00bc0bdda 100644 --- a/server/helpers/core-utils.ts +++ b/server/helpers/core-utils.ts @@ -8,9 +8,9 @@ import * as createTorrent from 'create-torrent' import { createHash, pseudoRandomBytes } from 'crypto' import { isAbsolute, join } from 'path' import * as pem from 'pem' -import * as rimraf from 'rimraf' import { URL } from 'url' import { truncate } from 'lodash' +import { exec } from 'child_process' const timeTable = { ms: 1, @@ -178,6 +178,8 @@ const bcryptComparePromise = promisify2(bcrypt.compare) const bcryptGenSaltPromise = promisify1(bcrypt.genSalt) const bcryptHashPromise = promisify2(bcrypt.hash) const createTorrentPromise = promisify2(createTorrent) +const execPromise2 = promisify2(exec) +const execPromise = promisify1(exec) // --------------------------------------------------------------------------- @@ -203,5 +205,7 @@ export { bcryptComparePromise, bcryptGenSaltPromise, bcryptHashPromise, - createTorrentPromise + createTorrentPromise, + execPromise2, + execPromise } diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts index f5bf6de56..6228fec04 100644 --- a/server/helpers/utils.ts +++ b/server/helpers/utils.ts @@ -1,7 +1,7 @@ import { ResultList } from '../../shared' import { CONFIG } from '../initializers' import { ApplicationModel } from '../models/application/application' -import { pseudoRandomBytesPromise, sha256 } from './core-utils' +import { execPromise, execPromise2, pseudoRandomBytesPromise, sha256 } from './core-utils' import { logger } from './logger' import { join } from 'path' import { Instance as ParseTorrent } from 'parse-torrent' @@ -54,14 +54,25 @@ 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 +async function getVersion () { + try { + const tag = await execPromise2( + '[ ! -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/, '') + } catch (err) { + logger.debug('Cannot get version from git tags.', { err }) + } + + try { + const version = await execPromise('[ ! -d .git ] || git rev-parse --short HEAD') + + if (version) return version.toString().trim() + } catch (err) { + logger.debug('Cannot get version from git HEAD.', { err }) + } return require('../../../package.json').version } diff --git a/server/tools/cli.ts b/server/tools/cli.ts index 87d1512a3..53b20964e 100644 --- a/server/tools/cli.ts +++ b/server/tools/cli.ts @@ -1,8 +1,7 @@ const config = require('application-config')('PeerTube/CLI') const netrc = require('netrc-parser').default -import { getVersion } from '../helpers/utils' -const version = getVersion +const version = require('../../../package.json').version let settings = { remotes: [], diff --git a/server/tools/peertube.ts b/server/tools/peertube.ts index 21609deed..ad76bafb4 100755 --- a/server/tools/peertube.ts +++ b/server/tools/peertube.ts @@ -7,7 +7,7 @@ import { } from './cli' program - .version(version(), '-v, --version') + .version(version, '-v, --version') .usage('[command] [options]') /* Subcommands automatically loaded in the directory and beginning by peertube-* */