From d5ec7ba0f815f99d0d5ef8c7bfcdda217ebee86b Mon Sep 17 00:00:00 2001 From: openhands Date: Fri, 3 Jul 2026 17:21:05 +0200 Subject: [PATCH] feat: self-host all Habbo fonts via proxy route /api/font/[style]/[text] --- .../media/logo-1783091166418-npn577.gif | Bin 711 -> 0 bytes src/app/api/font/[style]/[text]/route.ts | 93 ++++++++++++++++++ src/components/public/habbo-fonts.ts | 2 +- 3 files changed, 94 insertions(+), 1 deletion(-) delete mode 100644 public/assets/images/media/logo-1783091166418-npn577.gif create mode 100644 src/app/api/font/[style]/[text]/route.ts diff --git a/public/assets/images/media/logo-1783091166418-npn577.gif b/public/assets/images/media/logo-1783091166418-npn577.gif deleted file mode 100644 index d995749ff31de555b155c0a174508b7ba752d082..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 711 zcmV;&0yzCgNk%w1VXOcr0HOc@0RI300095s0RPSa|6>3E0000000000A^8LW00000 zEC2ui0IUEf000C27`oj4Fv>}*y*O*2yZ>M)id-O^XsV*h>ZYw5zwb=1_6?gl&i6Z@ zN>LI9je;EOXH@o_I_OPGqt*gNWReMlT4mgB_&JW2r{^m6>(hGESM65L9>T%&^}UUJ z=l^bdc7T0)ghGCShlqklg?U+ze3OHCmXef?m6=O%mv)g&V~Lz6q@tdsbDx^6onWCm z60EPPr>>@Dx3!zSxT`*~OS87R#;Lx%zq`4}%f`ZFw9V7N$<)Qp%G=o2);rN=)y&`A z<=xNP=;q`^b-!xr=kx8yiuc9gX!zds^5pyYJu5MwpuvL(4Jt^;@Zds*4--;o7!hGb zhXE*NY^eTmBS(oB6?(L&=c7iGAWuS^pfcskmM9yb6uAHa?-Cn&CRstAIcraeMd=cxdx>)gHwv9o$#TZy}VZx8sYOb4@>EFzp zBX1Tt`R-mKmkobj-Iujv*N{QmZJTu~>eRA3kJcSJx9Hxmck3-3^E8&!#DAM^&D<>G z+Jd38y?xoY)8N4KUVr}gdh+d-absWpy18fW+`nTLjNJPA^6<|)H>=+Eaq-&U#~#m{ zypDX&^&v)GVeXkHT!DjB<}AXfr|5Jo7W2MNMedC60l;3FM=53h$yBwV~aH6$l{GU`lX|dHNtpbbwLXGV~It|m}HJX?zrTS tJmMH-i+)LX;f7dd$zX*LUa94mU}E6lm}Hh|=9y@wspgt&wpnHZ06R(VYxDpB diff --git a/src/app/api/font/[style]/[text]/route.ts b/src/app/api/font/[style]/[text]/route.ts new file mode 100644 index 00000000..695f8343 --- /dev/null +++ b/src/app/api/font/[style]/[text]/route.ts @@ -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", + }, + }); +} diff --git a/src/components/public/habbo-fonts.ts b/src/components/public/habbo-fonts.ts index 9d5cb2a3..b294c410 100644 --- a/src/components/public/habbo-fonts.ts +++ b/src/components/public/habbo-fonts.ts @@ -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}`; }