Make avatar imager resilient with upstream fallback everywhere
This commit is contained in:
1 parent
1bbd809b43
commit
1df1ffc3e9
13 files changed
+277
-210
No files matched your search
@@ -6,8 +6,24 @@
|
||||
|
||||
export type { AvatarOptions } from "@/types/admin";
|
||||
|
||||
import type { SyntheticEvent } from "react";
|
||||
import type { AvatarOptions } from "@/types/admin";
|
||||
|
||||
/**
|
||||
* Neutral silhouette (grayscale SVG) shown when even the fallback upstream
|
||||
* cannot produce a render — keeps a broken avatar from showing a broken-image
|
||||
* glyph anywhere on the site.
|
||||
*/
|
||||
export const AVATAR_FALLBACK_SRC =
|
||||
"data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' fill='%23e2e2e2'/%3E%3Ccircle cx='32' cy='24' r='11' fill='%239d9d9d'/%3E%3Cpath d='M10 60c5-10 13-14 22-14s17 4 22 14z' fill='%239d9d9d'/%3E%3C/svg%3E";
|
||||
|
||||
export function avatarImageOnError(event: SyntheticEvent<HTMLImageElement>) {
|
||||
const img = event.currentTarget;
|
||||
if (img.dataset.fallback) return;
|
||||
img.dataset.fallback = "1";
|
||||
img.src = AVATAR_FALLBACK_SRC;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an avatar image URL using the configured imager.
|
||||
* Uses effect=14 and img_format=apng by default for epicnabbo.nl compatibility.
|
||||
|
||||
Reference in new issue
Block a user