- Add persistent disk cache for rendered avatars/badges (storage/imaging) so repeats never touch the flaky local renderer and cached renders survive upstream downtime - Serve cache-first with stale-on-error; cut primary/fallback timeouts from 10s/6s to 4s/4s so failing images cannot stall pages - Avatar proxy now returns a graceful 200 silhouette instead of 502 when no renderer can produce a figure, so no broken-image glyphs appear - Badge endpoint becomes a caching proxy trying configured CDN, public Habbo CDN and local /swf copy in order, and drops the fragile IP rate limit that could blank badge streams - Route all site badge images (profile, me, badges, apply pages) through the cached proxy instead of hot-linking images.habbo.com
34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
import { getAvatarUrl } from "@/lib/imager";
|
|
import type { AvatarOptions } from "@/types/admin";
|
|
|
|
/** Build a Habbo avatar-imager URL for a figure string. */
|
|
export function avatarImageUrl(look: string, opts: AvatarOptions = {}): string {
|
|
return getAvatarUrl(look, opts);
|
|
}
|
|
|
|
/** Build a proxied, cached badge image URL for a badge code. */
|
|
export function badgeImageUrl(code: string): string {
|
|
return `/api/imaging/badge?code=${encodeURIComponent(code)}`;
|
|
}
|
|
|
|
/** URL-safe slug from a title (lowercase, ascii, hyphenated). */
|
|
export function slugify(input: string): string {
|
|
// NFKD splits accented letters into base + combining mark; the combining
|
|
// marks (and any other non-alphanumerics) are then collapsed to hyphens.
|
|
const slug = input
|
|
.toLowerCase()
|
|
.normalize("NFKD")
|
|
.replace(/[^a-z0-9]+/g, "-")
|
|
.replace(/^-+|-+$/g, "")
|
|
.slice(0, 255);
|
|
return slug || "article";
|
|
}
|
|
|
|
/** Trim text to `max` chars on a word boundary, adding an ellipsis. */
|
|
export function excerpt(text: string, max = 160): string {
|
|
if (text.length <= max) return text;
|
|
const cut = text.slice(0, max);
|
|
const lastSpace = cut.lastIndexOf(" ");
|
|
return `${(lastSpace > 0 ? cut.slice(0, lastSpace) : cut).trimEnd()}…`;
|
|
}
|