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

@ -1,8 +1,10 @@
import { api } from "../api.mjs";
import { __ID__, filePath } from "../consts.mjs";
import { getFileSize } from "../utils/fs.mjs";
const { HandlebarsApplicationMixin } = foundry.applications.api;
const { AbstractSidebarTab } = foundry.applications.sidebar;
const { deepClone } = foundry.utils;
export class ArtSidebar extends HandlebarsApplicationMixin(AbstractSidebarTab) {
// #region Options
@ -30,16 +32,32 @@ export class ArtSidebar extends HandlebarsApplicationMixin(AbstractSidebarTab) {
// #endregion Options
// #region Data Prep
_preparePartContext(partID, ctx) {
async _preparePartContext(partID, ctx) {
ctx = deepClone(ctx);
switch (partID) {
case `tokens`: {
await this._prepareTokensContext(ctx);
break;
};
case `artists`: {
await this._prepareArtistsContext(ctx);
break;
};
};
return ctx;
};
_prepareTokensContext(ctx) {};
async _prepareTokensContext(ctx) {
const size = await getFileSize(filePath(`storage/db/images.json`));
ctx.size = size.friendly;
};
_prepareArtistsContext(ctx) {};
async _prepareArtistsContext(ctx) {
const size = await getFileSize(filePath(`storage/db/artists.json`));
ctx.size = size.friendly;
};
// #endregion Data Prep
// #region Actions