Graphical PDS migrator for AT Protocol
1import { getSessionAgent } from "../../lib/sessions.ts"; 2import { define } from "../../utils.ts"; 3import { resolver } from "../../lib/id-resolver.ts"; 4 5export const handler = define.handlers({ 6 async GET(ctx) { 7 const req = ctx.req; 8 const res = new Response(); 9 10 try { 11 console.log( 12 "[/api/me] Request headers:", 13 Object.fromEntries(req.headers.entries()), 14 ); 15 16 const agent = await getSessionAgent(req, res); 17 if (!agent) { 18 console.log("[/api/me] No agent found"); 19 return new Response(JSON.stringify(null), { 20 status: 200, 21 headers: { 22 "Content-Type": "application/json", 23 "X-Response-Type": "null", 24 }, 25 }); 26 } 27 28 const session = await agent.com.atproto.server.getSession(); 29 30 const handle = await resolver.resolveDidToHandle(session.data.did); 31 32 const responseData = { 33 did: session.data.did, 34 handle, 35 }; 36 37 return new Response(JSON.stringify(responseData), { 38 status: 200, 39 headers: { 40 "Content-Type": "application/json", 41 "X-Response-Type": "user", 42 }, 43 }); 44 } catch (err) { 45 const message = err instanceof Error ? err.message : String(err); 46 console.error("[/api/me] Error:", { 47 error: message, 48 stack: err instanceof Error ? err.stack : undefined, 49 url: req.url, 50 method: req.method, 51 headers: Object.fromEntries(req.headers.entries()), 52 }); 53 54 return new Response(JSON.stringify(null), { 55 status: 200, 56 headers: { 57 "Content-Type": "application/json", 58 "X-Response-Type": "error", 59 "X-Error-Message": encodeURIComponent(message), 60 }, 61 }); 62 } 63 }, 64});