mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
#295 Sanitize get/save chat names
This commit is contained in:
14
server.js
14
server.js
@ -528,7 +528,7 @@ app.post("/savechat", jsonParser, function (request, response) {
|
|||||||
var dir_name = String(request.body.avatar_url).replace('.png', '');
|
var dir_name = String(request.body.avatar_url).replace('.png', '');
|
||||||
let chat_data = request.body.chat;
|
let chat_data = request.body.chat;
|
||||||
let jsonlData = chat_data.map(JSON.stringify).join('\n');
|
let jsonlData = chat_data.map(JSON.stringify).join('\n');
|
||||||
fs.writeFile(chatsPath + dir_name + "/" + request.body.file_name + '.jsonl', jsonlData, 'utf8', function (err) {
|
fs.writeFile(`${chatsPath + dir_name}/${sanitize(request.body.file_name)}.jsonl`, jsonlData, 'utf8', function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
response.send(err);
|
response.send(err);
|
||||||
return console.log(err);
|
return console.log(err);
|
||||||
@ -552,11 +552,10 @@ app.post("/getchat", jsonParser, function (request, response) {
|
|||||||
|
|
||||||
if (err === null) { //if there is a dir, then read the requested file from the JSON call
|
if (err === null) { //if there is a dir, then read the requested file from the JSON call
|
||||||
|
|
||||||
fs.stat(chatsPath + dir_name + "/" + request.body.file_name + ".jsonl", function (err, stat) {
|
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 (err === null) { //if no error (the file exists), read the file
|
||||||
if (stat !== undefined) {
|
if (stat !== undefined) {
|
||||||
fs.readFile(chatsPath + dir_name + "/" + request.body.file_name + ".jsonl", 'utf8', (err, data) => {
|
fs.readFile(`${chatsPath + dir_name}/${sanitize(request.body.file_name)}.jsonl`, 'utf8', (err, data) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
response.send(err);
|
response.send(err);
|
||||||
@ -585,9 +584,8 @@ 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_getstatus = response) {
|
||||||
if (!request.body) return response_getstatus.sendStatus(400);
|
if (!request.body) return response_getstatus.sendStatus(400);
|
||||||
api_server = request.body.api_server;
|
api_server = request.body.api_server;
|
||||||
@ -1281,7 +1279,7 @@ app.post('/getsettings', jsonParser, (request, response) => { //Wintermute's cod
|
|||||||
.filter(x => path.parse(x).ext == '.json')
|
.filter(x => path.parse(x).ext == '.json')
|
||||||
.sort();
|
.sort();
|
||||||
|
|
||||||
instructFiles.forEach(item => {
|
instructFiles.forEach(item => {
|
||||||
const file = fs.readFileSync(
|
const file = fs.readFileSync(
|
||||||
path.join(directories.instruct, item),
|
path.join(directories.instruct, item),
|
||||||
'utf-8',
|
'utf-8',
|
||||||
@ -2847,7 +2845,7 @@ app.post('/writesecret', jsonParser, (request, response) => {
|
|||||||
const key = request.body.key;
|
const key = request.body.key;
|
||||||
const value = request.body.value;
|
const value = request.body.value;
|
||||||
|
|
||||||
writeSecret(key,value);
|
writeSecret(key, value);
|
||||||
return response.send('ok');
|
return response.send('ok');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user