From 3e63930e210d8a7619a6c04ce3f62521bed8e866 Mon Sep 17 00:00:00 2001 From: Mannu Date: Sun, 10 May 2026 14:40:33 +0530 Subject: [PATCH] Fix list: search all memories with prefix --- src/app/api/upload/route.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/app/api/upload/route.ts b/src/app/api/upload/route.ts index 7e0de7f..f71af15 100644 --- a/src/app/api/upload/route.ts +++ b/src/app/api/upload/route.ts @@ -34,17 +34,14 @@ export async function GET(req: NextRequest) { try { const { client, bucket, baseUrl } = getR2(); const { searchParams } = new URL(req.url); - const childId = searchParams.get("childId") || "default"; - const prefix = `memories/${childId}`; + const prefix = searchParams.get("childId") || "default"; - const command = new ListObjectsV2Command({ Bucket: bucket, Prefix: prefix, MaxKeys: 10 }); + // List all objects with memories/ prefix + const command = new ListObjectsV2Command({ Bucket: bucket, Prefix: "memories/", MaxKeys: 50 }); const res = await client.send(command); - // Debug: log what we found - console.log("List result:", JSON.stringify(res)); - if (!res.Contents || res.Contents.length === 0) { - return NextResponse.json({ memories: [], debug: { bucket, prefix, count: 0 } }); + return NextResponse.json({ memories: [], debug: "no files found" }); } const objects = res.Contents.map((obj) => ({ @@ -57,7 +54,7 @@ export async function GET(req: NextRequest) { return NextResponse.json({ memories: objects }); } catch (error) { console.error("R2 list error:", error); - return NextResponse.json({ error: String(error), stack: error?.stack }, { status: 500 }); + return NextResponse.json({ error: String(error) }, { status: 500 }); } }