Serve avatars from site's own /imaging endpoint instead of habbo.com
Local Build and Deploy / deploy (push) Successful in 1m7s

- Change default public imager URL from habbo.com to /imaging
- /imaging and /api/imaging/avatar now proxy from upstream (habbo.com) instead of redirecting
- Add resolveUpstreamBase() to separate public URL from upstream URL
- Update admin settings default and description
This commit is contained in:
openhands committed 2026-07-15 22:23:09 +02:00
1 parent 71f154cf52
commit 19faa5615c
6 files changed
+128 -79

No files matched your search

+22 -13
View File
@@ -1,38 +1,47 @@
/**
* Habbo avatar imager helpers.
* Avatar imager helpers.
*
* Images are loaded directly from Habbo's public imager. The old self-hosted
* `/api/imaging/avatar` proxy fails in production (Habbo blocks server-side
* fetches), so the browser always hits Habbo.com instead.
* The public-facing imager URL resolves to the site's own `/imaging` endpoint
* by default. That endpoint proxies the image from the configured upstream
* (defaults to Habbo's public imager).
*/
export type { AvatarOptions } from "@/types/admin";
import type { AvatarOptions } from "@/types/admin";
/** Official Habbo avatar imaging endpoint. */
export const HABBO_IMAGER_URL =
"https://www.habbo.com/habbo-imaging/avatarimage";
/** Default public imager endpoint (relative — served by the site itself). */
export const DEFAULT_IMAGER_URL = "/imaging";
/**
* Resolve a usable imager base URL.
* Rejects the broken self-hosted proxy if it was stored in settings.
* Resolve the public-facing imager base URL.
* Rejects the broken self-hosted proxy route if stored in settings.
*/
export function resolveImagerBase(configured?: string | null): string {
const fromEnv = process.env.NEXT_PUBLIC_IMAGER_URL?.trim();
if (fromEnv && !fromEnv.includes("/api/imaging/avatar") && !fromEnv.includes("/imaging")) {
if (fromEnv && !fromEnv.includes("/api/imaging/avatar")) {
return fromEnv.replace(/\/+$/, "");
}
const v = (configured ?? "").trim();
if (!v || v.includes("/api/imaging/avatar") || v.includes("/imaging")) {
return HABBO_IMAGER_URL;
if (!v || v.includes("/api/imaging/avatar")) {
return DEFAULT_IMAGER_URL;
}
return v.replace(/\/+$/, "");
}
/**
* Build an avatar image URL (Habbo imager by default).
* Resolve the upstream URL used by the proxy endpoint.
* Falls back to Habbo's public imager when nothing else is configured.
*/
export function resolveUpstreamBase(): string {
const fromEnv = process.env.IMAGING_UPSTREAM_URL?.trim();
if (fromEnv) return fromEnv.replace(/\/+$/, "");
return "https://www.habbo.com/habbo-imaging/avatarimage";
}
/**
* Build an avatar image URL (site's own `/imaging` endpoint by default).
*
* @example
* getAvatarUrl('hr-893-45.hd-180-1.ch-210-66.lg-270-82')