diff --git a/public/script.js b/public/script.js index f99f29d65..31f6e10a0 100644 --- a/public/script.js +++ b/public/script.js @@ -3200,7 +3200,6 @@ async function displayPastChats() { $("#load_select_chat_div").css("display", "none"); $("#ChatHistoryCharName").text(displayName); - for (const key in data) { let strlen = 300; let mes = data[key]["mes"]; @@ -3210,11 +3209,12 @@ async function displayPastChats() { mes = "..." + mes.substring(mes.length - strlen); } + const file_size = data[key]["file_size"]; const fileName = data[key]['file_name']; const template = $('#past_chat_template .select_chat_block_wrapper').clone(); template.find('.select_chat_block').attr('file_name', fileName); template.find('.avatar img').attr('src', avatarImg); - template.find('.select_chat_block_filename').text(fileName); + template.find('.select_chat_block_filename').text(fileName + " (" + file_size + ")"); template.find('.select_chat_block_mes').text(mes); template.find('.PastChat_cross').attr('file_name', fileName); diff --git a/public/scripts/group-chats.js b/public/scripts/group-chats.js index 4cbefd100..bbff238c4 100644 --- a/public/scripts/group-chats.js +++ b/public/scripts/group-chats.js @@ -700,7 +700,7 @@ async function deleteGroup(id) { } } -export async function editGroup(id, immediately, reload=true) { +export async function editGroup(id, immediately, reload = true) { let group = groups.find((x) => x.id === id); if (!group) { @@ -1122,8 +1122,9 @@ export async function getGroupPastChats(groupId) { try { for (const chatId of group.chats) { const messages = await loadGroupChat(chatId); + let this_chat_file_size = (JSON.stringify(messages).length / 1024).toFixed(2) + "kb"; const lastMessage = messages.length ? messages[messages.length - 1].mes : '[The chat is empty]'; - chats.push({ 'file_name': chatId, 'mes': lastMessage }); + chats.push({ 'file_name': chatId, 'mes': lastMessage, 'file_size': this_chat_file_size }); } } catch (err) { console.error(err); diff --git a/server.js b/server.js index 9e2942f7c..74893b5b0 100644 --- a/server.js +++ b/server.js @@ -285,7 +285,7 @@ app.get('/get_faq', function (_, response) { app.get('/get_readme', function (_, response) { response.sendFile(__dirname + "/readme.md"); }); -app.get('/deviceinfo', function(request, response) { +app.get('/deviceinfo', function (request, response) { const userAgent = request.header('user-agent'); const deviceDetector = new DeviceDetector(); const deviceInfo = deviceDetector.parse(userAgent); @@ -1396,6 +1396,13 @@ app.post("/getallchatsofcharacter", jsonParser, function (request, response) { for (let i = jsonFiles.length - 1; i >= 0; i--) { const file = jsonFiles[i]; const fileStream = fs.createReadStream(chatsPath + char_dir + '/' + file); + + const fullPathAndFile = chatsPath + char_dir + '/' + file + const stats = fs.statSync(fullPathAndFile); + const fileSizeInKB = (stats.size / 1024).toFixed(2) + "kb"; + + console.log(fileSizeInKB); + const rl = readline.createInterface({ input: fileStream, crlfDelay: Infinity @@ -1412,6 +1419,7 @@ app.post("/getallchatsofcharacter", jsonParser, function (request, response) { if (jsonData.name !== undefined || jsonData.character_name !== undefined) { chatData[i] = {}; chatData[i]['file_name'] = file; + chatData[i]['file_size'] = fileSizeInKB; chatData[i]['mes'] = jsonData['mes'] || '[The chat is empty]'; } } @@ -1654,7 +1662,7 @@ app.post("/importchat", urlencodedParser, function (request, response) { } }); } else { - response.send({error:true}); + response.send({ error: true }); return; } rl.close();