feat: simplify resolveAvatarUrl — custom image first, gravatar fallback

Remove settings parameter. Always prefer user.image if available, otherwise
fall back to gravatar with d=404 to trigger AvatarFallback (initials) when
no gravatar exists. Removes support for avatarMode and dicebearStyle.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Théo LAGACHE
2026-06-25 11:00:14 +02:00
co-authored by Claude Sonnet 4.6
parent 6a975629a5
commit 8d448718d0
+5 -20
View File
@@ -1,27 +1,12 @@
import { createHash } from "crypto";
import type { Setting } from "@/db/schema/01_setting";
import type { User } from "@/db/schema/02_user";
export function resolveAvatarUrl(
user: Pick<User, "email" | "image">,
settings: Pick<Setting, "avatarMode" | "dicebearStyle"> | null | undefined,
): string | undefined {
const mode = settings?.avatarMode ?? "internal";
if (mode === "gravatar") {
const hash = createHash("md5")
.update((user.email ?? "").trim().toLowerCase())
.digest("hex");
return `https://www.gravatar.com/avatar/${hash}?s=200&d=mp`;
}
if (mode === "dicebear") {
const style = settings?.dicebearStyle ?? "thumbs";
const hash = createHash("md5")
.update((user.email ?? "").trim().toLowerCase())
.digest("hex");
return `https://api.dicebear.com/10.x/${style}/svg?seed=${hash}`;
}
return user.image ?? undefined;
if (user.image) return user.image;
const hash = createHash("md5")
.update((user.email ?? "").trim().toLowerCase())
.digest("hex");
return `https://www.gravatar.com/avatar/${hash}?s=200&d=404`;
}