a tool for shared writing and social publishing
at update/thread-viewer 41 lines 1.2 kB view raw
1import { lexToJson } from "@atproto/api"; 2import { NextRequest } from "next/server"; 3import { getAgent } from "../agent"; 4 5export const runtime = "nodejs"; 6 7export async function GET(req: NextRequest) { 8 try { 9 const searchParams = req.nextUrl.searchParams; 10 const uri = searchParams.get("uri"); 11 const cursor = searchParams.get("cursor"); 12 const limit = searchParams.get("limit"); 13 14 if (!uri) { 15 return Response.json( 16 { error: "uri parameter is required" }, 17 { status: 400 }, 18 ); 19 } 20 21 const agent = await getAgent(); 22 23 const response = await agent.app.bsky.feed.getQuotes({ 24 uri, 25 limit: limit ? parseInt(limit, 10) : 50, 26 cursor: cursor || undefined, 27 }); 28 29 const result = lexToJson(response.data); 30 31 return Response.json(result, { 32 headers: { 33 // Cache for 5 minutes on CDN, allow stale content for 1 hour while revalidating 34 "Cache-Control": "public, s-maxage=300, stale-while-revalidate=3600", 35 }, 36 }); 37 } catch (error) { 38 console.error("Error fetching Bluesky quotes:", error); 39 return Response.json({ error: "Failed to fetch quotes" }, { status: 500 }); 40 } 41}