mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
@1.2.8:
1) Security update: https://github.com/TavernAI/TavernAI/security/advisories/GHSA-25wp-82wc-xchj 2) Fixed several bugs related to character import: now all imported characters are added to the top of the list. 3) Fixed a bug that duplicated character cards if the character name and map name did not match. 4) Made minor fixes for prompt formatting. 5) Added the ability to enable/disable TavernAI autostart in the browser through the configuration file. 6) Adapted for Pygmalion Dev.
This commit is contained in:
8
config.conf
Normal file
8
config.conf
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
const port = 8000;
|
||||||
|
const whitelist = ['127.0.0.1']; //Example for add several IP in whitelist: ['127.0.0.1', '192.168.0.10']
|
||||||
|
const whitelistMode = true; //Disabling enabling the ip whitelist mode. true/false
|
||||||
|
const autorun = true; //Autorun in the browser. true/false
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
port, whitelist, whitelistMode, autorun
|
||||||
|
};
|
@@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
"port": 8000,
|
|
||||||
"whitelist": ["127.0.0.1"],
|
|
||||||
"whitelistMode": true
|
|
||||||
}
|
|
80
package-lock.json
generated
80
package-lock.json
generated
@@ -1,13 +1,16 @@
|
|||||||
{
|
{
|
||||||
"name": "TavernAI",
|
"name": "TavernAI",
|
||||||
"version": "1.2.7",
|
"version": "1.2.8",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "TavernAI",
|
"name": "TavernAI",
|
||||||
"version": "1.2.7",
|
"version": "1.2.8",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"cookie-parser": "^1.4.6",
|
||||||
|
"cors": "^2.8.5",
|
||||||
|
"csrf-csrf": "^2.2.3",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"multer": "^1.4.5-lts.1",
|
"multer": "^1.4.5-lts.1",
|
||||||
"node-rest-client": "^3.1.1",
|
"node-rest-client": "^3.1.1",
|
||||||
@@ -283,6 +286,26 @@
|
|||||||
"node": ">= 0.6"
|
"node": ">= 0.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/cookie-parser": {
|
||||||
|
"version": "1.4.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/cookie-parser/-/cookie-parser-1.4.6.tgz",
|
||||||
|
"integrity": "sha512-z3IzaNjdwUC2olLIB5/ITd0/setiaFMLYiZJle7xg5Fe9KWAceil7xszYfHHBtDFYLSgJduS2Ty0P1uJdPDJeA==",
|
||||||
|
"dependencies": {
|
||||||
|
"cookie": "0.4.1",
|
||||||
|
"cookie-signature": "1.0.6"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.8.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/cookie-parser/node_modules/cookie": {
|
||||||
|
"version": "0.4.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.1.tgz",
|
||||||
|
"integrity": "sha512-ZwrFkGJxUR3EIoXtO+yVE69Eb7KlixbaeAWfBQB9vVsNn/o+Yw69gBWSSDK825hQNdN+wF8zELf3dFNl/kxkUA==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/cookie-signature": {
|
"node_modules/cookie-signature": {
|
||||||
"version": "1.0.6",
|
"version": "1.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
|
||||||
@@ -293,6 +316,18 @@
|
|||||||
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
|
||||||
"integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ=="
|
"integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ=="
|
||||||
},
|
},
|
||||||
|
"node_modules/cors": {
|
||||||
|
"version": "2.8.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
|
||||||
|
"integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==",
|
||||||
|
"dependencies": {
|
||||||
|
"object-assign": "^4",
|
||||||
|
"vary": "^1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.10"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/crc-32": {
|
"node_modules/crc-32": {
|
||||||
"version": "0.3.0",
|
"version": "0.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/crc-32/-/crc-32-0.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/crc-32/-/crc-32-0.3.0.tgz",
|
||||||
@@ -301,6 +336,14 @@
|
|||||||
"node": ">=0.8"
|
"node": ">=0.8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/csrf-csrf": {
|
||||||
|
"version": "2.2.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/csrf-csrf/-/csrf-csrf-2.2.3.tgz",
|
||||||
|
"integrity": "sha512-ph3Mt9Bn0IBe2hhm/HBFLAey9NjY+IFPj3RLiK76XBE196HGJrr0Emh3DllhwJtpW93YY0trW3qFyMRlpgPwTQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"http-errors": "^2.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/debug": {
|
"node_modules/debug": {
|
||||||
"version": "4.3.4",
|
"version": "4.3.4",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
||||||
@@ -1689,6 +1732,22 @@
|
|||||||
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.5.0.tgz",
|
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.5.0.tgz",
|
||||||
"integrity": "sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw=="
|
"integrity": "sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw=="
|
||||||
},
|
},
|
||||||
|
"cookie-parser": {
|
||||||
|
"version": "1.4.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/cookie-parser/-/cookie-parser-1.4.6.tgz",
|
||||||
|
"integrity": "sha512-z3IzaNjdwUC2olLIB5/ITd0/setiaFMLYiZJle7xg5Fe9KWAceil7xszYfHHBtDFYLSgJduS2Ty0P1uJdPDJeA==",
|
||||||
|
"requires": {
|
||||||
|
"cookie": "0.4.1",
|
||||||
|
"cookie-signature": "1.0.6"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"cookie": {
|
||||||
|
"version": "0.4.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.1.tgz",
|
||||||
|
"integrity": "sha512-ZwrFkGJxUR3EIoXtO+yVE69Eb7KlixbaeAWfBQB9vVsNn/o+Yw69gBWSSDK825hQNdN+wF8zELf3dFNl/kxkUA=="
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"cookie-signature": {
|
"cookie-signature": {
|
||||||
"version": "1.0.6",
|
"version": "1.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
|
||||||
@@ -1699,11 +1758,28 @@
|
|||||||
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
|
||||||
"integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ=="
|
"integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ=="
|
||||||
},
|
},
|
||||||
|
"cors": {
|
||||||
|
"version": "2.8.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
|
||||||
|
"integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==",
|
||||||
|
"requires": {
|
||||||
|
"object-assign": "^4",
|
||||||
|
"vary": "^1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"crc-32": {
|
"crc-32": {
|
||||||
"version": "0.3.0",
|
"version": "0.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/crc-32/-/crc-32-0.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/crc-32/-/crc-32-0.3.0.tgz",
|
||||||
"integrity": "sha512-kucVIjOmMc1f0tv53BJ/5WIX+MGLcKuoBhnGqQrgKJNqLByb/sVMWfW/Aw6hw0jgcqjJ2pi9E5y32zOIpaUlsA=="
|
"integrity": "sha512-kucVIjOmMc1f0tv53BJ/5WIX+MGLcKuoBhnGqQrgKJNqLByb/sVMWfW/Aw6hw0jgcqjJ2pi9E5y32zOIpaUlsA=="
|
||||||
},
|
},
|
||||||
|
"csrf-csrf": {
|
||||||
|
"version": "2.2.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/csrf-csrf/-/csrf-csrf-2.2.3.tgz",
|
||||||
|
"integrity": "sha512-ph3Mt9Bn0IBe2hhm/HBFLAey9NjY+IFPj3RLiK76XBE196HGJrr0Emh3DllhwJtpW93YY0trW3qFyMRlpgPwTQ==",
|
||||||
|
"requires": {
|
||||||
|
"http-errors": "^2.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"debug": {
|
"debug": {
|
||||||
"version": "4.3.4",
|
"version": "4.3.4",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
||||||
|
@@ -14,7 +14,7 @@
|
|||||||
"cors": "^2.8.5"
|
"cors": "^2.8.5"
|
||||||
},
|
},
|
||||||
"name": "TavernAI",
|
"name": "TavernAI",
|
||||||
"version": "1.2.7",
|
"version": "1.2.8",
|
||||||
"bin": {
|
"bin": {
|
||||||
"TavernAI": "server.js"
|
"TavernAI": "server.js"
|
||||||
},
|
},
|
||||||
|
@@ -25,7 +25,7 @@
|
|||||||
<script type=module>
|
<script type=module>
|
||||||
import {encode, decode} from "../scripts/gpt-2-3-tokenizer/mod.js";
|
import {encode, decode} from "../scripts/gpt-2-3-tokenizer/mod.js";
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
const VERSION = '1.2.7';
|
const VERSION = '1.2.8';
|
||||||
var converter = new showdown.Converter();
|
var converter = new showdown.Converter();
|
||||||
var bg_menu_toggle = false;
|
var bg_menu_toggle = false;
|
||||||
var default_user_name = "You";
|
var default_user_name = "You";
|
||||||
@@ -317,7 +317,7 @@
|
|||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"X-CSRF-Token": token,
|
"X-CSRF-Token": token
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
"": ""
|
"": ""
|
||||||
@@ -339,7 +339,6 @@
|
|||||||
}
|
}
|
||||||
characters.sort((a,b) => a.create_date - b.create_date );
|
characters.sort((a,b) => a.create_date - b.create_date );
|
||||||
//characters.reverse();
|
//characters.reverse();
|
||||||
|
|
||||||
if(this_chid != undefined) $("#avatar_url_pole").val(characters[this_chid].avatar);
|
if(this_chid != undefined) $("#avatar_url_pole").val(characters[this_chid].avatar);
|
||||||
printCharaters();
|
printCharaters();
|
||||||
//console.log(propOwn.length);
|
//console.log(propOwn.length);
|
||||||
@@ -834,7 +833,7 @@
|
|||||||
is_add_personality = true;
|
is_add_personality = true;
|
||||||
//chatString = chatString.substr(0,chatString.length-1);
|
//chatString = chatString.substr(0,chatString.length-1);
|
||||||
//anchorAndPersonality = "[Genre: roleplay chat][Tone: very long messages with descriptions]";
|
//anchorAndPersonality = "[Genre: roleplay chat][Tone: very long messages with descriptions]";
|
||||||
if(anchorTop != "" || charPersonality != ""){
|
if((anchorTop != "" || charPersonality != "") && !is_pygmalion){
|
||||||
if(anchorTop != "") charPersonality+=' ';
|
if(anchorTop != "") charPersonality+=' ';
|
||||||
item+="["+charPersonality+anchorTop+']\n';
|
item+="["+charPersonality+anchorTop+']\n';
|
||||||
}
|
}
|
||||||
@@ -1020,7 +1019,7 @@
|
|||||||
if(is_pygmalion){
|
if(is_pygmalion){
|
||||||
if_typing_text = false;
|
if_typing_text = false;
|
||||||
message_already_generated +=getMessage;
|
message_already_generated +=getMessage;
|
||||||
if(message_already_generated.indexOf('You:') === -1 && tokens_already_generated < parseInt(amount_gen)){
|
if(message_already_generated.indexOf('You:') === -1 && tokens_already_generated < parseInt(amount_gen) && getMessage.length > 0){
|
||||||
runGenerate(getMessage);
|
runGenerate(getMessage);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
50
server.js
50
server.js
@@ -20,10 +20,11 @@ const cookieParser = require('cookie-parser');
|
|||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
|
|
||||||
|
|
||||||
const config = require('./config.json');
|
const config = require('./config.conf');
|
||||||
const server_port = config.port;
|
const server_port = config.port;
|
||||||
const whitelist = config.whitelist;
|
const whitelist = config.whitelist;
|
||||||
const whitelistMode = config.whitelistMode;
|
const whitelistMode = config.whitelistMode;
|
||||||
|
const autorun = config.autorun;
|
||||||
|
|
||||||
var Client = require('node-rest-client').Client;
|
var Client = require('node-rest-client').Client;
|
||||||
var client = new Client();
|
var client = new Client();
|
||||||
@@ -69,7 +70,7 @@ const { invalidCsrfTokenError, generateToken, doubleCsrfProtection } = doubleCsr
|
|||||||
cookieName: "X-CSRF-Token",
|
cookieName: "X-CSRF-Token",
|
||||||
cookieOptions: {
|
cookieOptions: {
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
sameSite: "strict",
|
sameSite: "strict"
|
||||||
},
|
},
|
||||||
size: 64,
|
size: 64,
|
||||||
getTokenFromRequest: (req) => req.headers["x-csrf-token"]
|
getTokenFromRequest: (req) => req.headers["x-csrf-token"]
|
||||||
@@ -89,15 +90,15 @@ const cors = require('cors');
|
|||||||
const CORS = cors({
|
const CORS = cors({
|
||||||
origin: 'null',
|
origin: 'null',
|
||||||
methods: ['OPTIONS']
|
methods: ['OPTIONS']
|
||||||
})
|
});
|
||||||
|
|
||||||
app.use(CORS);
|
app.use(CORS);
|
||||||
|
|
||||||
app.use(function (req, res, next) { //Security
|
app.use(function (req, res, next) { //Security
|
||||||
const clientIp = req.connection.remoteAddress.split(':').pop();
|
const clientIp = req.connection.remoteAddress.split(':').pop();
|
||||||
if (whitelistMode === true && !whitelist.includes(clientIp)) {
|
if (whitelistMode === true && !whitelist.includes(clientIp)) {
|
||||||
console.log('Forbidden: Connection attempt from '+ clientIp+'. If you are attempting to connect, please add your IP address in whitelist or disable whitelist mode in config.json in root of TavernAI folder.\nExample for add several IP in whitelist: "whitelist": ["127.0.0.1", "'+ clientIp+'"]\nExample for disable whitelist mode: "whitelistMode": false');
|
console.log('Forbidden: Connection attempt from '+ clientIp+'. If you are attempting to connect, please add your IP address in whitelist or disable whitelist mode in config.conf in root of TavernAI folder.\n');
|
||||||
return res.status(403).send('<b>Forbidden</b>: Connection attempt from <b>'+ clientIp+'</b>. If you are attempting to connect, please add your IP address in whitelist or disable whitelist mode in config.json in root of TavernAI folder.<br>Example for add several IP in whitelist: "whitelist": ["127.0.0.1", "'+ clientIp+'"]<br>Example for disable whitelist mode: "whitelistMode": false');
|
return res.status(403).send('<b>Forbidden</b>: Connection attempt from <b>'+ clientIp+'</b>. If you are attempting to connect, please add your IP address in whitelist or disable whitelist mode in config.conf in root of TavernAI folder.');
|
||||||
}
|
}
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
@@ -433,17 +434,18 @@ app.post("/editcharacter", urlencodedParser, function(request, response){
|
|||||||
var char = charaFormatData(request.body);//{"name": request.body.ch_name, "description": request.body.description, "personality": request.body.personality, "first_mes": request.body.first_mes, "avatar": request.body.avatar_url, "chat": request.body.chat, "last_mes": request.body.last_mes, "mes_example": ''};
|
var char = charaFormatData(request.body);//{"name": request.body.ch_name, "description": request.body.description, "personality": request.body.personality, "first_mes": request.body.first_mes, "avatar": request.body.avatar_url, "chat": request.body.chat, "last_mes": request.body.last_mes, "mes_example": ''};
|
||||||
char.chat = request.body.chat;
|
char.chat = request.body.chat;
|
||||||
char.create_date = request.body.create_date;
|
char.create_date = request.body.create_date;
|
||||||
|
|
||||||
char = JSON.stringify(char);
|
char = JSON.stringify(char);
|
||||||
|
let target_img = (request.body.avatar_url).replace('.png', '');
|
||||||
if(!filedata){
|
if(!filedata){
|
||||||
|
|
||||||
charaWrite(img_path+request.body.avatar_url, char, request.body.ch_name, response, 'Character saved');
|
charaWrite(img_path+request.body.avatar_url, char, target_img, response, 'Character saved');
|
||||||
}else{
|
}else{
|
||||||
//console.log(filedata.filename);
|
//console.log(filedata.filename);
|
||||||
img_path = "uploads/";
|
img_path = "uploads/";
|
||||||
img_file = filedata.filename;
|
img_file = filedata.filename;
|
||||||
|
|
||||||
charaWrite(img_path+img_file, char, request.body.ch_name, response, 'Character saved');
|
charaWrite(img_path+img_file, char, target_img, response, 'Character saved');
|
||||||
//response.send('Character saved');
|
//response.send('Character saved');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -470,7 +472,7 @@ app.post("/deletecharacter", urlencodedParser, function(request, response){
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
async function charaWrite(img_url, data, name, response = undefined, mes = 'ok'){
|
async function charaWrite(img_url, data, target_img, response = undefined, mes = 'ok'){
|
||||||
try {
|
try {
|
||||||
// Load the image in any format
|
// Load the image in any format
|
||||||
sharp.cache(false);
|
sharp.cache(false);
|
||||||
@@ -483,7 +485,7 @@ async function charaWrite(img_url, data, name, response = undefined, mes = 'ok')
|
|||||||
|
|
||||||
// Get the chunks
|
// Get the chunks
|
||||||
var chunks = extract(image);
|
var chunks = extract(image);
|
||||||
var tEXtChunks = chunks.filter(chunk => chunk.name === 'tEXt');
|
var tEXtChunks = chunks.filter(chunk => chunk.create_date === 'tEXt');
|
||||||
|
|
||||||
// Remove all existing tEXt chunks
|
// Remove all existing tEXt chunks
|
||||||
for (var tEXtChunk of tEXtChunks) {
|
for (var tEXtChunk of tEXtChunks) {
|
||||||
@@ -494,7 +496,7 @@ async function charaWrite(img_url, data, name, response = undefined, mes = 'ok')
|
|||||||
chunks.splice(-1, 0, PNGtext.encode('chara', base64EncodedData));
|
chunks.splice(-1, 0, PNGtext.encode('chara', base64EncodedData));
|
||||||
//chunks.splice(-1, 0, text.encode('lorem', 'ipsum'));
|
//chunks.splice(-1, 0, text.encode('lorem', 'ipsum'));
|
||||||
|
|
||||||
fs.writeFileSync(charactersPath+name+'.png', new Buffer.from(encode(chunks)));
|
fs.writeFileSync(charactersPath+target_img+'.png', new Buffer.from(encode(chunks)));
|
||||||
if(response !== undefined) response.send(mes);
|
if(response !== undefined) response.send(mes);
|
||||||
|
|
||||||
|
|
||||||
@@ -925,8 +927,11 @@ app.post("/getallchatsofchatacter", jsonParser, function(request, response){
|
|||||||
|
|
||||||
});
|
});
|
||||||
function getPngName(file){
|
function getPngName(file){
|
||||||
if (fs.existsSync(charactersPath+file+'.png')) {
|
let i = 1;
|
||||||
file = file+'1';
|
let base_name = file;
|
||||||
|
while (fs.existsSync(charactersPath+file+'.png')) {
|
||||||
|
file = base_name+i;
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
@@ -949,12 +954,12 @@ app.post("/importcharacter", urlencodedParser, function(request, response){
|
|||||||
|
|
||||||
if(jsonData.name !== undefined){
|
if(jsonData.name !== undefined){
|
||||||
png_name = getPngName(jsonData.name);
|
png_name = getPngName(jsonData.name);
|
||||||
var char = {"name": jsonData.name, "description": jsonData.description ?? '', "personality": jsonData.personality ?? '', "first_mes": jsonData.first_mes ?? '', "avatar": 'none', "chat": Date.now(), "mes_example": jsonData.mes_example ?? '', "scenario": jsonData.scenario ?? '', "create_date": Date.now()};
|
let char = {"name": jsonData.name, "description": jsonData.description ?? '', "personality": jsonData.personality ?? '', "first_mes": jsonData.first_mes ?? '', "avatar": 'none', "chat": Date.now(), "mes_example": jsonData.mes_example ?? '', "scenario": jsonData.scenario ?? '', "create_date": Date.now()};
|
||||||
char = JSON.stringify(char);
|
char = JSON.stringify(char);
|
||||||
charaWrite('./public/img/fluffy.png', char, png_name, response, {file_name: png_name});
|
charaWrite('./public/img/fluffy.png', char, png_name, response, {file_name: png_name});
|
||||||
}else if(jsonData.char_name !== undefined){//json Pygmalion notepad
|
}else if(jsonData.char_name !== undefined){//json Pygmalion notepad
|
||||||
png_name = getPngName(jsonData.char_name);
|
png_name = getPngName(jsonData.char_name);
|
||||||
var char = {"name": jsonData.char_name, "description": jsonData.char_persona ?? '', "personality": '', "first_mes": jsonData.char_greeting ?? '', "avatar": 'none', "chat": Date.now(), "mes_example": jsonData.example_dialogue ?? '', "scenario": jsonData.world_scenario ?? '', "create_date": Date.now()};
|
let char = {"name": jsonData.char_name, "description": jsonData.char_persona ?? '', "personality": '', "first_mes": jsonData.char_greeting ?? '', "avatar": 'none', "chat": Date.now(), "mes_example": jsonData.example_dialogue ?? '', "scenario": jsonData.world_scenario ?? '', "create_date": Date.now()};
|
||||||
char = JSON.stringify(char);
|
char = JSON.stringify(char);
|
||||||
charaWrite('./public/img/fluffy.png', char, png_name, response, {file_name: png_name});
|
charaWrite('./public/img/fluffy.png', char, png_name, response, {file_name: png_name});
|
||||||
}else{
|
}else{
|
||||||
@@ -966,9 +971,14 @@ app.post("/importcharacter", urlencodedParser, function(request, response){
|
|||||||
try{
|
try{
|
||||||
|
|
||||||
var img_data = charaRead('./uploads/'+filedata.filename);
|
var img_data = charaRead('./uploads/'+filedata.filename);
|
||||||
let jsonObject = JSON.parse(img_data);
|
let jsonData = JSON.parse(img_data);
|
||||||
png_name = getPngName(jsonObject.name);
|
png_name = getPngName(jsonData.name);
|
||||||
if(jsonObject.name !== undefined){
|
|
||||||
|
if(jsonData.name !== undefined){
|
||||||
|
let char = {"name": jsonData.name, "description": jsonData.description ?? '', "personality": jsonData.personality ?? '', "first_mes": jsonData.first_mes ?? '', "avatar": 'none', "chat": Date.now(), "mes_example": jsonData.mes_example ?? '', "scenario": jsonData.scenario ?? '', "create_date": Date.now()};
|
||||||
|
char = JSON.stringify(char);
|
||||||
|
charaWrite('./uploads/'+filedata.filename, char, png_name, response, {file_name: png_name});
|
||||||
|
/*
|
||||||
fs.copyFile('./uploads/'+filedata.filename, charactersPath+png_name+'.png', (err) => {
|
fs.copyFile('./uploads/'+filedata.filename, charactersPath+png_name+'.png', (err) => {
|
||||||
if(err) {
|
if(err) {
|
||||||
response.send({error:true});
|
response.send({error:true});
|
||||||
@@ -978,7 +988,7 @@ app.post("/importcharacter", urlencodedParser, function(request, response){
|
|||||||
response.send({file_name: png_name});
|
response.send({file_name: png_name});
|
||||||
}
|
}
|
||||||
//console.log('The image was copied from temp directory.');
|
//console.log('The image was copied from temp directory.');
|
||||||
});
|
});*/
|
||||||
}
|
}
|
||||||
}catch(err){
|
}catch(err){
|
||||||
console.log(err);
|
console.log(err);
|
||||||
@@ -1103,7 +1113,7 @@ app.listen(server_port, function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log('Launching...');
|
console.log('Launching...');
|
||||||
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);
|
console.log('TavernAI started: http://127.0.0.1:'+server_port);
|
||||||
if (fs.existsSync('public/characters/update.txt') && !is_colab) {
|
if (fs.existsSync('public/characters/update.txt') && !is_colab) {
|
||||||
convertStage1();
|
convertStage1();
|
||||||
|
Reference in New Issue
Block a user