fix: photo import language + no-recipe-recognized handling (v0.29.0)
importFromPhoto() accepted a locale param but silently discarded it (named _locale, never read) — now builds a language instruction the same way generate-recipe.ts does for text generation. The AI output schema had no way to signal "couldn't find a recipe in this image" — generateObject would always fabricate a title/fields. Added a `found` boolean the model sets to false in that case; the route now returns 422 instead of creating a garbage recipe and sending the user into the editor with it. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -158,8 +158,10 @@ export function AiGenerateDialog({
|
||||
body: JSON.stringify({ imageBase64: photoBase64, mimeType: photoMime }),
|
||||
});
|
||||
if (!res.ok) {
|
||||
let msg = t("photoError");
|
||||
try { msg = ((await res.json()) as { error?: string }).error ?? msg; } catch { /* non-JSON body */ }
|
||||
let msg = res.status === 422 ? tRecipe("photoNoRecipeFound") : t("photoError");
|
||||
if (res.status !== 422) {
|
||||
try { msg = ((await res.json()) as { error?: string }).error ?? msg; } catch { /* non-JSON body */ }
|
||||
}
|
||||
toast.error(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ export function PhotoImportButton() {
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
if (res.status === 422) throw new Error(t("photoNoRecipeFound"));
|
||||
const data = await res.json().catch(() => ({})) as { error?: string };
|
||||
throw new Error(data.error ?? `Request failed: ${res.status}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user