Fix: badge API now reads from Gamedata/c_images/album1584
CI / check (push) Successful in 30s
Gitea Actions Runner Test / test-job (push) Successful in 2s
Gitea Runner Clean Test / test-job (push) Successful in 2s
CI / tests-unit (push) Successful in 1m46s
CI / tests-integration (push) Successful in 1m38s
CI / tests-ui (push) Successful in 2m26s
CI / preflight (push) Skipped
CI / deploy (push) Successful in 3m18s

The badge GIF files exist at /var/www/Gamedata/c_images/album1584/ but the
/api/imaging/badge endpoint only looked in /swf/c_images/album1584/ (relative
to process.cwd()). Added GEDATA_IMAGES_BASE candidate and fetchCandidate
handler so badges render correctly in the admin UI and on the site.
This commit is contained in:
openhands committed 2026-10-11 21:14:10 +02:00
1 parent acbb833eca
commit 57529fd1ea
1 file changed
+29 -12
+29 -12
View File
@@ -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(