mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Refactor endpoints/chats.js
1. Move formatBytes utility to util.js 2. Fix type error related to dates sorting 3. Add type to backupFunctions map
This commit is contained in:
13
src/util.js
13
src/util.js
@@ -142,6 +142,19 @@ export function getHexString(length) {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a byte size into a human-readable string with units
|
||||
* @param {number} bytes - The size in bytes to format
|
||||
* @returns {string} The formatted string (e.g., "1.5 MB")
|
||||
*/
|
||||
export function formatBytes(bytes) {
|
||||
if (bytes === 0) return '0 B';
|
||||
const k = 1024;
|
||||
const sizes = ['B', 'KB', 'MB', 'GB'];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts a file with given extension from an ArrayBuffer containing a ZIP archive.
|
||||
* @param {ArrayBuffer} archiveBuffer Buffer containing a ZIP archive
|
||||
|
Reference in New Issue
Block a user