mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
#362 Fix card chat name sanitation
This commit is contained in:
@ -833,6 +833,13 @@ async function getCharacters() {
|
|||||||
characters[i] = [];
|
characters[i] = [];
|
||||||
characters[i] = getData[i];
|
characters[i] = getData[i];
|
||||||
characters[i]['name'] = DOMPurify.sanitize(characters[i]['name']);
|
characters[i]['name'] = DOMPurify.sanitize(characters[i]['name']);
|
||||||
|
|
||||||
|
// For dropped-in cards
|
||||||
|
if (!characters[i]['chat']) {
|
||||||
|
characters[i]['chat'] = `${characters[i]['name']} - ${humanizedDateTime()}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
characters[i]['chat'] = String(characters[i]['chat']);
|
||||||
}
|
}
|
||||||
if (this_chid != undefined && this_chid != "invalid-safety-id") {
|
if (this_chid != undefined && this_chid != "invalid-safety-id") {
|
||||||
$("#avatar_url_pole").val(characters[this_chid].avatar);
|
$("#avatar_url_pole").val(characters[this_chid].avatar);
|
||||||
@ -1217,7 +1224,7 @@ function addOneMessage(mes, { type = "normal", insertAfter = null, scroll = true
|
|||||||
$(".mes_prompt").hide();
|
$(".mes_prompt").hide();
|
||||||
//console.log(itemizedPrompts);
|
//console.log(itemizedPrompts);
|
||||||
} else {
|
} else {
|
||||||
//console.log('skipping prompt data for User Message');
|
//console.log('skipping prompt data for User Message');
|
||||||
}
|
}
|
||||||
|
|
||||||
newMessage.find('.avatar img').on('error', function () {
|
newMessage.find('.avatar img').on('error', function () {
|
||||||
|
96
server.js
96
server.js
@ -515,65 +515,51 @@ app.post("/generate_textgenerationwebui", jsonParser, async function (request, r
|
|||||||
|
|
||||||
|
|
||||||
app.post("/savechat", jsonParser, function (request, response) {
|
app.post("/savechat", jsonParser, function (request, response) {
|
||||||
var dir_name = String(request.body.avatar_url).replace('.png', '');
|
try {
|
||||||
let chat_data = request.body.chat;
|
var dir_name = String(request.body.avatar_url).replace('.png', '');
|
||||||
let jsonlData = chat_data.map(JSON.stringify).join('\n');
|
let chat_data = request.body.chat;
|
||||||
fs.writeFile(`${chatsPath + dir_name}/${sanitize(request.body.file_name)}.jsonl`, jsonlData, 'utf8', function (err) {
|
let jsonlData = chat_data.map(JSON.stringify).join('\n');
|
||||||
if (err) {
|
fs.writeFileSync(`${chatsPath + dir_name}/${sanitize(String(request.body.file_name))}.jsonl`, jsonlData, 'utf8');
|
||||||
response.send(err);
|
return response.send({ result: "ok" });
|
||||||
return console.log(err);
|
} catch (error) {
|
||||||
} else {
|
response.send(error);
|
||||||
response.send({ result: "ok" });
|
return console.log(error);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post("/getchat", jsonParser, function (request, response) {
|
app.post("/getchat", jsonParser, function (request, response) {
|
||||||
var dir_name = String(request.body.avatar_url).replace('.png', '');
|
try {
|
||||||
|
const dirName = String(request.body.avatar_url).replace('.png', '');
|
||||||
|
const chatDirExists = fs.existsSync(chatsPath + dirName);
|
||||||
|
|
||||||
fs.stat(chatsPath + dir_name, function (err, stat) {
|
//if no chat dir for the character is found, make one with the character name
|
||||||
|
if (!chatDirExists) {
|
||||||
if (stat === undefined) { //if no chat dir for the character is found, make one with the character name
|
fs.mkdirSync(chatsPath + dirName);
|
||||||
|
return response.send({});
|
||||||
fs.mkdirSync(chatsPath + dir_name);
|
|
||||||
response.send({});
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
|
|
||||||
if (err === null) { //if there is a dir, then read the requested file from the JSON call
|
|
||||||
|
|
||||||
fs.stat(`${chatsPath + dir_name}/${sanitize(request.body.file_name)}.jsonl`, function (err, stat) {
|
|
||||||
if (err === null) { //if no error (the file exists), read the file
|
|
||||||
if (stat !== undefined) {
|
|
||||||
fs.readFile(`${chatsPath + dir_name}/${sanitize(request.body.file_name)}.jsonl`, 'utf8', (err, data) => {
|
|
||||||
if (err) {
|
|
||||||
console.error(err);
|
|
||||||
response.send(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//console.log(data);
|
|
||||||
const lines = data.split('\n');
|
|
||||||
|
|
||||||
// Iterate through the array of strings and parse each line as JSON
|
|
||||||
const jsonData = lines.map(tryParse).filter(x => x);
|
|
||||||
response.send(jsonData);
|
|
||||||
//console.log('read the requested file')
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
response.send({});
|
|
||||||
//return console.log(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
console.error(err);
|
|
||||||
response.send({});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
|
if (!request.body.file_name) {
|
||||||
|
return response.send({});
|
||||||
|
}
|
||||||
|
|
||||||
|
const fileName = `${chatsPath + dirName}/${sanitize(String(request.body.file_name))}.jsonl`;
|
||||||
|
const chatFileExists = fs.existsSync(fileName);
|
||||||
|
|
||||||
|
if (!chatFileExists) {
|
||||||
|
return response.send({});
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = fs.readFileSync(fileName, 'utf8');
|
||||||
|
const lines = data.split('\n');
|
||||||
|
|
||||||
|
// Iterate through the array of strings and parse each line as JSON
|
||||||
|
const jsonData = lines.map(tryParse).filter(x => x);
|
||||||
|
return response.send(jsonData);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
return response.send({});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post("/getstatus", jsonParser, async function (request, response_getstatus = response) {
|
app.post("/getstatus", jsonParser, async function (request, response_getstatus = response) {
|
||||||
|
Reference in New Issue
Block a user