Merge branch 'main' of github.com:remanso-space/remanso

This commit is contained in:
Julien Calixte
2026-02-19 20:42:21 +01:00
40 changed files with 4264 additions and 488 deletions

View File

@@ -1,49 +0,0 @@
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
}
const response = await fetch(`https://plc.directory/${did}`)
const {
alsoKnownAs: [aka],
service: [{ serviceEndpoint }],
} = await response.json()
const alias = aka.replace("at://", "")
const author = { alias, endpoint: serviceEndpoint }
correspondanceCache.set(did, author)
return author
}
export const getAka = async (dids: Set<string>) => {
const correspondance = await Promise.all(
[...dids].map(async (did) => {
if (correspondanceCache.has(did)) {
return [did, correspondanceCache.get(did)] as [string, Author]
}
const response = await fetch(`https://plc.directory/${did}`)
const {
alsoKnownAs: [aka],
service: [{ serviceEndpoint }],
} = await response.json()
const alias = aka.replace("at://", "")
const author = { alias, endpoint: serviceEndpoint }
correspondanceCache.set(did, author)
return [did, author] as [string, Author]
}),
)
return new Map(correspondance)
}

View File

@@ -0,0 +1,79 @@
import { createSchema, createFetch } from "@better-fetch/fetch"
import { type } from "arktype"
export type Author = { handle: string; pds: string }
const correspondanceCache = new Map<string, Author>()
const schema = createSchema(
{
"/xrpc/blue.microcosm.identity.resolveMiniDoc": {
output: type({
did: "string",
handle: "string",
pds: "string",
signing_key: "string",
}),
query: type({
identifier: "string",
}),
},
},
{ strict: true },
)
const microcosmSlingshot = createFetch({
baseURL: "https://slingshot.microcosm.blue",
// plugins: [logger()],
schema,
})
export const getAuthor = async (did: string): Promise<Author | null> => {
if (correspondanceCache.has(did)) {
return correspondanceCache.get(did) as Author
}
try {
const { data: author, error } = await microcosmSlingshot(
"/xrpc/blue.microcosm.identity.resolveMiniDoc",
{ query: { identifier: did } },
)
if (!author) {
return null
}
correspondanceCache.set(did, author)
return author
} catch (e) {
console.warn(e)
return null
}
}
export const getAuthors = async (dids: Set<string>) => {
const correspondance = await Promise.all(
[...dids].map(async (did) => {
if (correspondanceCache.has(did)) {
return [did, correspondanceCache.get(did)] as [string, Author | null]
}
const { data: author } = await microcosmSlingshot(
"/xrpc/blue.microcosm.identity.resolveMiniDoc",
{ query: { identifier: did } },
)
if (!author) {
return [did, null] as [string, Author | null]
}
correspondanceCache.set(did, author)
return [did, author] as [string, Author | null]
}),
)
return new Map(correspondance)
}

View File

@@ -1,3 +1,5 @@
import { getAuthor } from "@/modules/atproto/getAuthor"
const endpointCache = new Map<string, string>()
const getEndpoint = async (did: string) => {
@@ -15,10 +17,13 @@ const getEndpoint = async (did: string) => {
}
export const getUrl = async ({ did, rkey }: { did: string; rkey: string }) => {
const url = new URL(
"/xrpc/com.atproto.repo.getRecord",
await getEndpoint(did),
)
const author = await getAuthor(did)
if (!author) {
return null
}
const url = new URL("/xrpc/com.atproto.repo.getRecord", author.pds)
url.searchParams.set("repo", did)
url.searchParams.set("collection", "space.remanso.note")
url.searchParams.set("rkey", rkey)

View 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] }
}

View 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
}

View File

@@ -0,0 +1,13 @@
export const withATProtoImages = (
markdown: string,
{ pds, did }: { pds: 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", pds)
imageUrl.searchParams.set("did", did)
imageUrl.searchParams.set("cid", cid)
return `![${altText}](${imageUrl.toString()})`
})
}

View File

@@ -1,4 +1,5 @@
import { computed } from "vue"
import { useUserRepoStore } from "@/modules/repo/store/userRepo.store"
export const useNotes = () => {

View File

@@ -10,10 +10,6 @@ export const useUserSettings = () => {
const store = useUserRepoStore()
watchEffect(() => {
if (store.userSettings === undefined) {
return
}
const root = document.documentElement
const fontFamily = store.userSettings?.chosenFontFamily