diff --git a/public/script.js b/public/script.js index 8aca4cdc9..bc191ff2b 100644 --- a/public/script.js +++ b/public/script.js @@ -267,6 +267,7 @@ var animation_rm_easing = ""; var popup_type = ""; var bg_file_for_del = ""; +var chat_file_for_del = ""; var online_status = "no_connection"; var api_server = ""; @@ -614,7 +615,7 @@ async function getBackgrounds() { const thumbPath = `/thumbnail?type=bg&file=${bg}`; $("#bg_menu_content").append( `
-
+
` ); } @@ -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() { chat.forEach(function (item, i, arr) { addOneMessage(item); @@ -2320,7 +2338,12 @@ async function getAllCharaChats() { data[key]["file_name"] + '
' + mes + - "
" + "" + + '
' + + "" + ); if ( characters[this_chid]["chat"] == @@ -2577,6 +2600,7 @@ function callPopup(text, type) { break; case "del_world": case "del_group": + case "del_chat": default: $("#dialogue_popup_ok").text("Delete"); } @@ -3167,6 +3191,14 @@ $(document).ready(function () { popup_type = "del_bg"; callPopup("

Delete the background?

"); }); + + $(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("

Delete the Chat File?

"); + }); + $("#advanced_div").click(function () { if (!is_advanced_char_open) { is_advanced_char_open = true; @@ -3197,6 +3229,9 @@ $(document).ready(function () { delBackground(bg_file_for_del.attr("bgfile")); bg_file_for_del.parent().remove(); } + if (popup_type == "del_chat") { + delChat(chat_file_for_del); + } if (popup_type == "del_ch") { console.log( "Deleting character -- ChID: " + diff --git a/public/style.css b/public/style.css index 3f4803e39..c4d752b5a 100644 --- a/public/style.css +++ b/public/style.css @@ -948,6 +948,7 @@ input[type=search]:focus::-webkit-search-cancel-button { background-size: cover; background-position: center; box-shadow: 0 0 0 2pt black; + background-image: url(img/cross.png); } .no-border {border:none !important;} @@ -2090,6 +2091,23 @@ input[type="range"]{ 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 { width: 35px; height: 35px; diff --git a/server.js b/server.js index 8f0b39268..46ab7a0b4 100644 --- a/server.js +++ b/server.js @@ -812,6 +812,28 @@ app.post("/delbackground", jsonParser, function (request, response) { invalidateThumbnail('bg', request.body.bg); 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) { response_dw_bg = response; if (!request.body) return response.sendStatus(400);