Use simpleGit to get app version
This commit is contained in:
parent
dc1121b72a
commit
11e7ca76e1
|
@ -25,7 +25,6 @@
|
|||
"ip-matching": "^2.1.2",
|
||||
"ipaddr.js": "^2.0.1",
|
||||
"jimp": "^0.22.10",
|
||||
"jquery": "^3.6.4",
|
||||
"json5": "^2.2.3",
|
||||
"lodash": "^4.17.21",
|
||||
"mime-types": "^2.1.35",
|
||||
|
@ -39,7 +38,6 @@
|
|||
"sanitize-filename": "^1.6.3",
|
||||
"sillytavern-transformers": "^2.7.3",
|
||||
"simple-git": "^3.19.1",
|
||||
"uniqolor": "^1.1.0",
|
||||
"vectra": "^0.2.2",
|
||||
"write-file-atomic": "^5.0.1",
|
||||
"ws": "^8.13.0",
|
||||
|
@ -50,6 +48,7 @@
|
|||
"sillytavern": "server.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"jquery": "^3.6.4",
|
||||
"pkg": "^5.8.1",
|
||||
"pkg-fetch": "^3.5.2"
|
||||
}
|
||||
|
@ -2182,7 +2181,8 @@
|
|||
"node_modules/jquery": {
|
||||
"version": "3.7.0",
|
||||
"resolved": "https://registry.npmjs.org/jquery/-/jquery-3.7.0.tgz",
|
||||
"integrity": "sha512-umpJ0/k8X0MvD1ds0P9SfowREz2LenHsQaxSohMZ5OMNEU2r0tf8pdeEFTHMFxWVxKNyU9rTtK3CWzUCTKJUeQ=="
|
||||
"integrity": "sha512-umpJ0/k8X0MvD1ds0P9SfowREz2LenHsQaxSohMZ5OMNEU2r0tf8pdeEFTHMFxWVxKNyU9rTtK3CWzUCTKJUeQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/jsesc": {
|
||||
"version": "2.5.2",
|
||||
|
@ -3790,11 +3790,6 @@
|
|||
"resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz",
|
||||
"integrity": "sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA=="
|
||||
},
|
||||
"node_modules/uniqolor": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/uniqolor/-/uniqolor-1.1.0.tgz",
|
||||
"integrity": "sha512-j2XyokF24fsj+L5u6fbu4rM3RQc6VWJuAngYM2k0ZdG3yiVxt0smLkps2GmQIYqK8VkELGdM9vFU/HfOkK/zoQ=="
|
||||
},
|
||||
"node_modules/universalify": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz",
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
"ip-matching": "^2.1.2",
|
||||
"ipaddr.js": "^2.0.1",
|
||||
"jimp": "^0.22.10",
|
||||
"jquery": "^3.6.4",
|
||||
"json5": "^2.2.3",
|
||||
"lodash": "^4.17.21",
|
||||
"mime-types": "^2.1.35",
|
||||
|
@ -29,7 +28,6 @@
|
|||
"sanitize-filename": "^1.6.3",
|
||||
"sillytavern-transformers": "^2.7.3",
|
||||
"simple-git": "^3.19.1",
|
||||
"uniqolor": "^1.1.0",
|
||||
"vectra": "^0.2.2",
|
||||
"write-file-atomic": "^5.0.1",
|
||||
"ws": "^8.13.0",
|
||||
|
@ -78,6 +76,7 @@
|
|||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"jquery": "^3.6.4",
|
||||
"pkg": "^5.8.1",
|
||||
"pkg-fetch": "^3.5.2"
|
||||
}
|
||||
|
|
|
@ -309,8 +309,8 @@ app.get('/deviceinfo', function (request, response) {
|
|||
const deviceInfo = deviceDetector.parse(userAgent || "");
|
||||
return response.send(deviceInfo);
|
||||
});
|
||||
app.get('/version', function (_, response) {
|
||||
const data = getVersion();
|
||||
app.get('/version', async function (_, response) {
|
||||
const data = await getVersion();
|
||||
response.send(data);
|
||||
})
|
||||
|
||||
|
@ -3255,7 +3255,7 @@ const autorunUrl = new URL(
|
|||
);
|
||||
|
||||
const setupTasks = async function () {
|
||||
const version = getVersion();
|
||||
const version = await getVersion();
|
||||
|
||||
console.log(`SillyTavern ${version.pkgVersion}` + (version.gitBranch ? ` '${version.gitBranch}' (${version.gitRevision})` : ''));
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const simpleGit = require('simple-git');
|
||||
const { default: simpleGit } = require('simple-git');
|
||||
const sanitize = require('sanitize-filename');
|
||||
const { DIRECTORIES } = require('./constants');
|
||||
|
||||
|
@ -27,7 +27,6 @@ async function getManifest(extensionPath) {
|
|||
* @returns {Promise<Object>} - Returns the extension information as an object
|
||||
*/
|
||||
async function checkIfRepoIsUpToDate(extensionPath) {
|
||||
// @ts-ignore - simple-git types are incorrect, this is apparently callable but no call signature
|
||||
const git = simpleGit();
|
||||
await git.cwd(extensionPath).fetch('origin');
|
||||
const currentBranch = await git.cwd(extensionPath).branch();
|
||||
|
@ -62,7 +61,6 @@ function registerEndpoints(app, jsonParser) {
|
|||
* @returns {void}
|
||||
*/
|
||||
app.post('/api/extensions/install', jsonParser, async (request, response) => {
|
||||
// @ts-ignore - simple-git types are incorrect, this is apparently callable but no call signature
|
||||
const git = simpleGit();
|
||||
if (!request.body.url) {
|
||||
return response.status(400).send('Bad Request: URL is required in the request body.');
|
||||
|
@ -108,7 +106,6 @@ function registerEndpoints(app, jsonParser) {
|
|||
* @returns {void}
|
||||
*/
|
||||
app.post('/api/extensions/update', jsonParser, async (request, response) => {
|
||||
// @ts-ignore - simple-git types are incorrect, this is apparently callable but no call signature
|
||||
const git = simpleGit();
|
||||
if (!request.body.extensionName) {
|
||||
return response.status(400).send('Bad Request: extensionName is required in the request body.');
|
||||
|
@ -154,7 +151,6 @@ function registerEndpoints(app, jsonParser) {
|
|||
* @returns {void}
|
||||
*/
|
||||
app.post('/api/extensions/version', jsonParser, async (request, response) => {
|
||||
// @ts-ignore - simple-git types are incorrect, this is apparently callable but no call signature
|
||||
const git = simpleGit();
|
||||
if (!request.body.extensionName) {
|
||||
return response.status(400).send('Bad Request: extensionName is required in the request body.');
|
||||
|
|
17
src/horde.js
17
src/horde.js
|
@ -5,9 +5,14 @@ const { readSecret, SECRET_KEYS } = require("./secrets");
|
|||
|
||||
const ANONYMOUS_KEY = "0000000000";
|
||||
|
||||
function getHordeClient() {
|
||||
/**
|
||||
* Returns the AIHorde client.
|
||||
* @returns {Promise<AIHorde>} AIHorde client
|
||||
*/
|
||||
async function getHordeClient() {
|
||||
const version = await getVersion();
|
||||
const ai_horde = new AIHorde({
|
||||
client_agent: getVersion()?.agent || 'SillyTavern:UNKNOWN:Cohee#1207',
|
||||
client_agent: version?.agent || 'SillyTavern:UNKNOWN:Cohee#1207',
|
||||
});
|
||||
return ai_horde;
|
||||
}
|
||||
|
@ -50,7 +55,7 @@ function registerEndpoints(app, jsonParser) {
|
|||
|
||||
app.post('/api/horde/sd-samplers', jsonParser, async (_, response) => {
|
||||
try {
|
||||
const ai_horde = getHordeClient();
|
||||
const ai_horde = await getHordeClient();
|
||||
const samplers = Object.values(ai_horde.ModelGenerationInputStableSamplers);
|
||||
response.send(samplers);
|
||||
} catch (error) {
|
||||
|
@ -61,7 +66,7 @@ function registerEndpoints(app, jsonParser) {
|
|||
|
||||
app.post('/api/horde/sd-models', jsonParser, async (_, response) => {
|
||||
try {
|
||||
const ai_horde = getHordeClient();
|
||||
const ai_horde = await getHordeClient();
|
||||
const models = await ai_horde.getModels();
|
||||
response.send(models);
|
||||
} catch (error) {
|
||||
|
@ -78,7 +83,7 @@ function registerEndpoints(app, jsonParser) {
|
|||
}
|
||||
|
||||
try {
|
||||
const ai_horde = getHordeClient();
|
||||
const ai_horde = await getHordeClient();
|
||||
const user = await ai_horde.findUser({ token: api_key_horde });
|
||||
return response.send(user);
|
||||
} catch (error) {
|
||||
|
@ -106,7 +111,7 @@ function registerEndpoints(app, jsonParser) {
|
|||
const api_key_horde = readSecret(SECRET_KEYS.HORDE) || ANONYMOUS_KEY;
|
||||
console.log('Stable Horde request:', request.body);
|
||||
|
||||
const ai_horde = getHordeClient();
|
||||
const ai_horde = await getHordeClient();
|
||||
const generation = await ai_horde.postAsyncImageGenerate(
|
||||
{
|
||||
prompt: `${request.body.prompt} ### ${request.body.negative_prompt}`,
|
||||
|
|
16
src/util.js
16
src/util.js
|
@ -1,10 +1,10 @@
|
|||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const child_process = require('child_process');
|
||||
const commandExistsSync = require('command-exists').sync;
|
||||
const _ = require('lodash');
|
||||
const yauzl = require('yauzl');
|
||||
const mime = require('mime-types');
|
||||
const { default: simpleGit } = require('simple-git');
|
||||
|
||||
/**
|
||||
* Returns the config object from the config.conf file.
|
||||
|
@ -44,9 +44,9 @@ function getBasicAuthHeader(auth) {
|
|||
/**
|
||||
* Returns the version of the running instance. Get the version from the package.json file and the git revision.
|
||||
* Also returns the agent string for the Horde API.
|
||||
* @returns {{agent: string, pkgVersion: string, gitRevision: string | null, gitBranch: string | null}} Version info object
|
||||
* @returns {Promise<{agent: string, pkgVersion: string, gitRevision: string | null, gitBranch: string | null}>} Version info object
|
||||
*/
|
||||
function getVersion() {
|
||||
async function getVersion() {
|
||||
let pkgVersion = 'UNKNOWN';
|
||||
let gitRevision = null;
|
||||
let gitBranch = null;
|
||||
|
@ -54,13 +54,9 @@ function getVersion() {
|
|||
const pkgJson = require(path.join(process.cwd(), './package.json'));
|
||||
pkgVersion = pkgJson.version;
|
||||
if (!process['pkg'] && commandExistsSync('git')) {
|
||||
gitRevision = child_process
|
||||
.execSync('git rev-parse --short HEAD', { cwd: process.cwd(), stdio: ['ignore', 'pipe', 'ignore'] })
|
||||
.toString().trim();
|
||||
|
||||
gitBranch = child_process
|
||||
.execSync('git rev-parse --abbrev-ref HEAD', { cwd: process.cwd(), stdio: ['ignore', 'pipe', 'ignore'] })
|
||||
.toString().trim();
|
||||
const git = simpleGit();
|
||||
gitRevision = await git.cwd(process.cwd()).revparse(['--short', 'HEAD']);
|
||||
gitBranch = await git.cwd(process.cwd()).revparse(['--abbrev-ref', 'HEAD']);
|
||||
}
|
||||
}
|
||||
catch {
|
||||
|
|
Loading…
Reference in New Issue