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 d995749f..00000000 Binary files a/public/assets/images/media/logo-1783091166418-npn577.gif and /dev/null differ 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}`; }