diff options
author | Chocobozzz <me@florianbigard.com> | 2018-10-03 14:35:35 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-10-03 14:36:00 +0200 |
commit | 499d9015955c0cedd094fbe814dee6235e639627 (patch) | |
tree | b5116cb74b7f2a6ba39dfdc7eda76d2db31e0ca5 /server/helpers/utils.ts | |
parent | 6a6951ec103e495160b0e4641ea9bbf8014789c3 (diff) | |
download | PeerTube-499d9015955c0cedd094fbe814dee6235e639627.tar.gz PeerTube-499d9015955c0cedd094fbe814dee6235e639627.tar.zst PeerTube-499d9015955c0cedd094fbe814dee6235e639627.zip |
Fix config endpoint
Diffstat (limited to 'server/helpers/utils.ts')
-rw-r--r-- | server/helpers/utils.ts | 29 |
1 files changed, 20 insertions, 9 deletions
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 @@ | |||
1 | import { ResultList } from '../../shared' | 1 | import { ResultList } from '../../shared' |
2 | import { CONFIG } from '../initializers' | 2 | import { CONFIG } from '../initializers' |
3 | import { ApplicationModel } from '../models/application/application' | 3 | import { ApplicationModel } from '../models/application/application' |
4 | import { pseudoRandomBytesPromise, sha256 } from './core-utils' | 4 | import { execPromise, execPromise2, pseudoRandomBytesPromise, sha256 } from './core-utils' |
5 | import { logger } from './logger' | 5 | import { logger } from './logger' |
6 | import { join } from 'path' | 6 | import { join } from 'path' |
7 | import { Instance as ParseTorrent } from 'parse-torrent' | 7 | import { Instance as ParseTorrent } from 'parse-torrent' |
@@ -54,14 +54,25 @@ function getSecureTorrentName (originalName: string) { | |||
54 | return sha256(originalName) + '.torrent' | 54 | return sha256(originalName) + '.torrent' |
55 | } | 55 | } |
56 | 56 | ||
57 | function getVersion () { | 57 | async function getVersion () { |
58 | const tag = require('child_process') | 58 | try { |
59 | .execSync('[[ ! -d .git ]] || git name-rev --name-only --tags --no-undefined HEAD 2>/dev/null || true', { stdio: [0,1,2] }) | 59 | const tag = await execPromise2( |
60 | if (tag) return tag.replace(/^v/, '') | 60 | '[ ! -d .git ] || git name-rev --name-only --tags --no-undefined HEAD 2>/dev/null || true', |
61 | 61 | { stdio: [ 0, 1, 2 ] } | |
62 | const version = require('child_process') | 62 | ) |
63 | .execSync('[[ ! -d .git ]] || git rev-parse --short HEAD').toString().trim() | 63 | |
64 | if (version) return version | 64 | if (tag) return tag.replace(/^v/, '') |
65 | } catch (err) { | ||
66 | logger.debug('Cannot get version from git tags.', { err }) | ||
67 | } | ||
68 | |||
69 | try { | ||
70 | const version = await execPromise('[ ! -d .git ] || git rev-parse --short HEAD') | ||
71 | |||
72 | if (version) return version.toString().trim() | ||
73 | } catch (err) { | ||
74 | logger.debug('Cannot get version from git HEAD.', { err }) | ||
75 | } | ||
65 | 76 | ||
66 | return require('../../../package.json').version | 77 | return require('../../../package.json').version |
67 | } | 78 | } |