feat: add stacked public notes
This commit is contained in:
@@ -2,8 +2,6 @@ export type Author = { alias: string; endpoint: string }
|
||||
|
||||
const correspondanceCache = new Map<string, Author>()
|
||||
|
||||
console.log({ correspondanceCache })
|
||||
|
||||
export const getUniqueAka = async (did: string): Promise<Author> => {
|
||||
if (correspondanceCache.has(did)) {
|
||||
return correspondanceCache.get(did) as Author
|
||||
|
||||
7
src/modules/atproto/parseAtUri.ts
Normal file
7
src/modules/atproto/parseAtUri.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export const parseAtUri = (atUri: string): { did: string; rkey: string } => {
|
||||
const match = atUri.match(/^at:\/\/(did:[^/]+)\/[^/]+\/(.+)$/)
|
||||
if (!match) {
|
||||
throw new Error(`Invalid AT URI: ${atUri}`)
|
||||
}
|
||||
return { did: match[1], rkey: match[2] }
|
||||
}
|
||||
29
src/modules/atproto/publicNote.types.ts
Normal file
29
src/modules/atproto/publicNote.types.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
export interface PublicNoteRecord {
|
||||
uri: string
|
||||
cid: string
|
||||
value: PublicNote
|
||||
}
|
||||
|
||||
export interface PublicNote {
|
||||
$type: string
|
||||
title: string
|
||||
images: PublicNoteImage[]
|
||||
content: string
|
||||
createdAt: string
|
||||
publishedAt: string
|
||||
theme?: string
|
||||
fontFamily?: string
|
||||
fontSize?: string
|
||||
}
|
||||
|
||||
export interface PublicNoteImage {
|
||||
alt: string
|
||||
image: PublicNoteBlob
|
||||
}
|
||||
|
||||
export interface PublicNoteBlob {
|
||||
$type: string
|
||||
ref: { $link: string }
|
||||
mimeType: string
|
||||
size: number
|
||||
}
|
||||
13
src/modules/atproto/withATProtoImages.ts
Normal file
13
src/modules/atproto/withATProtoImages.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export const withATProtoImages = (
|
||||
markdown: string,
|
||||
{ endpoint, did }: { endpoint: string; did: string },
|
||||
): string => {
|
||||
const imageLinkPattern = /!\[([^\]]*)\]\((bafkrei[a-z0-9]+)\)/g
|
||||
|
||||
return markdown.replace(imageLinkPattern, (_, altText, cid) => {
|
||||
const imageUrl = new URL("/xrpc/com.atproto.sync.getBlob", endpoint)
|
||||
imageUrl.searchParams.set("did", did)
|
||||
imageUrl.searchParams.set("cid", cid)
|
||||
return `})`
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user