Check for git command before running

This commit is contained in:
SillyLossy
2023-05-09 17:55:42 +03:00
parent 9bdceabdf9
commit 5c7e7ba83a
3 changed files with 16 additions and 3 deletions

6
package-lock.json generated
View File

@@ -11,6 +11,7 @@
"dependencies": { "dependencies": {
"@dqbd/tiktoken": "^1.0.2", "@dqbd/tiktoken": "^1.0.2",
"axios": "^1.3.4", "axios": "^1.3.4",
"command-exists": "^1.2.9",
"compression": "^1", "compression": "^1",
"cookie-parser": "^1.4.6", "cookie-parser": "^1.4.6",
"cors": "^2.8.5", "cors": "^2.8.5",
@@ -655,6 +656,11 @@
"node": ">= 0.8" "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": { "node_modules/compressible": {
"version": "2.0.18", "version": "2.0.18",
"license": "MIT", "license": "MIT",

View File

@@ -2,6 +2,7 @@
"dependencies": { "dependencies": {
"@dqbd/tiktoken": "^1.0.2", "@dqbd/tiktoken": "^1.0.2",
"axios": "^1.3.4", "axios": "^1.3.4",
"command-exists": "^1.2.9",
"compression": "^1", "compression": "^1",
"cookie-parser": "^1.4.6", "cookie-parser": "^1.4.6",
"cors": "^2.8.5", "cors": "^2.8.5",

View File

@@ -58,6 +58,7 @@ const DeviceDetector = require("device-detector-js");
const { TextEncoder, TextDecoder } = require('util'); const { TextEncoder, TextDecoder } = require('util');
const utf8Encode = new TextEncoder(); const utf8Encode = new TextEncoder();
const utf8Decode = new TextDecoder('utf-8', { ignoreBOM: true }); const utf8Decode = new TextDecoder('utf-8', { ignoreBOM: true });
const commandExistsSync = require('command-exists').sync;
const config = require(path.join(__dirname, './config.conf')); const config = require(path.join(__dirname, './config.conf'));
const server_port = process.env.SILLY_TAVERN_PORT || config.port; const server_port = process.env.SILLY_TAVERN_PORT || config.port;
@@ -310,10 +311,15 @@ app.get('/version', function (_, response) {
try { try {
const pkgJson = require('./package.json'); const pkgJson = require('./package.json');
pkgVersion = pkgJson.version; pkgVersion = pkgJson.version;
if (commandExistsSync('git')) {
gitRevision = require('child_process') gitRevision = require('child_process')
.execSync('git rev-parse --short HEAD', { cwd: __dirname }) .execSync('git rev-parse --short HEAD', { cwd: __dirname })
.toString().trim(); .toString().trim();
} }
}
catch {
// suppress exception
}
finally { finally {
response.send(`SillyTavern:${gitRevision || pkgVersion}:Cohee#1207`) response.send(`SillyTavern:${gitRevision || pkgVersion}:Cohee#1207`)
} }