UX/UI/perf pass: admin tabs, theme toggle, log polish, mod search, JAR cache

- Admin page split into tabs (Server/Players/Chat/Mods/Backups/Logs) with
  hash + localStorage persistence; inactive tabs no longer mount.
- Log viewer: level color-coding, search, level filter chips, auto-scroll
  toggle, copy button, visible-line count.
- Installed mods list: search field + side filter (all/both/server/client)
  with live count; public ModList gets skeleton + empty states and search.
- Theme toggle with no-flash inline init, localStorage + system preference.
- Layout: full OG / Twitter metadata, title template, keywords,
  dual-theme themeColor, metadataBase.
- lib/mods.ts: per-jar mtime+size parse cache (cold 6s -> warm ~45ms on
  /api/mods for the full mod list); cache eviction on mod removal.
- ChatBridge polling eased 3s -> 5s with 2s stale window.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
hurkicorgi 2026-04-13 04:58:25 -06:00
parent b6cf8c7cdc
commit 6c91f7fef0
10 changed files with 490 additions and 89 deletions

View file

@ -81,12 +81,18 @@ function extractToml(content: string, key: string): string | null {
return match ? match[1] : null;
}
function extractModMeta(
type JarParseCacheEntry = {
mtimeMs: number;
size: number;
meta: Omit<ModMeta, "side">;
};
const jarParseCache = new Map<string, JarParseCacheEntry>();
function parseJarMeta(
dir: string,
filename: string
): Omit<ModMeta, "side"> {
const filePath = join(dir, filename);
const stat = statSync(filePath);
let modId = "unknown";
let displayName = filename
.replace(/-(\d)/, " $1")
@ -95,7 +101,7 @@ function extractModMeta(
let version = "";
try {
const zip = new AdmZip(filePath);
const zip = new AdmZip(join(dir, filename));
const toml = zip.getEntry("META-INF/mods.toml");
if (toml) {
const content = toml.getData().toString("utf8");
@ -112,10 +118,33 @@ function extractModMeta(
displayName,
version,
filename,
size: (stat.size / 1024 / 1024).toFixed(1) + " MB",
size: "",
};
}
function extractModMeta(
dir: string,
filename: string
): Omit<ModMeta, "side"> {
const filePath = join(dir, filename);
const stat = statSync(filePath);
const cacheKey = filePath;
const cached = jarParseCache.get(cacheKey);
if (cached && cached.mtimeMs === stat.mtimeMs && cached.size === stat.size) {
return { ...cached.meta, size: (stat.size / 1024 / 1024).toFixed(1) + " MB" };
}
const meta = parseJarMeta(dir, filename);
jarParseCache.set(cacheKey, {
mtimeMs: stat.mtimeMs,
size: stat.size,
meta,
});
return { ...meta, size: (stat.size / 1024 / 1024).toFixed(1) + " MB" };
}
export function getModDetails(): ModMeta[] {
return memo(MODS_CACHE_KEY, MODS_CACHE_TTL, computeModDetails);
}
@ -155,8 +184,10 @@ export function removeMod(filename: string): void {
if (existsSync(serverPath)) {
unlinkSync(serverPath);
jarParseCache.delete(serverPath);
} else if (existsSync(clientPath)) {
unlinkSync(clientPath);
jarParseCache.delete(clientPath);
} else {
throw new Error(`Mod "${filename}" not found`);
}