feat: switch avatar imager to epicnabbo.nl with figure conversion

- Update imager to use epicnabbo.nl by default with effect=14 and img_format=apng
- Add figure string converter (old Habbo format -> epicnabbo.nl short format)
- Update avatarImageUrl to auto-convert figure strings
- Update online-users-widget to use new avatarImageUrl
- Add tests for imager and figure conversion
This commit is contained in:
openhands committed 2026-08-09 19:38:04 +02:00
1 parent 703c29bc83
commit fc7e6ca248
10 files changed
+270 -114

No files matched your search

+15 -35
View File
@@ -1,9 +1,8 @@
/**
* Avatar imager helpers.
*
* 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).
* The public-facing imager URL is configured via NEXT_PUBLIC_IMAGER_URL env var.
* Defaults to epicnabbo.nl imager with effect=14 and img_format=apng.
*/
export type { AvatarOptions } from "@/types/admin";
@@ -11,45 +10,23 @@ export type { AvatarOptions } from "@/types/admin";
import { env } from "@/env";
import type { AvatarOptions } from "@/types/admin";
/** Build an absolute default imager URL from public env vars. */
function defaultImagerUrl(): string {
const pub = env.NEXT_PUBLIC_IMAGER_URL?.trim();
if (pub && !pub.includes("/api/imaging/avatar"))
return pub.replace(/\/+$/, "");
const app = env.NEXT_PUBLIC_APP_URL?.trim();
if (app) return `${app.replace(/\/+$/, "")}/imaging`;
return "/imaging";
}
const DEFAULT_IMAGER_URL = "https://epicnabbo.nl/imaging/avatarimage";
/**
* Resolve the public-facing imager base URL.
* Rejects the broken self-hosted proxy route if stored in settings.
* Resolve the public-facing imager base URL from env.
* Falls back to epicnabbo.nl if not configured.
*/
export function resolveImagerBase(configured?: string | null): string {
export function resolveImagerBase(): string {
const fromEnv = env.NEXT_PUBLIC_IMAGER_URL?.trim();
if (fromEnv && !fromEnv.includes("/api/imaging/avatar")) {
return fromEnv.replace(/\/+$/, "");
if (!fromEnv) {
return DEFAULT_IMAGER_URL;
}
const v = (configured ?? "").trim();
if (!v || v.includes("/api/imaging/avatar")) {
return defaultImagerUrl();
}
return v.replace(/\/+$/, "");
return fromEnv.replace(/\/+$/, "");
}
/**
* 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 = 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).
* Build an avatar image URL using the configured imager.
* Uses effect=14 and img_format=apng by default for epicnabbo.nl compatibility.
*/
export function getAvatarUrl(
figure: string,
@@ -62,6 +39,8 @@ export function getAvatarUrl(
headOnly = false,
gesture,
action,
effect = 14,
img_format = "apng",
} = options;
const params = new URLSearchParams({
@@ -69,7 +48,8 @@ export function getAvatarUrl(
direction: String(direction),
head_direction: String(headDirection),
size,
img_format: "png",
img_format,
effect: String(effect),
});
if (headOnly) params.set("headonly", "1");