diff --git a/package-lock.json b/package-lock.json index 6fbd886f7..2f8f65d34 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "dependencies": { "@dqbd/tiktoken": "^1.0.2", "axios": "^1.3.4", + "command-exists": "^1.2.9", "compression": "^1", "cookie-parser": "^1.4.6", "cors": "^2.8.5", @@ -655,6 +656,11 @@ "node": ">= 0.8" } }, + "node_modules/command-exists": { + "version": "1.2.9", + "resolved": "https://registry.npmjs.org/command-exists/-/command-exists-1.2.9.tgz", + "integrity": "sha512-LTQ/SGc+s0Xc0Fu5WaKnR0YiygZkm9eKFvyS+fRsU7/ZWFF8ykFM6Pc9aCVf1+xasOOZpO3BAVgVrKvsqKHV7w==" + }, "node_modules/compressible": { "version": "2.0.18", "license": "MIT", diff --git a/package.json b/package.json index fa16e3a2e..479282a18 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "dependencies": { "@dqbd/tiktoken": "^1.0.2", "axios": "^1.3.4", + "command-exists": "^1.2.9", "compression": "^1", "cookie-parser": "^1.4.6", "cors": "^2.8.5", diff --git a/server.js b/server.js index 7be289fd8..f076ac54f 100644 --- a/server.js +++ b/server.js @@ -58,6 +58,7 @@ const DeviceDetector = require("device-detector-js"); const { TextEncoder, TextDecoder } = require('util'); const utf8Encode = new TextEncoder(); const utf8Decode = new TextDecoder('utf-8', { ignoreBOM: true }); +const commandExistsSync = require('command-exists').sync; const config = require(path.join(__dirname, './config.conf')); const server_port = process.env.SILLY_TAVERN_PORT || config.port; @@ -310,9 +311,14 @@ app.get('/version', function (_, response) { try { const pkgJson = require('./package.json'); pkgVersion = pkgJson.version; - gitRevision = require('child_process') - .execSync('git rev-parse --short HEAD', { cwd: __dirname }) - .toString().trim(); + if (commandExistsSync('git')) { + gitRevision = require('child_process') + .execSync('git rev-parse --short HEAD', { cwd: __dirname }) + .toString().trim(); + } + } + catch { + // suppress exception } finally { response.send(`SillyTavern:${gitRevision || pkgVersion}:Cohee#1207`)