Added Past Chat File Delete Function

This commit is contained in:
RossAsscends
2023-03-24 13:55:34 +09:00
parent bd7e7c6379
commit e1a337f140
3 changed files with 77 additions and 2 deletions

View File

@ -267,6 +267,7 @@ var animation_rm_easing = "";
var popup_type = ""; var popup_type = "";
var bg_file_for_del = ""; var bg_file_for_del = "";
var chat_file_for_del = "";
var online_status = "no_connection"; var online_status = "no_connection";
var api_server = ""; var api_server = "";
@ -614,7 +615,7 @@ async function getBackgrounds() {
const thumbPath = `/thumbnail?type=bg&file=${bg}`; const thumbPath = `/thumbnail?type=bg&file=${bg}`;
$("#bg_menu_content").append( $("#bg_menu_content").append(
`<div class="bg_example" bgfile="${bg}" class="bg_example_img" style="background-image: url('${thumbPath}');"> `<div class="bg_example" bgfile="${bg}" class="bg_example_img" style="background-image: url('${thumbPath}');">
<div bgfile="${bg}" class=bg_example_cross style="background-image: url(img/cross.png);"> <div bgfile="${bg}" class="bg_example_cross">
</div>` </div>`
); );
} }
@ -688,6 +689,23 @@ async function delBackground(bg) {
} }
} }
async function delChat(chatfile) {
const response = await fetch("/delchat", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-CSRF-Token": token,
},
body: JSON.stringify({
chatfile: chatfile,
id: characters[this_chid].name
}),
});
if (response.ok === true) {
}
}
function printMessages() { function printMessages() {
chat.forEach(function (item, i, arr) { chat.forEach(function (item, i, arr) {
addOneMessage(item); addOneMessage(item);
@ -2320,7 +2338,12 @@ async function getAllCharaChats() {
data[key]["file_name"] + data[key]["file_name"] +
'</div><div class="select_chat_block_mes">' + '</div><div class="select_chat_block_mes">' +
mes + mes +
"</div></div>" "</div>" +
'<div file_name="' +
data[key]["file_name"] +
'" class="PastChat_cross"></div>' +
"</div >"
); );
if ( if (
characters[this_chid]["chat"] == characters[this_chid]["chat"] ==
@ -2577,6 +2600,7 @@ function callPopup(text, type) {
break; break;
case "del_world": case "del_world":
case "del_group": case "del_group":
case "del_chat":
default: default:
$("#dialogue_popup_ok").text("Delete"); $("#dialogue_popup_ok").text("Delete");
} }
@ -3167,6 +3191,14 @@ $(document).ready(function () {
popup_type = "del_bg"; popup_type = "del_bg";
callPopup("<h3>Delete the background?</h3>"); callPopup("<h3>Delete the background?</h3>");
}); });
$(document).on("click", ".PastChat_cross", function () {
chat_file_for_del = $(this).attr('file_name');
console.log('detected cross click for' + chat_file_for_del);
popup_type = "del_chat";
callPopup("<h3>Delete the Chat File?</h3>");
});
$("#advanced_div").click(function () { $("#advanced_div").click(function () {
if (!is_advanced_char_open) { if (!is_advanced_char_open) {
is_advanced_char_open = true; is_advanced_char_open = true;
@ -3197,6 +3229,9 @@ $(document).ready(function () {
delBackground(bg_file_for_del.attr("bgfile")); delBackground(bg_file_for_del.attr("bgfile"));
bg_file_for_del.parent().remove(); bg_file_for_del.parent().remove();
} }
if (popup_type == "del_chat") {
delChat(chat_file_for_del);
}
if (popup_type == "del_ch") { if (popup_type == "del_ch") {
console.log( console.log(
"Deleting character -- ChID: " + "Deleting character -- ChID: " +

View File

@ -948,6 +948,7 @@ input[type=search]:focus::-webkit-search-cancel-button {
background-size: cover; background-size: cover;
background-position: center; background-position: center;
box-shadow: 0 0 0 2pt black; box-shadow: 0 0 0 2pt black;
background-image: url(img/cross.png);
} }
.no-border {border:none !important;} .no-border {border:none !important;}
@ -2090,6 +2091,23 @@ input[type="range"]{
opacity: 0.6; opacity: 0.6;
} }
.PastChat_cross{
position: absolute;
right: 15px;
margin-top: 5px;
width: 15px;
height: 15px;
cursor: pointer;
opacity: 0.4;
background-image: url(img/cross.png);
background-size: contain;
background-color: var(--black100);
background-repeat: no-repeat;
background-position: center;
border-radius: 50%;
box-shadow: 0 0 0 2pt black;
}
#advanced_book_logo { #advanced_book_logo {
width: 35px; width: 35px;
height: 35px; height: 35px;

View File

@ -812,6 +812,28 @@ app.post("/delbackground", jsonParser, function (request, response) {
invalidateThumbnail('bg', request.body.bg); invalidateThumbnail('bg', request.body.bg);
return response.send('ok'); return response.send('ok');
}); });
app.post("/delchat", jsonParser, function (request, response) {
if (!request.body) return response.sendStatus(400);
if (request.body.chatfile !== sanitize(request.body.chatfile)) {
console.error('Malicious chat name prevented');
return response.sendStatus(403);
}
const fileName = path.join(directories.chats, '/', sanitize(request.body.id), '/', sanitize(request.body.chatfile));
if (!fs.existsSync(fileName)) {
console.log('Chat file not found');
return response.sendStatus(400);
}
fs.rmSync(fileName);
console.log('deleted chat file: ' + fileName);
return response.send('ok');
});
app.post("/downloadbackground", urlencodedParser, function (request, response) { app.post("/downloadbackground", urlencodedParser, function (request, response) {
response_dw_bg = response; response_dw_bg = response;
if (!request.body) return response.sendStatus(400); if (!request.body) return response.sendStatus(400);