aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-11-23 11:06:10 +0100
committerChocobozzz <me@florianbigard.com>2018-11-23 11:07:00 +0100
commit1b5e2d72900c8ceaf76940b72839d3c424ac96e8 (patch)
tree155fb65bd2d35259294dcfdb9d0c3e1de0400b92 /server
parentf95cb03a29716a455ad89877dfd5192d825e3931 (diff)
downloadPeerTube-1b5e2d72900c8ceaf76940b72839d3c424ac96e8.tar.gz
PeerTube-1b5e2d72900c8ceaf76940b72839d3c424ac96e8.tar.zst
PeerTube-1b5e2d72900c8ceaf76940b72839d3c424ac96e8.zip
Optimize config endpoint
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/config.ts8
-rw-r--r--server/helpers/utils.ts6
-rw-r--r--server/tools/peertube-repl.ts7
3 files changed, 9 insertions, 12 deletions
diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts
index 03c1cec7b..5233e9f68 100644
--- a/server/controllers/api/config.ts
+++ b/server/controllers/api/config.ts
@@ -10,7 +10,7 @@ import { customConfigUpdateValidator } from '../../middlewares/validators/config
10import { ClientHtml } from '../../lib/client-html' 10import { ClientHtml } from '../../lib/client-html'
11import { auditLoggerFactory, CustomConfigAuditView, getAuditIdFromRes } from '../../helpers/audit-logger' 11import { auditLoggerFactory, CustomConfigAuditView, getAuditIdFromRes } from '../../helpers/audit-logger'
12import { remove, writeJSON } from 'fs-extra' 12import { remove, writeJSON } from 'fs-extra'
13import { getVersion } from '../../helpers/utils' 13import { getServerCommit } from '../../helpers/utils'
14 14
15const packageJSON = require('../../../../package.json') 15const packageJSON = require('../../../../package.json')
16const configRouter = express.Router() 16const configRouter = express.Router()
@@ -40,11 +40,11 @@ configRouter.delete('/custom',
40) 40)
41 41
42let serverCommit: string 42let serverCommit: string
43async function getConfig (req: express.Request, res: express.Response, next: express.NextFunction) { 43async function getConfig (req: express.Request, res: express.Response) {
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 : await getVersion() 46
47 if (serverCommit === packageJSON.version) serverCommit = '' 47 if (serverCommit === undefined) serverCommit = await getServerCommit()
48 48
49 const enabledResolutions = Object.keys(CONFIG.TRANSCODING.RESOLUTIONS) 49 const enabledResolutions = Object.keys(CONFIG.TRANSCODING.RESOLUTIONS)
50 .filter(key => CONFIG.TRANSCODING.ENABLED === CONFIG.TRANSCODING.RESOLUTIONS[key] === true) 50 .filter(key => CONFIG.TRANSCODING.ENABLED === CONFIG.TRANSCODING.RESOLUTIONS[key] === true)
diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts
index 049c3f8bc..5c9d6fe2f 100644
--- a/server/helpers/utils.ts
+++ b/server/helpers/utils.ts
@@ -57,7 +57,7 @@ function getSecureTorrentName (originalName: string) {
57 return sha256(originalName) + '.torrent' 57 return sha256(originalName) + '.torrent'
58} 58}
59 59
60async function getVersion () { 60async function getServerCommit () {
61 try { 61 try {
62 const tag = await execPromise2( 62 const tag = await execPromise2(
63 '[ ! -d .git ] || git name-rev --name-only --tags --no-undefined HEAD 2>/dev/null || true', 63 '[ ! -d .git ] || git name-rev --name-only --tags --no-undefined HEAD 2>/dev/null || true',
@@ -77,7 +77,7 @@ async function getVersion () {
77 logger.debug('Cannot get version from git HEAD.', { err }) 77 logger.debug('Cannot get version from git HEAD.', { err })
78 } 78 }
79 79
80 return require('../../../package.json').version 80 return ''
81} 81}
82 82
83/** 83/**
@@ -102,7 +102,7 @@ export {
102 getFormattedObjects, 102 getFormattedObjects,
103 getSecureTorrentName, 103 getSecureTorrentName,
104 getServerActor, 104 getServerActor,
105 getVersion, 105 getServerCommit,
106 generateVideoTmpPath, 106 generateVideoTmpPath,
107 getUUIDFromFilename 107 getUUIDFromFilename
108} 108}
diff --git a/server/tools/peertube-repl.ts b/server/tools/peertube-repl.ts
index 6800ff8ab..04d8b95a3 100644
--- a/server/tools/peertube-repl.ts
+++ b/server/tools/peertube-repl.ts
@@ -20,14 +20,10 @@ import * as signupUtils from '../helpers/signup'
20import * as utils from '../helpers/utils' 20import * as utils from '../helpers/utils'
21import * as YoutubeDLUtils from '../helpers/youtube-dl' 21import * as YoutubeDLUtils from '../helpers/youtube-dl'
22 22
23let versionCommitHash
24
25const start = async () => { 23const start = async () => {
26 await initDatabaseModels(true) 24 await initDatabaseModels(true)
27 25
28 await utils.getVersion().then((data) => { 26 const versionCommitHash = await utils.getServerCommit()
29 versionCommitHash = data
30 })
31 27
32 const initContext = (replServer) => { 28 const initContext = (replServer) => {
33 return (context) => { 29 return (context) => {
@@ -59,6 +55,7 @@ const start = async () => {
59 55
60 initContext(replServer)(replServer.context) 56 initContext(replServer)(replServer.context)
61 replServer.on('reset', initContext(replServer)) 57 replServer.on('reset', initContext(replServer))
58 replServer.on('exit', () => process.exit())
62 59
63 const resetCommand = { 60 const resetCommand = {
64 help: 'Reset REPL', 61 help: 'Reset REPL',