add at.link

This commit is contained in:
2026-01-22 21:57:22 +09:00
parent cefe7981ee
commit ca6bb5319c
10 changed files with 296 additions and 5 deletions

View File

@@ -652,3 +652,49 @@ export async function getRse(did: string): Promise<RseCollection | null> {
}
return null
}
// Link item type
export interface LinkItem {
service: 'github' | 'youtube' | 'x'
username: string
}
// Link collection type
export interface LinkCollection {
links: LinkItem[]
createdAt: string
updatedAt?: string
}
// Get user's links (ai.syui.at.link)
export async function getLinks(did: string): Promise<LinkCollection | null> {
const collection = 'ai.syui.at.link'
// Try local first
try {
const res = await fetch(`/content/${did}/${collection}/self.json`)
if (res.ok && isJsonResponse(res)) {
const record = await res.json()
return record.value as LinkCollection
}
} catch {
// Try remote
}
// Remote fallback
const pds = await getPds(did)
if (!pds) return null
try {
const host = pds.replace('https://', '')
const url = `${xrpcUrl(host, comAtprotoRepo.getRecord)}?repo=${did}&collection=${collection}&rkey=self`
const res = await fetch(url)
if (res.ok) {
const record = await res.json()
return record.value as LinkCollection
}
} catch {
// Failed
}
return null
}

View File

@@ -1,5 +1,5 @@
export interface Route {
type: 'home' | 'user' | 'post' | 'postpage' | 'atbrowser' | 'service' | 'collection' | 'record' | 'chat' | 'chat-thread' | 'chat-edit' | 'card' | 'card-old' | 'rse'
type: 'home' | 'user' | 'post' | 'postpage' | 'atbrowser' | 'service' | 'collection' | 'record' | 'chat' | 'chat-thread' | 'chat-edit' | 'card' | 'card-old' | 'rse' | 'link'
handle?: string
rkey?: string
service?: string
@@ -69,6 +69,12 @@ export function parseRoute(): Route {
return { type: 'rse', handle: rseMatch[1] }
}
// Link page: /@handle/at/link
const linkMatch = path.match(/^\/@([^/]+)\/at\/link\/?$/)
if (linkMatch) {
return { type: 'link', handle: linkMatch[1] }
}
// Chat edit: /@handle/at/chat/{rkey}/edit
const chatEditMatch = path.match(/^\/@([^/]+)\/at\/chat\/([^/]+)\/edit$/)
if (chatEditMatch) {
@@ -125,6 +131,8 @@ export function navigate(route: Route): void {
path = `/@${route.handle}/at/chat/${route.rkey}`
} else if (route.type === 'chat-edit' && route.handle && route.rkey) {
path = `/@${route.handle}/at/chat/${route.rkey}/edit`
} else if (route.type === 'link' && route.handle) {
path = `/@${route.handle}/at/link`
}
window.history.pushState({}, '', path)