diff --git a/src/app/api/imaging/badge/route.ts b/src/app/api/imaging/badge/route.ts index 0ee337c6..93892c5b 100644 --- a/src/app/api/imaging/badge/route.ts +++ b/src/app/api/imaging/badge/route.ts @@ -23,6 +23,7 @@ const CODE_RE = /^[A-Za-z0-9_+.-]+$/; const CODE_MAX_LEN = 50; const DEFAULT_BASE = "https://images.habbo.com/c_images/album1584"; const LOCAL_SWF_BASE = "/swf/c_images/album1584"; +const GEDATA_IMAGES_BASE = "/var/www/Gamedata/c_images/album1584"; const FETCH_TIMEOUT_MS = 5_000; // Neutral placeholder (grey rounded square) served as a 200 so broken badge @@ -45,10 +46,11 @@ export async function GET(request: NextRequest) { const sourceLocal = request.nextUrl.searchParams.get("source") === "local"; const candidates: string[] = sourceLocal - ? [LOCAL_SWF_BASE, DEFAULT_BASE] + ? [LOCAL_SWF_BASE, GEDATA_IMAGES_BASE, DEFAULT_BASE] : [ ...((configured && [configured]) as string[]), DEFAULT_BASE, + GEDATA_IMAGES_BASE, LOCAL_SWF_BASE, ]; @@ -105,18 +107,33 @@ async function fetchCandidate( } // Local `/swf/...` path — read straight from the deployed public folder. - try { - const file = join( - process.cwd(), - "public", - normalized.replace(/^\//, ""), - `${code}.gif`, - ); - const body = new Uint8Array(await readFile(file)); - return { body, contentType: "image/gif", source: "local" }; - } catch { - return null; + if (normalized.startsWith("/swf")) { + try { + const file = join( + process.cwd(), + "public", + normalized.replace(/^\//, ""), + `${code}.gif`, + ); + const body = new Uint8Array(await readFile(file)); + return { body, contentType: "image/gif", source: "local" }; + } catch { + return null; + } } + + // Local Gamedata path — read from /var/www/Gamedata/c_images/album1584/ + if (normalized.startsWith("/var/www/Gamedata")) { + try { + const file = join(normalized, `${code}.gif`); + const body = new Uint8Array(await readFile(file)); + return { body, contentType: "image/gif", source: "local" }; + } catch { + return null; + } + } + + return null; } function badgeResponse(