feat: self-host all Habbo fonts via proxy route /api/font/[style]/[text]

This commit is contained in:
openhands committed 2026-07-03 17:21:05 +02:00
1 parent f3367e9b7b
commit d5ec7ba0f8
3 files changed
+94 -1

No files matched your search

+93
View File
@@ -0,0 +1,93 @@
import { NextResponse } from "next/server";
import { mkdir, writeFile, readFile } from "fs/promises";
import { existsSync } from "fs";
import path from "path";
export const dynamic = "force-dynamic";
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 VALID_STYLES = new Set(FONT_STYLES);
export async function GET(
_request: Request,
{ params }: { params: Promise<{ style: string; text: string }> },
) {
const { style, text } = await params;
if (!VALID_STYLES.has(style)) {
return new NextResponse("Invalid font style", { status: 400 });
}
const sanitized = text.replace(/[^a-z0-9+]/g, "");
if (!sanitized) {
return new NextResponse("Invalid text", { status: 400 });
}
const cacheFile = `${style}-${sanitized}.gif`;
const cachePath = path.join(process.cwd(), CACHE_DIR, cacheFile);
if (existsSync(cachePath)) {
const bytes = await readFile(cachePath);
return new NextResponse(bytes, {
headers: {
"Content-Type": "image/gif",
"Cache-Control": "public, max-age=86400",
},
});
}
const upstream = `https://habbofont.net/font/${style}/${sanitized}.gif`;
const res = await fetch(upstream);
if (!res.ok) {
return new NextResponse("Font render error", { status: 502 });
}
const buffer = Buffer.from(await res.arrayBuffer());
await mkdir(path.dirname(cachePath), { recursive: true });
await writeFile(cachePath, buffer);
return new NextResponse(buffer, {
headers: {
"Content-Type": "image/gif",
"Cache-Control": "public, max-age=86400",
},
});
}
+1 -1
View File
@@ -265,5 +265,5 @@ export const HABBO_FONT_GROUPS: HabboFontGroup[] = [
export function buildFontUrl(styleName: string, text: string): string {
const t = text.toLowerCase().replace(/\s/g, "+");
return `https://habbofont.net/font/${styleName}/${t}.gif`;
return `/api/font/${styleName}/${t}`;
}