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("[/api/me] Request headers:", Object.fromEntries(req.headers.entries())); 12 13 const agent = await getSessionAgent(req, res); 14 if (!agent) { 15 console.log("[/api/me] No agent found"); 16 return new Response(JSON.stringify(null), { 17 status: 200, 18 headers: { 19 "Content-Type": "application/json", 20 "X-Response-Type": "null" 21 } 22 }); 23 } 24 25 const session = await agent.com.atproto.server.getSession(); 26 27 const handle = await resolver.resolveDidToHandle(session.data.did); 28 29 const responseData = { 30 did: session.data.did, 31 handle 32 }; 33 34 return new Response(JSON.stringify(responseData), { 35 status: 200, 36 headers: { 37 "Content-Type": "application/json", 38 "X-Response-Type": "user" 39 } 40 }); 41 } catch (err) { 42 const message = err instanceof Error ? err.message : String(err); 43 console.error("[/api/me] Error:", { 44 error: message, 45 stack: err instanceof Error ? err.stack : undefined, 46 url: req.url, 47 method: req.method, 48 headers: Object.fromEntries(req.headers.entries()) 49 }); 50 51 return new Response(JSON.stringify(null), { 52 status: 200, 53 headers: { 54 "Content-Type": "application/json", 55 "X-Response-Type": "error", 56 "X-Error-Message": encodeURIComponent(message) 57 } 58 }); 59 } 60 }, 61});