diff --git a/src/pds.js b/src/pds.js index c4e4276..c02b94e 100644 --- a/src/pds.js +++ b/src/pds.js @@ -885,6 +885,9 @@ const pdsRoutes = { '/xrpc/com.atproto.repo.getRecord': { handler: (pds, req, url) => pds.handleGetRecord(url) }, + '/xrpc/com.atproto.repo.describeRepo': { + handler: (pds, req, url) => pds.handleDescribeRepo() + }, '/xrpc/com.atproto.sync.getLatestCommit': { handler: (pds, req, url) => pds.handleGetLatestCommit() }, @@ -1295,6 +1298,26 @@ export class PersonalDataServer { return Response.json({ uri, cid: row.cid, value }) } + async handleDescribeRepo() { + const did = await this.getDid() + if (!did) { + return Response.json({ error: 'RepoNotFound', message: 'repo not found' }, { status: 404 }) + } + const handle = await this.state.storage.get('handle') + // Get unique collections + const collections = this.sql.exec( + `SELECT DISTINCT collection FROM records` + ).toArray().map(r => r.collection) + + return Response.json({ + handle: handle || did, + did, + didDoc: {}, + collections, + handleIsCorrect: !!handle + }) + } + handleGetLatestCommit() { const commits = this.sql.exec( `SELECT cid, rev FROM commits ORDER BY seq DESC LIMIT 1` @@ -1442,6 +1465,17 @@ async function handleRequest(request, env) { return Response.json({ repos, cursor: undefined }) } + // describeRepo uses ?repo= param instead of ?did= + if (url.pathname === '/xrpc/com.atproto.repo.describeRepo') { + const repo = url.searchParams.get('repo') + if (!repo) { + return Response.json({ error: 'InvalidRequest', message: 'missing repo param' }, { status: 400 }) + } + const id = env.PDS.idFromName(repo) + const pds = env.PDS.get(id) + return pds.fetch(request) + } + const did = url.searchParams.get('did') if (!did) { return new Response('missing did param', { status: 400 })