enh: show extracted file content

This commit is contained in:
Timothy J. Baek
2024-09-28 10:53:25 +02:00
parent 9636913de0
commit 90ec458c4c
6 changed files with 123 additions and 16 deletions

View File

@@ -873,3 +873,21 @@ export const createMessagesList = (history, messageId) => {
return [message];
}
};
export const formatFileSize = (size) => {
if (size == null) return 'Unknown size';
if (typeof size !== 'number' || size < 0) return 'Invalid size';
if (size === 0) return '0 B';
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
let unitIndex = 0;
while (size >= 1024 && unitIndex < units.length - 1) {
size /= 1024;
unitIndex++;
}
return `${size.toFixed(1)} ${units[unitIndex]}`;
};
export const getLineCount = (text) => {
return text.split('\n').length;
};