chat history view shoes filesizes now

This commit is contained in:
RossAscends
2023-05-03 00:45:45 +09:00
parent a310c03082
commit a04171b262
3 changed files with 15 additions and 6 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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]';
}
}