Add the database sizes into the sidebar (closes #21)
This commit is contained in:
parent
1e68187959
commit
3a8a2092f7
6 changed files with 75 additions and 9 deletions
|
|
@ -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));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue