feat: getRandomAvatarUrl function

This commit is contained in:
DIYgod
2024-01-18 21:17:09 +08:00
parent 1ebec84bbf
commit 630bfc0457
3 changed files with 7 additions and 3 deletions
+2 -1
View File
@@ -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 (
+2 -2
View File
@@ -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),
]
}
+3
View File
@@ -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}`