feat: 100% self-hosted Habbo fonts via sprite sheets + client-side compositor
This commit is contained in:
1 parent
8a58bcb252
commit
77ae4838c0
353 files changed
+227
-143
No files matched your search
@@ -1,93 +0,0 @@
|
||||
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 VALID_STYLES = new Set([
|
||||
"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",
|
||||
]);
|
||||
|
||||
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);
|
||||
|
||||
// Serve from cache if already fetched
|
||||
if (existsSync(cachePath)) {
|
||||
const bytes = await readFile(cachePath);
|
||||
return new NextResponse(bytes, {
|
||||
headers: {
|
||||
"Content-Type": "image/gif",
|
||||
"Cache-Control": "public, max-age=86400",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Fetch from habbofont.net and cache
|
||||
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",
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user