Files
EpicNext-Cms/scripts/precache-fonts.ts
T

78 lines
3.3 KiB
TypeScript

import { mkdir, writeFile } from "fs/promises";
import { existsSync } from "fs";
import path from "path";
const CACHE_DIR = "public/assets/fonts/cache";
const FONT_STYLES = [
"habbo_new","habbo_big","habbo_new_big","habbo_old_big","habbo",
"habbo_tiny","habbo_oldschool","habbo_blocky","habjoy","habjoy_light",
"paradise","paradise_rounded","habbnew","habbo_clicker","reception",
"accessoires","africa","alhambra","arctic","asian","asian_small",
"basic","base","bathroom","battlebanzai","bensalem","bensalem_sea",
"bling","bling_gold","bones","books","bots","bubble","bubble_blue",
"bubble_orange","bunny_run","bunny_run_blue","buttons","candy",
"collectibles","crystal","cubie","disco","dreams","dreams_flat",
"duckets","emo","exchange","executive","explore","explore_big",
"explore_small","faq","fbomb","festival","flags","fx","freehand",
"gaming","gallery","goldentemple","gravity","hma","gold_big",
"habbo_news","habbo_runway","habbid_red","habbid_blue","habbolife",
"habbowood","habbowood_big","hands","hello","horse","ice","iced",
"iron","japan","love","marketplace_red","monkey","mushroom",
"mushroom_green","neon_blue","neon_green","neon_pink","occasional",
"palooza","palooza_blue","pets","pillow_orange","pillow_pink","pipes",
"plants","plastic","recycle","retropixel","rugs","sale","shalimar",
"shalimar_big","shalimar_small","soccer","soccer_red","soccer_yellow",
"space","spaces","special_offers","straypixels","steampunk","scifi",
"summer","teleport","theater_lights","tribe","trophies","usva",
"unknown_blue","unknown_blue_2","unknown_metal","unknown_white",
"unknown_pillow_1","unknown_pillow_2","valentine","western","wood",
"yellow_text","jurrasic","halloween","halloween_2","halloween_3",
"plastic_playful","dinner_blue","dinner_green","dinner_red",
"battleball","lido","soccer_big","hc","hc_big","hc_small",
"hc_compact","hc_gold","habboclub","habboclub_banner","habbovip",
"habbovip_banner","agenda","mini_white","volter","volter_shadow",
"volter_modern","volter_modern_small","black","windows",
"windows_lowercase","windows_jungle","windows_blue","windows_green",
"windows_pink","windows_red","windows_red_dark","windows_yellow",
"windows_purple","beta_big","beta_small","beta_small_old","beta",
"habboclub_complete","gift","habboclub_silver","love_full",
"marketplace_full","relax","habbo_ribbon",
];
const text = process.argv[2]?.toLowerCase().replace(/\s/g, "+") || "atom";
async function main() {
const cacheDir = path.join(process.cwd(), CACHE_DIR);
await mkdir(cacheDir, { recursive: true });
let done = 0;
let failed = 0;
for (const style of FONT_STYLES) {
const cacheFile = `${style}-${text}.gif`;
const cachePath = path.join(cacheDir, cacheFile);
if (existsSync(cachePath)) {
done++;
continue;
}
const url = `https://habbofont.net/font/${style}/${text}.gif`;
try {
const res = await fetch(url);
if (!res.ok) { failed++; continue; }
const buffer = Buffer.from(await res.arrayBuffer());
await writeFile(cachePath, buffer);
done++;
process.stdout.write(`✓ ${style}\n`);
} catch {
failed++;
process.stdout.write(`✗ ${style}\n`);
}
}
console.log(`\nDone: ${done}/${FONT_STYLES.length} cached (${failed} failed)`);
}
main();