Add the database sizes into the sidebar (closes #21)

This commit is contained in:
Oliver 2026-02-02 22:45:19 -07:00
parent 1e68187959
commit 3a8a2092f7
6 changed files with 75 additions and 9 deletions

View file

@ -37,6 +37,30 @@ export async function lastModifiedAt(path) {
};
};
export async function getFileSize(path) {
try {
const response = await fetch(filePath(path), { method: `HEAD` });
const bytes = response.headers.get(`Content-Length`);
if (!bytes) { return null }
// round the non-bytes to 2 decimal places
const kilobytes = Math.floor(bytes / 10) / 100;
const megabytes = Math.floor(bytes / 10_000) / 100;
// determine the most appropriate unit to use
let friendly = `${bytes} bytes`;
if (megabytes > 0.25) {
friendly = `${megabytes}MB`;
} else if (kilobytes > 0) {
friendly = `${kilobytes}KB`;
};
return { bytes, kilobytes, megabytes, friendly };
} catch {
return null;
};
};
export async function getFile(path) {
try {
return fetchJsonWithTimeout(filePath(path));