From 630bfc0457dad2687e984a1bfbba6ca4cdf27130 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Thu, 18 Jan 2024 21:17:09 +0800 Subject: [PATCH] feat: getRandomAvatarUrl function --- src/components/ui/Avatar.tsx | 3 ++- src/lib/expand-unit.ts | 4 ++-- src/lib/helpers.ts | 3 +++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/components/ui/Avatar.tsx b/src/components/ui/Avatar.tsx index c4c662fa..15643173 100644 --- a/src/components/ui/Avatar.tsx +++ b/src/components/ui/Avatar.tsx @@ -1,6 +1,7 @@ import React, { useMemo } from "react" import { Image } from "~/components/ui/Image" +import { getRandomAvatarUrl } from "~/lib/helpers" import { toGateway } from "~/lib/ipfs-parser" import { cn } from "~/lib/utils" @@ -35,7 +36,7 @@ export const Avatar = ({ const borderRadius = rounded === false ? "rounded-lg" : "rounded-full" if (!image) { - image = `https://api.dicebear.com/6.x/bottts-neutral/svg?seed=${cid}` + image = getRandomAvatarUrl(cid || "") } return ( diff --git a/src/lib/expand-unit.ts b/src/lib/expand-unit.ts index ae15cea1..60ec8d6c 100644 --- a/src/lib/expand-unit.ts +++ b/src/lib/expand-unit.ts @@ -13,7 +13,7 @@ import { } from "~/lib/types" import { detectLanguage } from "./detect-lang" -import { getNoteSlug } from "./helpers" +import { getNoteSlug, getRandomAvatarUrl } from "./helpers" export const expandCrossbellNote = async ({ note, @@ -290,7 +290,7 @@ export const expandCrossbellCharacter = async (site: CharacterEntity) => { .filter(Boolean) } else { expandedCharacter.metadata.content.avatars = [ - `https://api.dicebear.com/6.x/bottts-neutral/svg?seed=${expandedCharacter.characterId}`, + getRandomAvatarUrl(expandedCharacter.characterId), ] } diff --git a/src/lib/helpers.ts b/src/lib/helpers.ts index 1d1436a6..17a9dbe5 100644 --- a/src/lib/helpers.ts +++ b/src/lib/helpers.ts @@ -88,3 +88,6 @@ export const getSiteRelativeUrl = (pathname: string, address: string) => { } } } + +export const getRandomAvatarUrl = (seed: string | number) => + `https://api.dicebear.com/7.x/bottts-neutral/svg?seed=${seed}`