1
0
Fork 0

Optimize config endpoint

This commit is contained in:
Chocobozzz 2018-11-23 11:06:10 +01:00
parent f95cb03a29
commit 1b5e2d7290
No known key found for this signature in database
GPG key ID: 583A612D890159BE
3 changed files with 9 additions and 12 deletions

View file

@ -10,7 +10,7 @@ import { customConfigUpdateValidator } from '../../middlewares/validators/config
import { ClientHtml } from '../../lib/client-html' import { ClientHtml } from '../../lib/client-html'
import { auditLoggerFactory, CustomConfigAuditView, getAuditIdFromRes } from '../../helpers/audit-logger' import { auditLoggerFactory, CustomConfigAuditView, getAuditIdFromRes } from '../../helpers/audit-logger'
import { remove, writeJSON } from 'fs-extra' import { remove, writeJSON } from 'fs-extra'
import { getVersion } from '../../helpers/utils' import { getServerCommit } from '../../helpers/utils'
const packageJSON = require('../../../../package.json') const packageJSON = require('../../../../package.json')
const configRouter = express.Router() const configRouter = express.Router()
@ -40,11 +40,11 @@ configRouter.delete('/custom',
) )
let serverCommit: string let serverCommit: string
async function getConfig (req: express.Request, res: express.Response, next: express.NextFunction) { async function getConfig (req: express.Request, res: express.Response) {
const allowed = await isSignupAllowed() const allowed = await isSignupAllowed()
const allowedForCurrentIP = isSignupAllowedForCurrentIP(req.ip) const allowedForCurrentIP = isSignupAllowedForCurrentIP(req.ip)
serverCommit = (serverCommit) ? serverCommit : await getVersion()
if (serverCommit === packageJSON.version) serverCommit = '' if (serverCommit === undefined) serverCommit = await getServerCommit()
const enabledResolutions = Object.keys(CONFIG.TRANSCODING.RESOLUTIONS) const enabledResolutions = Object.keys(CONFIG.TRANSCODING.RESOLUTIONS)
.filter(key => CONFIG.TRANSCODING.ENABLED === CONFIG.TRANSCODING.RESOLUTIONS[key] === true) .filter(key => CONFIG.TRANSCODING.ENABLED === CONFIG.TRANSCODING.RESOLUTIONS[key] === true)

View file

@ -57,7 +57,7 @@ function getSecureTorrentName (originalName: string) {
return sha256(originalName) + '.torrent' return sha256(originalName) + '.torrent'
} }
async function getVersion () { async function getServerCommit () {
try { try {
const tag = await execPromise2( const tag = await execPromise2(
'[ ! -d .git ] || git name-rev --name-only --tags --no-undefined HEAD 2>/dev/null || true', '[ ! -d .git ] || git name-rev --name-only --tags --no-undefined HEAD 2>/dev/null || true',
@ -77,7 +77,7 @@ async function getVersion () {
logger.debug('Cannot get version from git HEAD.', { err }) logger.debug('Cannot get version from git HEAD.', { err })
} }
return require('../../../package.json').version return ''
} }
/** /**
@ -102,7 +102,7 @@ export {
getFormattedObjects, getFormattedObjects,
getSecureTorrentName, getSecureTorrentName,
getServerActor, getServerActor,
getVersion, getServerCommit,
generateVideoTmpPath, generateVideoTmpPath,
getUUIDFromFilename getUUIDFromFilename
} }

View file

@ -20,14 +20,10 @@ import * as signupUtils from '../helpers/signup'
import * as utils from '../helpers/utils' import * as utils from '../helpers/utils'
import * as YoutubeDLUtils from '../helpers/youtube-dl' import * as YoutubeDLUtils from '../helpers/youtube-dl'
let versionCommitHash
const start = async () => { const start = async () => {
await initDatabaseModels(true) await initDatabaseModels(true)
await utils.getVersion().then((data) => { const versionCommitHash = await utils.getServerCommit()
versionCommitHash = data
})
const initContext = (replServer) => { const initContext = (replServer) => {
return (context) => { return (context) => {
@ -59,6 +55,7 @@ const start = async () => {
initContext(replServer)(replServer.context) initContext(replServer)(replServer.context)
replServer.on('reset', initContext(replServer)) replServer.on('reset', initContext(replServer))
replServer.on('exit', () => process.exit())
const resetCommand = { const resetCommand = {
help: 'Reset REPL', help: 'Reset REPL',