Fix R2 photo privacy - filter by childId
- GET /api/upload now filters R2 listing by childId - Only user's own photos are returned Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
67bb077687
commit
09f263b423
1 changed files with 7 additions and 2 deletions
|
|
@ -13,7 +13,10 @@ function getR2Config() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function GET() {
|
export async function GET(req: NextRequest) {
|
||||||
|
const { searchParams } = new URL(req.url);
|
||||||
|
const childId = searchParams.get("childId");
|
||||||
|
|
||||||
const R2 = getR2Config();
|
const R2 = getR2Config();
|
||||||
if (!R2.accountId || !R2.accessKeyId || !R2.secretKey || !R2.bucket) {
|
if (!R2.accountId || !R2.accessKeyId || !R2.secretKey || !R2.bucket) {
|
||||||
return NextResponse.json({ error: "R2 not configured" }, { status: 500 });
|
return NextResponse.json({ error: "R2 not configured" }, { status: 500 });
|
||||||
|
|
@ -28,7 +31,9 @@ export async function GET() {
|
||||||
const baseUrl = R2.publicUrl || `https://pub-${R2.accountId}.r2.dev`;
|
const baseUrl = R2.publicUrl || `https://pub-${R2.accountId}.r2.dev`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const command = new ListObjectsV2Command({ Bucket: R2.bucket });
|
// Filter by childId if provided
|
||||||
|
const prefix = childId ? `memories/${childId}/` : "memories/";
|
||||||
|
const command = new ListObjectsV2Command({ Bucket: R2.bucket, Prefix: prefix });
|
||||||
const response = await client.send(command);
|
const response = await client.send(command);
|
||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue