feat: add "cooked it" photo reviews
Users can rate a recipe with review text and an optional photo. Adds ratings.photo_key column, a reviews list endpoint, and a review-purpose presign path (reviewer isn't the recipe owner, so the upload authorization differs from cover-photo uploads). Also fixes CSP connect-src/img-src to allow the storage origin — direct-to-S3/MinIO presigned uploads and stored images were silently blocked by Content-Security-Policy in the browser. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -12,6 +12,7 @@ const Schema = z.object({
|
||||
message: "Content type must be jpeg, png, webp, or avif",
|
||||
}),
|
||||
recipeId: z.string().uuid(),
|
||||
purpose: z.enum(["recipe", "review"]).default("recipe"),
|
||||
});
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
@@ -24,15 +25,22 @@ export async function POST(req: NextRequest) {
|
||||
return NextResponse.json({ error: "Validation error", issues: parsed.error.issues }, { status: 400 });
|
||||
}
|
||||
|
||||
const owned = await db.query.recipes.findFirst({
|
||||
where: and(eq(recipes.id, parsed.data.recipeId), eq(recipes.authorId, session!.user.id)),
|
||||
columns: { id: true },
|
||||
const { recipeId, contentType, purpose } = parsed.data;
|
||||
const recipe = await db.query.recipes.findFirst({
|
||||
where: purpose === "recipe"
|
||||
? and(eq(recipes.id, recipeId), eq(recipes.authorId, session!.user.id))
|
||||
: eq(recipes.id, recipeId),
|
||||
columns: { id: true, visibility: true, authorId: true },
|
||||
});
|
||||
if (!owned) return NextResponse.json({ error: "Not found" }, { status: 404 });
|
||||
if (!recipe) return NextResponse.json({ error: "Not found" }, { status: 404 });
|
||||
if (purpose === "review" && recipe.visibility === "private" && recipe.authorId !== session!.user.id) {
|
||||
return NextResponse.json({ error: "Not found" }, { status: 404 });
|
||||
}
|
||||
|
||||
const ext = parsed.data.contentType.split("/")[1] ?? "jpg";
|
||||
const key = `recipes/${parsed.data.recipeId}/photos/${session!.user.id}-${crypto.randomUUID()}.${ext}`;
|
||||
const url = await createPresignedUploadUrl(key, parsed.data.contentType);
|
||||
const ext = contentType.split("/")[1] ?? "jpg";
|
||||
const folder = purpose === "review" ? "reviews" : "photos";
|
||||
const key = `recipes/${recipeId}/${folder}/${session!.user.id}-${crypto.randomUUID()}.${ext}`;
|
||||
const url = await createPresignedUploadUrl(key, contentType);
|
||||
|
||||
return NextResponse.json({ url, key });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user