Merge branch 'main' into dev

This commit is contained in:
SillyLossy
2023-04-07 00:34:27 +03:00
8 changed files with 407 additions and 176 deletions

View File

@@ -22,7 +22,7 @@ const crypto = require('crypto');
const ipaddr = require('ipaddr.js');
const config = require(path.join(process.cwd(), './config.conf'));
const server_port = config.port;
const server_port = process.env.SILLY_TAVERN_PORT || config.port;
const whitelist = config.whitelist;
const whitelistMode = config.whitelistMode;
const autorun = config.autorun;
@@ -87,13 +87,9 @@ function humanizedISO8601DateTime() {
return HumanizedDateTime;
};
var is_colab = false;
var is_colab = process.env.colaburl !== undefined;
var charactersPath = 'public/characters/';
var chatsPath = 'public/chats/';
if (is_colab && process.env.googledrive == 2) {
charactersPath = '/content/drive/MyDrive/TavernAI/characters/';
chatsPath = '/content/drive/MyDrive/TavernAI/chats/';
}
const jsonParser = express.json({ limit: '100mb' });
const urlencodedParser = express.urlencoded({ extended: true, limit: '100mb' });
const baseRequestArgs = { headers: { "Content-Type": "application/json" } };
@@ -174,9 +170,11 @@ app.use((req, res, next) => {
if (req.url.startsWith('/characters/') && is_colab && process.env.googledrive == 2) {
const filePath = path.join(charactersPath, decodeURIComponent(req.url.substr('/characters'.length)));
console.log('req.url: ' + req.url);
console.log(filePath);
fs.access(filePath, fs.constants.R_OK, (err) => {
if (!err) {
res.sendFile(filePath);
res.sendFile(filePath, { root: __dirname });
} else {
res.send('Character not found: ' + filePath);
//next();
@@ -736,16 +734,13 @@ app.post("/getcharacters", jsonParser, function (request, response) {
});
app.post("/getbackgrounds", jsonParser, function (request, response) {
var images = getImages("public/backgrounds");
if (is_colab === true) {
images = ['tavern.png'];
}
response.send(JSON.stringify(images));
});
app.post("/iscolab", jsonParser, function (request, response) {
let send_data = false;
if (process.env.colaburl !== undefined) {
send_data = String(process.env.colaburl).trim();
if (is_colab) {
send_data = String(process.env.colaburl).trim();
}
response.send({ colaburl: send_data });
@@ -1999,15 +1994,10 @@ function getAsync(url, args) {
// ** END **
app.listen(server_port, (listen ? '0.0.0.0' : '127.0.0.1'), async function () {
if (process.env.colab !== undefined) {
if (process.env.colab == 2) {
is_colab = true;
}
}
ensurePublicDirectoriesExist();
await ensureThumbnailCache();
console.log('Launching...');
if (autorun) open('http:127.0.0.1:' + server_port);
if (autorun) open('http://127.0.0.1:' + server_port);
console.log('TavernAI started: http://127.0.0.1:' + server_port);
if (fs.existsSync('public/characters/update.txt') && !is_colab) {
convertStage1();