mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Use simpleGit to get app version
This commit is contained in:
@ -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 {
|
||||
|
Reference in New Issue
Block a user