fix: avatar host default address on not found (#2027)
feat: updated to use libravatar
This commit is contained in:
@@ -88,10 +88,10 @@ type CurrentUserAvatarProps = {
|
|||||||
user: User | null;
|
user: User | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getGravatar = (email?: string | undefined | null) => {
|
const getAvatarLink = (email?: string | undefined | null) => {
|
||||||
if (!email) return null;
|
if (!email) return null;
|
||||||
const emailHash = createHash('sha256').update(email.trim().toLowerCase()).digest('hex');
|
const emailHash = createHash('sha256').update(email.trim().toLowerCase()).digest('hex');
|
||||||
return `https://gravatar.com/avatar/${emailHash}?d=null`;
|
return `https://seccdn.libravatar.org/avatar/${emailHash}?d=404`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const CurrentUserAvatar = forwardRef<HTMLDivElement, CurrentUserAvatarProps>(
|
const CurrentUserAvatar = forwardRef<HTMLDivElement, CurrentUserAvatarProps>(
|
||||||
@@ -100,18 +100,16 @@ const CurrentUserAvatar = forwardRef<HTMLDivElement, CurrentUserAvatarProps>(
|
|||||||
const { fn } = useMantineTheme();
|
const { fn } = useMantineTheme();
|
||||||
const border = fn.variant({ variant: 'default' }).border;
|
const border = fn.variant({ variant: 'default' }).border;
|
||||||
|
|
||||||
if (!user)
|
|
||||||
return <Avatar ref={ref} styles={{ root: { border: `1px solid ${border}` } }} {...others} />;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Avatar
|
<Avatar
|
||||||
ref={ref}
|
ref={ref}
|
||||||
color={primaryColor}
|
color={user == null ? undefined : primaryColor}
|
||||||
src={getGravatar(user.email)}
|
src={getAvatarLink(user?.email)}
|
||||||
styles={{ root: { border: `1px solid ${border}` } }}
|
alt={user?.name?.slice(0, 2).toUpperCase() ?? "anon"}
|
||||||
|
styles={{ root: { border: `1px solid ${border}` }, image: {} }}
|
||||||
{...others}
|
{...others}
|
||||||
>
|
>
|
||||||
{user.name?.slice(0, 2).toUpperCase()}
|
{user?.name?.slice(0, 2).toUpperCase()}
|
||||||
</Avatar>
|
</Avatar>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user