Highly ambitious ATProtocol AppView service and sdks
at main 38 lines 843 B view raw
1interface BlobRef { 2 $type: "blob"; 3 ref: { 4 $link: string; 5 }; 6 mimeType?: string; 7 size?: number; 8} 9 10/** 11 * Check if value is a blob reference 12 */ 13export function isBlobRef(value: unknown): value is BlobRef { 14 return ( 15 typeof value === "object" && 16 value !== null && 17 "$type" in value && 18 value.$type === "blob" && 19 "ref" in value && 20 typeof value.ref === "object" && 21 value.ref !== null && 22 "$link" in value.ref && 23 typeof value.ref.$link === "string" 24 ); 25} 26 27/** 28 * Convert blob ref to CDN URL 29 */ 30export function blobRefToCdnUrl( 31 did: string, 32 blobRef: BlobRef, 33 preset: "avatar" | "banner" | "feed_thumbnail" | "feed_fullsize" = "feed_fullsize", 34 cdnBaseUrl = "https://cdn.bsky.app/img" 35): string { 36 const cid = blobRef.ref.$link; 37 return `${cdnBaseUrl}/${preset}/plain/${did}/${cid}@jpeg`; 38}