diff --git a/CLAUDE.md b/CLAUDE.md index 15f9ab4..599f99b 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -7,7 +7,7 @@ > **Plattform:** Olares One (Kubernetes), Repo und CI auf Gitea — kein Supabase, > kein Vercel (E-0001). Eigene Gestaltung, nicht AImighty (E-0002). > Verteilung über den Markt, Repo öffentlich (E-0005). -> **Status:** 26.11.47 — alle neun Arbeitspakete aus `docs/PROJEKTSTART.md` sind gebaut: +> **Status:** 26.11.48 — alle neun Arbeitspakete aus `docs/PROJEKTSTART.md` sind gebaut: > Anmeldung (Passkeys, Kinder mit Gerät + PIN), Gerichte (Link, Kochbuchfoto, AI über den > Olares Router), Wünschen, Plan, Einkaufsliste (Echtzeit, offline), Kochmodus mit > Bewertung, Web-App; Einzahl bei Stück-Mengen (26.11.15), Preise und Kosten mit Ampel @@ -22,7 +22,7 @@ > (26.11.39, E-0016), Anmelden per Mail-Link über Resend (26.11.40, E-0017; nur > anmelden, keine Geräte oder Passkeys aus einer Mail-Sitzung), Leiste bleibt nach der > Tastatur unten (26.11.41), Icon Kochmütze mit Herz (26.11.42), Fotos aus der Mediathek (26.11.43), gleich große Karten (26.11.44), Runde beenden/löschen/ändern, -> Tage je Gericht von Hand und Kalender-Abo je Haushalt (26.11.45, E-0018), Einkaufsliste einsprechen (26.11.46), Herz für „Mein Gericht“ auf jeder Wunschkarte (26.11.47). Offen: Kai trägt +> Tage je Gericht von Hand und Kalender-Abo je Haushalt (26.11.45, E-0018), Einkaufsliste einsprechen (26.11.46), Herz für „Mein Gericht“ auf jeder Wunschkarte (26.11.47), Kochbuch mit bis zu sechs Seiten (26.11.48). Offen: Kai trägt > den Resend-Schlüssel unter Mehr › Mails verschicken ein und abonniert den Kalender-Link einmal auf dem iPhone. > **Letzte Aktualisierung:** 8. November 2026 diff --git a/OlaresManifest.yaml b/OlaresManifest.yaml index 20fedf0..11a3119 100644 --- a/OlaresManifest.yaml +++ b/OlaresManifest.yaml @@ -21,7 +21,7 @@ metadata: title: foodplanhero description: Plan. Cook. Smile. The family decides together what's for dinner — and the shopping list writes itself. Runs entirely on your own box. icon: https://git.aimighty.olares.de/aimighty/bilder/raw/branch/main/lunch/icon.png - version: 26.11.47 + version: 26.11.48 categories: - Applications @@ -61,7 +61,7 @@ permission: appData: true spec: - versionName: '26.11.47' + versionName: '26.11.48' featuredImage: https://git.aimighty.olares.de/aimighty/bilder/raw/branch/main/lunch/icon.png promoteImage: diff --git a/app/api/dishes/photo-import/route.ts b/app/api/dishes/photo-import/route.ts index 89d2dc0..ab82755 100644 --- a/app/api/dishes/photo-import/route.ts +++ b/app/api/dishes/photo-import/route.ts @@ -8,6 +8,9 @@ import { draftFromRecipe } from "@/lib/recipe-draft"; export const dynamic = "force-dynamic"; +/** Seiten je Rezept (26.11.48); dieselbe Zahl wie in components/dishes/photo-import.tsx. */ +const MAX_PAGES = 6; + // Kochbuchfoto → Entwurf. Das Bildmodell schreibt die Zutatenzeilen wörtlich // ab; Zuordnung und Umrechnung macht die App selbst (lib/recipe-import.ts). // Das Foto wird nicht gespeichert. @@ -17,8 +20,8 @@ export async function POST(request: Request) { const ai = await aiFor(session.householdId); if (!ai?.visionModel) return fail("aiNotConfigured", 409); const form = await request.formData().catch(() => null); - const files = (form?.getAll("photos") ?? []).filter((f): f is File => f instanceof File).slice(0, 2); - if (!files.length) return fail("photo", 400); + const files = (form?.getAll("photos") ?? []).filter((f): f is File => f instanceof File); + if (!files.length || files.length > MAX_PAGES) return fail("photo", 400); let images: string[]; try { images = await Promise.all(files.map(imageForModel)); @@ -30,9 +33,15 @@ export async function POST(request: Request) { try { recipe = recipeFromReply( await askJson(ai, "vision", RECIPE_PROMPT, [ - { type: "text", text: "Read the recipe on these cookbook pages." }, + { + type: "text", + text: + images.length > 1 + ? `Read the recipe on these ${images.length} cookbook pages, in order; it may continue from one page to the next.` + : "Read the recipe on this cookbook page.", + }, ...images.map((url) => ({ type: "image_url" as const, image_url: { url } })), - ]), + ], { timeoutMs: 120_000 + 30_000 * (images.length - 1) }), ); } catch (error) { if (error instanceof AiNotConfigured) return fail("aiNotConfigured", 409); diff --git a/components/dishes/photo-import.tsx b/components/dishes/photo-import.tsx index a324a8b..42115e5 100644 --- a/components/dishes/photo-import.tsx +++ b/components/dishes/photo-import.tsx @@ -1,28 +1,52 @@ "use client"; -import { Camera } from "lucide-react"; +import { Camera, Plus, X } from "lucide-react"; import { useTranslations } from "next-intl"; -import { useState } from "react"; -import { Button } from "@/components/ui/button"; +import { useEffect, useState } from "react"; +import { Button, buttonVariants } from "@/components/ui/button"; import { ErrorNotice } from "@/components/ui/notice"; +import { cn } from "@/lib/utils"; import { DishForm, type DishFormValue } from "./dish-form"; -// Kochbuchfoto → Entwurf. Das Bildmodell liest die Seite (app/api/dishes/photo-import), -// die Person prüft und speichert. Das Foto selbst wird nicht aufbewahrt. +/** Seiten je Rezept (26.11.48, Kai: „mehrere Seiten“). Der Server prüft dasselbe. */ +export const MAX_PAGES = 6; + +type Page = { file: File; url: string }; + +// Kochbuchfoto → Entwurf. Das Bildmodell liest die Seiten (app/api/dishes/photo-import), +// die Person prüft und speichert. Die Fotos selbst werden nicht aufbewahrt. +// Seiten sammeln sich: Jede Aufnahme oder Auswahl kommt hinten dazu — am iPhone +// liefert „Foto aufnehmen“ immer nur ein Bild. export function PhotoImport() { const t = useTranslations("dishes.photo"); - const [files, setFiles] = useState([]); + const [pages, setPages] = useState([]); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); const [draft, setDraft] = useState(null); + // Vorschaubilder freigeben, wenn die Seite verlassen wird. + useEffect(() => () => pages.forEach((p) => URL.revokeObjectURL(p.url)), []); // eslint-disable-line react-hooks/exhaustive-deps + + function add(list: FileList | null) { + const files = Array.from(list ?? []); + setPages((old) => [...old, ...files.slice(0, MAX_PAGES - old.length).map((file) => ({ file, url: URL.createObjectURL(file) }))]); + setError(null); + } + + function remove(index: number) { + setPages((old) => { + URL.revokeObjectURL(old[index]!.url); + return old.filter((_, i) => i !== index); + }); + } + async function read(event: React.FormEvent) { event.preventDefault(); - if (!files.length) return; + if (!pages.length) return; setBusy(true); setError(null); const body = new FormData(); - for (const f of files) body.append("photos", f); + for (const p of pages) body.append("photos", p.file); const res = await fetch("/api/dishes/photo-import", { method: "POST", body }); const data = await res.json().catch(() => ({})); setBusy(false); @@ -34,23 +58,65 @@ export function PhotoImport() { } if (draft) return ; + const full = pages.length >= MAX_PAGES; return (
- + { + add(e.target.files); + e.target.value = ""; // dieselbe Datei darf noch einmal kommen + }} + /> + {pages.length ? ( + <> +
    + {pages.map((p, i) => ( +
  1. + {/* eslint-disable-next-line @next/next/no-img-element */} + {t("page", + {t("page", { n: i + 1 })} + +
  2. + ))} +
+ {full ? ( +

{t("full", { n: MAX_PAGES })}

+ ) : ( + + )} + + ) : ( + + )} {error ? {t(`errors.${error}`)} : null} - {busy ?

{t("readingHint")}

: null} diff --git a/e2e/gerichte.spec.ts b/e2e/gerichte.spec.ts index 958197e..2d8c9d9 100644 --- a/e2e/gerichte.spec.ts +++ b/e2e/gerichte.spec.ts @@ -223,6 +223,8 @@ test.describe("cookbook photo and AI setting", () => { const origin = process.env.IMPORT_TEST_ORIGIN ?? "http://127.0.0.1:3021"; const reply = (r: object) => JSON.stringify({ choices: [{ message: { content: "```json\n" + JSON.stringify(r) + "\n```" } }] }); + let pagesSeen = 0; + test.beforeAll(async () => { const { createServer } = await import("node:http"); server = createServer((req, res) => { @@ -273,6 +275,7 @@ test.describe("cookbook photo and AI setting", () => { // Andere Hausform-Anfragen: Fehler — dann ordnen die Regeln ein. if (raw.includes("house style")) return res.writeHead(500).end(); const withImage = raw.includes("image_url"); + if (withImage) pagesSeen = (raw.match(/"type":"image_url"/g) ?? []).length; res.writeHead(200, { "content-type": "application/json" }).end( withImage ? reply({ title: "Kartoffelsalat aus dem Kochbuch", portions: 4, minutes: 40, ingredients: ["1 kg Kartoffeln", "2 Zwiebeln", "1 Glas Gurken"], steps: ["Kartoffeln kochen.", "Alles mischen."] }) @@ -323,9 +326,19 @@ test.describe("cookbook photo and AI setting", () => { test("a cookbook photo becomes a draft marked as read by the AI", async ({ page }) => { await page.goto("/gerichte/foto"); const jpg = await sharp({ create: { width: 1000, height: 1400, channels: 3, background: { r: 245, g: 240, b: 230 } } }).jpeg().toBuffer(); - await page.locator("input[type=file]").setInputFiles({ name: "seite.jpg", mimeType: "image/jpeg", buffer: jpg }); + // Mehrere Seiten (26.11.48): jede Auswahl kommt hinten dazu, einzelne lassen sich entfernen. + const input = page.locator("input[type=file]"); + await input.setInputFiles({ name: "seite1.jpg", mimeType: "image/jpeg", buffer: jpg }); + await expect(page.getByRole("img", { name: "Seite 1" })).toBeVisible(); + await input.setInputFiles({ name: "seite2.jpg", mimeType: "image/jpeg", buffer: jpg }); + await expect(page.getByRole("img", { name: "Seite 2" })).toBeVisible(); + await page.getByRole("button", { name: "Seite 1 entfernen" }).click(); + await expect(page.getByRole("img", { name: /^Seite/ })).toHaveCount(1); + await input.setInputFiles({ name: "seite3.jpg", mimeType: "image/jpeg", buffer: jpg }); + await expect(page.getByRole("list", { name: "2 Seiten" })).toBeVisible(); await page.getByRole("button", { name: "Rezept lesen" }).click(); await expect(page.locator("#title")).toHaveValue("Kartoffelsalat aus dem Kochbuch"); + expect(pagesSeen).toBe(2); await expect(page.getByRole("note").first()).toContainText("Von der AI gelesen"); await expect(page.getByRole("note").filter({ hasText: "Von der AI in die foodplanhero-Form gebracht" })).toBeVisible(); await expect(page.getByLabel("Schritt 1", { exact: true })).toHaveValue("Kartoffeln waschen."); diff --git a/messages/de.json b/messages/de.json index 6fb387a..da1b776 100644 --- a/messages/de.json +++ b/messages/de.json @@ -505,8 +505,8 @@ "photo": { "title": "Kochbuch fotografieren", "choose": "Seite fotografieren oder wählen", - "chosen": "{n, plural, one {1 Foto gewählt} other {# Fotos gewählt}}", - "chooseHint": "Eine Rezeptseite, höchstens zwei Fotos – neu aufgenommen oder aus der Mediathek. Das Foto wird nicht gespeichert.", + "chosen": "{n, plural, one {1 Seite} other {# Seiten}}", + "chooseHint": "Bis zu {n} Seiten, in der Reihenfolge des Rezepts – neu aufgenommen oder aus der Mediathek. Die Fotos werden nicht gespeichert.", "read": "Rezept lesen", "reading": "Die AI liest …", "readingHint": "Das kann eine Minute dauern.", @@ -519,7 +519,11 @@ "aiUnavailable": "Die AI ist gerade nicht erreichbar. Versuch es später noch einmal.", "aiNotConfigured": "Die AI ist nicht eingerichtet.", "unknown": "Das hat nicht geklappt. Bitte versuch es noch einmal." - } + }, + "addPage": "Weitere Seite hinzufügen", + "page": "Seite {n}", + "removePage": "Seite {n} entfernen", + "full": "Mehr als {n} Seiten gehen nicht auf einmal." }, "wish": "Wünschen", "sections": { diff --git a/messages/en.json b/messages/en.json index ba79bfb..9d7475a 100644 --- a/messages/en.json +++ b/messages/en.json @@ -505,8 +505,8 @@ "photo": { "title": "Photograph a cookbook", "choose": "Take or choose a photo of the page", - "chosen": "{n, plural, one {1 photo chosen} other {# photos chosen}}", - "chooseHint": "One recipe page, at most two photos – new or from your library. The photo is not kept.", + "chosen": "{n, plural, one {1 page} other {# pages}}", + "chooseHint": "Up to {n} pages, in the order of the recipe – taken now or from your library. The photos are not stored.", "read": "Read recipe", "reading": "The AI is reading …", "readingHint": "This can take a minute.", @@ -519,7 +519,11 @@ "aiUnavailable": "The AI cannot be reached right now. Please try again later.", "aiNotConfigured": "The AI is not set up.", "unknown": "That did not work. Please try again." - } + }, + "addPage": "Add another page", + "page": "Page {n}", + "removePage": "Remove page {n}", + "full": "No more than {n} pages at once." }, "wish": "Make a wish", "sections": { diff --git a/messages/es.json b/messages/es.json index 311efe8..c324070 100644 --- a/messages/es.json +++ b/messages/es.json @@ -505,8 +505,8 @@ "photo": { "title": "Photograph a cookbook", "choose": "Take or choose a photo of the page", - "chosen": "{n, plural, one {1 photo chosen} other {# photos chosen}}", - "chooseHint": "One recipe page, at most two photos – new or from your library. The photo is not kept.", + "chosen": "{n, plural, one {1 página} other {# páginas}}", + "chooseHint": "Hasta {n} páginas, en el orden de la receta – tomadas ahora o de la fototeca. Las fotos no se guardan.", "read": "Read recipe", "reading": "The AI is reading …", "readingHint": "This can take a minute.", @@ -519,7 +519,11 @@ "aiUnavailable": "The AI cannot be reached right now. Please try again later.", "aiNotConfigured": "The AI is not set up.", "unknown": "That did not work. Please try again." - } + }, + "addPage": "Añadir otra página", + "page": "Página {n}", + "removePage": "Quitar la página {n}", + "full": "No más de {n} páginas a la vez." }, "wish": "Make a wish", "sections": { diff --git a/messages/fr.json b/messages/fr.json index ff97ad8..86e2726 100644 --- a/messages/fr.json +++ b/messages/fr.json @@ -505,8 +505,8 @@ "photo": { "title": "Photograph a cookbook", "choose": "Take or choose a photo of the page", - "chosen": "{n, plural, one {1 photo chosen} other {# photos chosen}}", - "chooseHint": "One recipe page, at most two photos – new or from your library. The photo is not kept.", + "chosen": "{n, plural, one {1 page} other {# pages}}", + "chooseHint": "Jusqu’à {n} pages, dans l’ordre de la recette – prises maintenant ou depuis la photothèque. Les photos ne sont pas conservées.", "read": "Read recipe", "reading": "The AI is reading …", "readingHint": "This can take a minute.", @@ -519,7 +519,11 @@ "aiUnavailable": "The AI cannot be reached right now. Please try again later.", "aiNotConfigured": "The AI is not set up.", "unknown": "That did not work. Please try again." - } + }, + "addPage": "Ajouter une page", + "page": "Page {n}", + "removePage": "Retirer la page {n}", + "full": "Pas plus de {n} pages à la fois." }, "wish": "Make a wish", "sections": { diff --git a/olares/Chart.yaml b/olares/Chart.yaml index c78d218..e9a125a 100644 --- a/olares/Chart.yaml +++ b/olares/Chart.yaml @@ -2,5 +2,5 @@ apiVersion: v2 name: lunch description: foodplanhero (Plan. Cook. Smile.) — die Familie entscheidet gemeinsam, was es gibt; aus dem Plan entsteht die Einkaufsliste type: application -version: 26.11.47 # YY.M. wie im AImighty-Markt — bei jeder Chart-Änderung erhöhen -appVersion: "26.11.47" # MUSS gleich version sein: der Linter prüft es, und der Image-Tag hängt daran +version: 26.11.48 # YY.M. wie im AImighty-Markt — bei jeder Chart-Änderung erhöhen +appVersion: "26.11.48" # MUSS gleich version sein: der Linter prüft es, und der Image-Tag hängt daran diff --git a/olares/OlaresManifest.yaml b/olares/OlaresManifest.yaml index 20fedf0..11a3119 100644 --- a/olares/OlaresManifest.yaml +++ b/olares/OlaresManifest.yaml @@ -21,7 +21,7 @@ metadata: title: foodplanhero description: Plan. Cook. Smile. The family decides together what's for dinner — and the shopping list writes itself. Runs entirely on your own box. icon: https://git.aimighty.olares.de/aimighty/bilder/raw/branch/main/lunch/icon.png - version: 26.11.47 + version: 26.11.48 categories: - Applications @@ -61,7 +61,7 @@ permission: appData: true spec: - versionName: '26.11.47' + versionName: '26.11.48' featuredImage: https://git.aimighty.olares.de/aimighty/bilder/raw/branch/main/lunch/icon.png promoteImage: diff --git a/olares/markt/26.11.48.md b/olares/markt/26.11.48.md new file mode 100644 index 0000000..e84887f --- /dev/null +++ b/olares/markt/26.11.48.md @@ -0,0 +1,5 @@ +# Cookbook photos with several pages +v26.11.48: A cookbook recipe can now span up to six pages. Each photo you take or pick is added to the others, shown as Page 1, Page 2 and so on, and any page can be removed again. The AI reads the pages in order as one recipe. The photos are not stored. + +## Deutsch +v26.11.48: Ein Rezept aus dem Kochbuch darf jetzt bis zu sechs Seiten haben. Jedes aufgenommene oder gewählte Foto kommt zu den anderen dazu, als Seite 1, Seite 2 und so weiter, und jede Seite lässt sich wieder entfernen. Die AI liest die Seiten der Reihe nach als ein Rezept. Die Fotos werden nicht gespeichert.