mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
@@ -372,12 +372,26 @@ export async function getChatInfo(pathToFile, additionalData = {}, isGroup = fal
|
|||||||
const stats = await fs.promises.stat(pathToFile);
|
const stats = await fs.promises.stat(pathToFile);
|
||||||
const fileSizeInKB = `${(stats.size / 1024).toFixed(2)}kb`;
|
const fileSizeInKB = `${(stats.size / 1024).toFixed(2)}kb`;
|
||||||
|
|
||||||
if (stats.size === 0) {
|
const chatData = {
|
||||||
|
file_name: path.parse(pathToFile).base,
|
||||||
|
file_size: fileSizeInKB,
|
||||||
|
chat_items: 0,
|
||||||
|
mes: '[The chat is empty]',
|
||||||
|
last_mes: stats.mtimeMs,
|
||||||
|
...additionalData,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (stats.size === 0 && !isGroup) {
|
||||||
console.warn(`Found an empty chat file: ${pathToFile}`);
|
console.warn(`Found an empty chat file: ${pathToFile}`);
|
||||||
res({});
|
res({});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (stats.size === 0 && isGroup) {
|
||||||
|
res(chatData);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const rl = readline.createInterface({
|
const rl = readline.createInterface({
|
||||||
input: fileStream,
|
input: fileStream,
|
||||||
crlfDelay: Infinity,
|
crlfDelay: Infinity,
|
||||||
@@ -395,14 +409,9 @@ export async function getChatInfo(pathToFile, additionalData = {}, isGroup = fal
|
|||||||
if (lastLine) {
|
if (lastLine) {
|
||||||
const jsonData = tryParse(lastLine);
|
const jsonData = tryParse(lastLine);
|
||||||
if (jsonData && (jsonData.name || jsonData.character_name)) {
|
if (jsonData && (jsonData.name || jsonData.character_name)) {
|
||||||
const chatData = {};
|
chatData.chat_items = isGroup ? itemCounter : (itemCounter - 1);
|
||||||
|
chatData.mes = jsonData['mes'] || '[The chat is empty]';
|
||||||
chatData['file_name'] = path.parse(pathToFile).base;
|
chatData.last_mes = jsonData['send_date'] || stats.mtimeMs;
|
||||||
chatData['file_size'] = fileSizeInKB;
|
|
||||||
chatData['chat_items'] = isGroup ? itemCounter : (itemCounter - 1);
|
|
||||||
chatData['mes'] = jsonData['mes'] || '[The chat is empty]';
|
|
||||||
chatData['last_mes'] = jsonData['send_date'] || stats.mtimeMs;
|
|
||||||
Object.assign(chatData, additionalData);
|
|
||||||
|
|
||||||
res(chatData);
|
res(chatData);
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user