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 | |
parent | 6a6951ec103e495160b0e4641ea9bbf8014789c3 (diff) | |
download | PeerTube-499d9015955c0cedd094fbe814dee6235e639627.tar.gz PeerTube-499d9015955c0cedd094fbe814dee6235e639627.tar.zst PeerTube-499d9015955c0cedd094fbe814dee6235e639627.zip |
Fix config endpoint
-rw-r--r-- | server/controllers/api/config.ts | 2 | ||||
-rw-r--r-- | server/helpers/core-utils.ts | 8 | ||||
-rw-r--r-- | server/helpers/utils.ts | 29 | ||||
-rw-r--r-- | server/tools/cli.ts | 3 | ||||
-rwxr-xr-x | server/tools/peertube.ts | 2 |
5 files changed, 29 insertions, 15 deletions
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 | |||
43 | async function getConfig (req: express.Request, res: express.Response, next: express.NextFunction) { | 43 | async function getConfig (req: express.Request, res: express.Response, next: express.NextFunction) { |
44 | const allowed = await isSignupAllowed() | 44 | const allowed = await isSignupAllowed() |
45 | const allowedForCurrentIP = isSignupAllowedForCurrentIP(req.ip) | 45 | const allowedForCurrentIP = isSignupAllowedForCurrentIP(req.ip) |
46 | serverCommit = (serverCommit) ? serverCommit : getVersion() | 46 | serverCommit = (serverCommit) ? serverCommit : await getVersion() |
47 | if (serverCommit === packageJSON.version) serverCommit = '' | 47 | if (serverCommit === packageJSON.version) serverCommit = '' |
48 | 48 | ||
49 | const enabledResolutions = Object.keys(CONFIG.TRANSCODING.RESOLUTIONS) | 49 | 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' | |||
8 | import { createHash, pseudoRandomBytes } from 'crypto' | 8 | import { createHash, pseudoRandomBytes } from 'crypto' |
9 | import { isAbsolute, join } from 'path' | 9 | import { isAbsolute, join } from 'path' |
10 | import * as pem from 'pem' | 10 | import * as pem from 'pem' |
11 | import * as rimraf from 'rimraf' | ||
12 | import { URL } from 'url' | 11 | import { URL } from 'url' |
13 | import { truncate } from 'lodash' | 12 | import { truncate } from 'lodash' |
13 | import { exec } from 'child_process' | ||
14 | 14 | ||
15 | const timeTable = { | 15 | const timeTable = { |
16 | ms: 1, | 16 | ms: 1, |
@@ -178,6 +178,8 @@ const bcryptComparePromise = promisify2<any, string, boolean>(bcrypt.compare) | |||
178 | const bcryptGenSaltPromise = promisify1<number, string>(bcrypt.genSalt) | 178 | const bcryptGenSaltPromise = promisify1<number, string>(bcrypt.genSalt) |
179 | const bcryptHashPromise = promisify2<any, string | number, string>(bcrypt.hash) | 179 | const bcryptHashPromise = promisify2<any, string | number, string>(bcrypt.hash) |
180 | const createTorrentPromise = promisify2<string, any, any>(createTorrent) | 180 | const createTorrentPromise = promisify2<string, any, any>(createTorrent) |
181 | const execPromise2 = promisify2<string, any, string>(exec) | ||
182 | const execPromise = promisify1<string, string>(exec) | ||
181 | 183 | ||
182 | // --------------------------------------------------------------------------- | 184 | // --------------------------------------------------------------------------- |
183 | 185 | ||
@@ -203,5 +205,7 @@ export { | |||
203 | bcryptComparePromise, | 205 | bcryptComparePromise, |
204 | bcryptGenSaltPromise, | 206 | bcryptGenSaltPromise, |
205 | bcryptHashPromise, | 207 | bcryptHashPromise, |
206 | createTorrentPromise | 208 | createTorrentPromise, |
209 | execPromise2, | ||
210 | execPromise | ||
207 | } | 211 | } |
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 | } |
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 @@ | |||
1 | const config = require('application-config')('PeerTube/CLI') | 1 | const config = require('application-config')('PeerTube/CLI') |
2 | const netrc = require('netrc-parser').default | 2 | const netrc = require('netrc-parser').default |
3 | import { getVersion } from '../helpers/utils' | ||
4 | 3 | ||
5 | const version = getVersion | 4 | const version = require('../../../package.json').version |
6 | 5 | ||
7 | let settings = { | 6 | let settings = { |
8 | remotes: [], | 7 | 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 { | |||
7 | } from './cli' | 7 | } from './cli' |
8 | 8 | ||
9 | program | 9 | program |
10 | .version(version(), '-v, --version') | 10 | .version(version, '-v, --version') |
11 | .usage('[command] [options]') | 11 | .usage('[command] [options]') |
12 | 12 | ||
13 | /* Subcommands automatically loaded in the directory and beginning by peertube-* */ | 13 | /* Subcommands automatically loaded in the directory and beginning by peertube-* */ |