A simple AtProto app to read pet.mewsse.link records on my PDS.
at main 1.7 kB view raw
1import { isBlob } from '@atcute/lexicons/interfaces' 2import type { Did } from '@atcute/lexicons/syntax' 3import type { Embed } from '../db.ts' 4 5export async function findEmbed(did: Did<"web"> | Did<"plc">, pds: string, embed: any): Promise<Embed | null> { 6 if (!embed) return null 7 8 if (embed.$type === "pet.mewsse.embed.image" || embed.$type === "pet.mewsse.embed.video") { 9 if (!embed.image && !embed.video) return null 10 11 const embedType = embed.image || embed.video 12 13 if (!embedType) return null 14 15 const cid = isBlob(embedType) ? embedType.ref.$link : embedType.cid 16 17 // let the user pull the blob with their browser directly fomr the pds 18 // decreasing space needed to run the service and prevent duplication 19 // if hosted at the same place as the pds (self host anyone ?) 20 return { 21 '$type': embed.$type, 22 url: `${pds}/xrpc/com.atproto.sync.getBlob?did=${did}&cid=${cid}`, 23 alt: embed.alt 24 } 25 } 26 27 if (embed.$type === "pet.mewsse.embed.post" && embed.uri) { 28 const at = embed.uri.split('at://').pop() 29 const response = await fetch(`https://embed.bsky.app/oembed?url=${embed.uri}`) 30 const body = await response.json() 31 32 return { 33 '$type': embed.$type, 34 html: body.html, 35 alt: embed.alt 36 } 37 } 38 39 if (embed.$type === "pet.mewsse.embed.external" && embed.uri) { 40 if (embed.uri.indexOf('youtube') != -1) { 41 const response = await fetch(`https://www.youtube.com/oembed?url=${embed.uri}`) 42 const body = await response.json() 43 44 return { 45 '$type': embed.$type, 46 html: body.html, 47 alt: embed.alt 48 } 49 } 50 51 return { 52 '$type': embed.$type, 53 url: embed.uri, 54 alt: embed.alt 55 } 56 } 57 58 return null 59}