fix: recipe/storage tier limits are lifetime totals, not monthly (v0.58.0)
Recipe count and storage usage shared the monthly user_usage bucket with AI calls, so both incorrectly reset every month even though nothing was deleted. Only AI calls should be monthly. Recipe count and storage are now derived live from real data (recipes, recipe/review photos, avatar) instead of a counter — deleting a photo or recipe is itself the "decrement", no extra wiring needed. Storage size is tracked per-row (recipePhotos.sizeMb, ratings.photoSizeMb, users.avatarSizeMb) and threaded through presign -> upload -> save. Also fixes avatar removal silently no-oping (client sent a field the PATCH schema didn't recognize). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -68,6 +68,7 @@ export function CookedItReview({
|
||||
const [hovered, setHovered] = useState(0);
|
||||
const [text, setText] = useState(initialText);
|
||||
const [photoKey, setPhotoKey] = useState<string | null>(initialPhotoKey);
|
||||
const [photoSizeMb, setPhotoSizeMb] = useState(0);
|
||||
const [preview, setPreview] = useState<string | null>(null);
|
||||
const [uploading, setUploading] = useState(false);
|
||||
const [saving, setSaving] = useState(false);
|
||||
@@ -94,13 +95,14 @@ export function CookedItReview({
|
||||
toast.error(t("reviewPhotoFailed"));
|
||||
return;
|
||||
}
|
||||
const { url, fields, key } = (await res.json()) as { url: string; fields: Record<string, string>; key: string };
|
||||
const { url, fields, key, sizeMb } = (await res.json()) as { url: string; fields: Record<string, string>; key: string; sizeMb: number };
|
||||
const uploaded = await uploadToPresignedPost(url, fields, file);
|
||||
if (!uploaded) {
|
||||
toast.error(t("reviewPhotoFailed"));
|
||||
return;
|
||||
}
|
||||
setPhotoKey(key);
|
||||
setPhotoSizeMb(sizeMb);
|
||||
setPreview(URL.createObjectURL(file));
|
||||
} finally {
|
||||
setUploading(false);
|
||||
@@ -114,7 +116,7 @@ export function CookedItReview({
|
||||
const res = await fetch(`/api/v1/recipes/${recipeId}/rate`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ score, reviewText: text.trim() || undefined, photoKey: photoKey ?? undefined }),
|
||||
body: JSON.stringify({ score, reviewText: text.trim() || undefined, photoKey: photoKey ?? undefined, photoSizeMb }),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const err = (await res.json()) as { error?: string };
|
||||
@@ -159,7 +161,7 @@ export function CookedItReview({
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => { setPhotoKey(null); setPreview(null); }}
|
||||
onClick={() => { setPhotoKey(null); setPreview(null); setPhotoSizeMb(0); }}
|
||||
className="absolute -top-1.5 -right-1.5 rounded-full bg-background border p-0.5"
|
||||
>
|
||||
<X className="h-3 w-3" />
|
||||
|
||||
Reference in New Issue
Block a user