Merge branch 'release' into staging

This commit is contained in:
Cohee 2023-08-26 22:07:06 +03:00
commit 4998c3acc8
1 changed files with 22 additions and 19 deletions

View File

@ -152,7 +152,6 @@ let main_api = "kobold";
let response_generate_novel; let response_generate_novel;
let characters = {}; let characters = {};
let response_dw_bg; let response_dw_bg;
let response_getstatus;
let first_run = true; let first_run = true;
@ -776,14 +775,15 @@ app.post("/getchat", jsonParser, function (request, response) {
} }
}); });
app.post("/getstatus", jsonParser, async function (request, response_getstatus = response) { app.post("/getstatus", jsonParser, async function (request, response) {
if (!request.body) return response_getstatus.sendStatus(400); if (!request.body) return response.sendStatus(400);
api_server = request.body.api_server; api_server = request.body.api_server;
main_api = request.body.main_api; main_api = request.body.main_api;
if (api_server.indexOf('localhost') != -1) { if (api_server.indexOf('localhost') != -1) {
api_server = api_server.replace('localhost', '127.0.0.1'); api_server = api_server.replace('localhost', '127.0.0.1');
} }
var args = {
const args = {
headers: { "Content-Type": "application/json" } headers: { "Content-Type": "application/json" }
}; };
@ -791,9 +791,10 @@ app.post("/getstatus", jsonParser, async function (request, response_getstatus =
args.headers = Object.assign(args.headers, get_mancer_headers()); args.headers = Object.assign(args.headers, get_mancer_headers());
} }
var url = api_server + "/v1/model"; const url = api_server + "/v1/model";
let version = ''; let version = '';
let koboldVersion = {}; let koboldVersion = {};
if (main_api == "kobold") { if (main_api == "kobold") {
try { try {
version = (await getAsync(api_server + "/v1/info/version")).result; version = (await getAsync(api_server + "/v1/info/version")).result;
@ -811,24 +812,26 @@ app.post("/getstatus", jsonParser, async function (request, response_getstatus =
}; };
} }
} }
client.get(url, args, async function (data, response) {
if (typeof data !== 'object') { try {
let data = await getAsync(url, args);
if (!data || typeof data !== 'object') {
data = {}; data = {};
} }
if (response.statusCode == 200) {
data.version = version;
data.koboldVersion = koboldVersion;
if (data.result == "ReadOnly") { if (data.result == "ReadOnly") {
data.result = "no_connection"; data.result = "no_connection";
} }
} else {
data.response = data.result; data.version = version;
data.result = "no_connection"; data.koboldVersion = koboldVersion;
return response.send(data);
} catch (error) {
console.log(error);
return response.send({ result: "no_connection" });
} }
response_getstatus.send(data);
}).on('error', function () {
response_getstatus.send({ result: "no_connection" });
});
}); });
function getVersion() { function getVersion() {