Serve avatars from Habbo imager instead of broken self-hosted proxy.
Local Build and Deploy / deploy (push) Successful in 56s
Local Build and Deploy / deploy (push) Successful in 56s
Co-authored-by: Cursor <[email protected]>
This commit is contained in:
1 parent
2c68fb7e5a
commit
8cce8837bc
6 files changed
+107
-51
No files matched your search
+29
-8
@@ -1,18 +1,38 @@
|
||||
/**
|
||||
* Centralized Habbo avatar imager utility.
|
||||
* Points to the self-hosted imager API (`/api/imaging/avatar`) which handles
|
||||
* disk + memory caching and (Phase 2) local rendering from .nitro bundles.
|
||||
* Override with NEXT_PUBLIC_IMAGER_URL when needed (e.g. CDN in front).
|
||||
* Habbo 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.
|
||||
*/
|
||||
|
||||
const IMAGER_URL = process.env.NEXT_PUBLIC_IMAGER_URL || "/api/imaging/avatar";
|
||||
|
||||
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";
|
||||
|
||||
/**
|
||||
* Build an avatar image URL served by the self-hosted imager.
|
||||
* Resolve a usable imager base URL.
|
||||
* Rejects the broken self-hosted proxy if it was 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")) {
|
||||
return fromEnv.replace(/\/+$/, "");
|
||||
}
|
||||
|
||||
const v = (configured ?? "").trim();
|
||||
if (!v || v.includes("/api/imaging/avatar")) {
|
||||
return HABBO_IMAGER_URL;
|
||||
}
|
||||
return v.replace(/\/+$/, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an avatar image URL (Habbo imager by default).
|
||||
*
|
||||
* @example
|
||||
* getAvatarUrl('hr-893-45.hd-180-1.ch-210-66.lg-270-82')
|
||||
@@ -43,5 +63,6 @@ export function getAvatarUrl(
|
||||
if (gesture) params.set("gesture", gesture);
|
||||
if (action) params.set("action", action);
|
||||
|
||||
return `${IMAGER_URL}?${params.toString()}`;
|
||||
const base = resolveImagerBase();
|
||||
return `${base}?${params.toString()}`;
|
||||
}
|
||||
Reference in new issue
Block a user