···88 ShTangledActorProfile,
99 shTangledActorProfileSchema,
1010} from "@/lib/types/lexicons/sh/tangled/actor/profile";
1111-import z from "zod";
12111212+/**
1313+ * Gets the avatar of the specified DID from their repository. Specifically, queries for sh.tangled.actor.profile self records first, then as a fallback, queries for app.bsky.actor.profile.
1414+ * If both return invalid avatar blob URLs, then it returns "#" as a fallback.
1515+ * You should **NOT** use '#' as the value to an <img> element's `src` attribute. Instead, call the function early then set some other fallback in the component return.
1616+ * @param {Object} params - The supplied params object.
1717+ * @param {string} params.did - The DID you want to fetch. This should be a "did:plc:..." or a "did:web:...". This is NOT checked at runtime.
1818+ * @param {URL} params.repoUrl - The URL of the DID's home repository (PDS). Omit any trailing slashes. This is automatically trimmed at runtime.
1919+ */
1320export const getAvatar = async ({
1421 did,
1522 repoUrl,
···38453946 return `${cleanedUrl}/xrpc/com.atproto.sync.getBlob?did=${did}&cid=${avatarCid}`;
4047 }
4848+4949+ const bskyAvatarResult = await getBskyAvatar({
5050+ did,
5151+ repoUrl: cleanedUrl,
5252+ });
5353+5454+ if (bskyAvatarResult.ok) {
5555+ const { avatar } = bskyAvatarResult.data;
5656+ if (!avatar) {
5757+ throw new Error(
5858+ "In `getAvatar`, the resulting Bluesky profile object did not contain an Avatar field, even though it passed validation for an explicit avatar field within `getBlueskyAvatar`. This should not happen.",
5959+ );
6060+ }
6161+ const { ref } = avatar;
6262+ const avatarCid = ref.$link;
6363+6464+ return `${cleanedUrl}/xrpc/com.atproto.sync.getBlob?did=${did}&cid=${avatarCid}`;
6565+ }
6666+6767+ // at this point, both the tangled profile lookup and the bluesky profile lookup have failed. So, we will return '#'.
6868+6969+ return "#";
4170};
42714372const getTangledAvatar = async ({