interface BlobRef { $type: "blob"; ref: { $link: string; }; mimeType?: string; size?: number; } /** * Check if value is a blob reference */ export function isBlobRef(value: unknown): value is BlobRef { return ( typeof value === "object" && value !== null && "$type" in value && value.$type === "blob" && "ref" in value && typeof value.ref === "object" && value.ref !== null && "$link" in value.ref && typeof value.ref.$link === "string" ); } /** * Convert blob ref to CDN URL */ export function blobRefToCdnUrl( did: string, blobRef: BlobRef, preset: "avatar" | "banner" | "feed_thumbnail" | "feed_fullsize" = "feed_fullsize", cdnBaseUrl = "https://cdn.bsky.app/img" ): string { const cid = blobRef.ref.$link; return `${cdnBaseUrl}/${preset}/plain/${did}/${cid}@jpeg`; }