mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Don't lose original file name when uploading backgrounds.
+bonus lint fix for importing JSONs
This commit is contained in:
41
server.js
41
server.js
@@ -1338,40 +1338,23 @@ app.post("/delchat", jsonParser, function (request, response) {
|
||||
return response.send('ok');
|
||||
});
|
||||
|
||||
|
||||
app.post("/downloadbackground", urlencodedParser, function (request, response) {
|
||||
response_dw_bg = response;
|
||||
if (!request.body) return response.sendStatus(400);
|
||||
|
||||
let filedata = request.file;
|
||||
//console.log(filedata.mimetype);
|
||||
var fileType = ".png";
|
||||
var img_file = "ai";
|
||||
var img_path = "public/img/";
|
||||
|
||||
img_path = "uploads/";
|
||||
img_file = filedata.filename;
|
||||
if (filedata.mimetype == "image/jpeg") fileType = ".jpeg";
|
||||
if (filedata.mimetype == "image/png") fileType = ".png";
|
||||
if (filedata.mimetype == "image/gif") fileType = ".gif";
|
||||
if (filedata.mimetype == "image/bmp") fileType = ".bmp";
|
||||
fs.copyFile(img_path + img_file, 'public/backgrounds/' + img_file + fileType, (err) => {
|
||||
invalidateThumbnail('bg', img_file + fileType);
|
||||
if (err) {
|
||||
|
||||
return console.log(err);
|
||||
} else {
|
||||
//console.log(img_file+fileType);
|
||||
response_dw_bg.send(img_file + fileType);
|
||||
}
|
||||
//console.log('The image was copied from temp directory.');
|
||||
});
|
||||
if (!request.body || !request.file) return response.sendStatus(400);
|
||||
|
||||
const img_path = path.join("uploads/", request.file.filename);
|
||||
const filename = request.file.originalname;
|
||||
|
||||
try {
|
||||
fs.copyFileSync(img_path, path.join('public/backgrounds/', filename));
|
||||
invalidateThumbnail('bg', filename);
|
||||
response_dw_bg.send(filename);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
response_dw_bg.sendStatus(500);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
app.post("/savesettings", jsonParser, function (request, response) {
|
||||
fs.writeFile('public/settings.json', JSON.stringify(request.body, null, 4), 'utf8', function (err) {
|
||||
if (err) {
|
||||
@@ -1852,7 +1835,7 @@ app.post("/importcharacter", urlencodedParser, async function (request, response
|
||||
response.send({ error: true });
|
||||
}
|
||||
|
||||
let = jsonData = json5.parse(data);
|
||||
let jsonData = json5.parse(data);
|
||||
|
||||
if (jsonData.spec !== undefined) {
|
||||
console.log('importing from v2 json');
|
||||
|
Reference in New Issue
Block a user