26.11.48: Kochbuch mit mehreren Seiten #49

Merged
kai merged 1 commits from claude/kochbuch-seiten into main 2026-11-08 13:13:50 +00:00
12 changed files with 156 additions and 47 deletions

No files matched your search

+2 -2
View File
@@ -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
+2 -2
View File
@@ -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:
+13 -4
View File
@@ -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);
+88 -22
View File
@@ -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<File[]>([]);
const [pages, setPages] = useState<Page[]>([]);
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const [draft, setDraft] = useState<DishFormValue | null>(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 <DishForm initial={draft} />;
const full = pages.length >= MAX_PAGES;
return (
<form onSubmit={read} className="flex flex-col gap-4">
<label className="flex min-h-32 cursor-pointer flex-col items-center justify-center gap-2 rounded-2xl border border-dashed border-border p-6 text-center focus-within:ring-2 focus-within:ring-ring">
<Camera aria-hidden className="size-8 text-accent" strokeWidth={1.5} />
<span className="font-semibold">{files.length ? t("chosen", { n: files.length }) : t("choose")}</span>
<span className="text-sm text-muted-foreground">{t("chooseHint")}</span>
<input
type="file"
accept="image/*"
multiple
className="sr-only"
aria-label={t("choose")}
onChange={(e) => setFiles(Array.from(e.target.files ?? []).slice(0, 2))}
/>
</label>
<input
id="cookbook-pages"
type="file"
accept="image/*"
multiple
className="sr-only"
aria-label={pages.length ? t("addPage") : t("choose")}
disabled={full || busy}
onChange={(e) => {
add(e.target.files);
e.target.value = ""; // dieselbe Datei darf noch einmal kommen
}}
/>
{pages.length ? (
<>
<ol aria-label={t("chosen", { n: pages.length })} className="grid grid-cols-3 gap-3">
{pages.map((p, i) => (
<li key={p.url} className="relative overflow-hidden rounded-xl border border-border">
{/* eslint-disable-next-line @next/next/no-img-element */}
<img src={p.url} alt={t("page", { n: i + 1 })} className="aspect-[3/4] w-full object-cover" />
<span className="absolute bottom-1 left-1 rounded-full bg-background/90 px-2 py-0.5 text-xs font-semibold">{t("page", { n: i + 1 })}</span>
<button
type="button"
aria-label={t("removePage", { n: i + 1 })}
disabled={busy}
onClick={() => remove(i)}
className="absolute right-0 top-0 flex size-11 items-center justify-center focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
>
<span className="flex size-8 items-center justify-center rounded-full bg-background/90">
<X aria-hidden className="size-4" />
</span>
</button>
</li>
))}
</ol>
{full ? (
<p className="text-sm text-muted-foreground">{t("full", { n: MAX_PAGES })}</p>
) : (
<label htmlFor="cookbook-pages" className={cn(buttonVariants({ variant: "outline" }), "cursor-pointer")}>
<Plus aria-hidden />
{t("addPage")}
</label>
)}
</>
) : (
<label
htmlFor="cookbook-pages"
className="flex min-h-32 cursor-pointer flex-col items-center justify-center gap-2 rounded-2xl border border-dashed border-border p-6 text-center"
>
<Camera aria-hidden className="size-8 text-accent" strokeWidth={1.5} />
<span className="font-semibold">{t("choose")}</span>
<span className="text-sm text-muted-foreground">{t("chooseHint", { n: MAX_PAGES })}</span>
</label>
)}
{error ? <ErrorNotice>{t(`errors.${error}`)}</ErrorNotice> : null}
<Button type="submit" size="lg" disabled={busy || !files.length}>
<Button type="submit" size="lg" disabled={busy || !pages.length}>
{busy ? t("reading") : t("read")}
</Button>
{busy ? <p className="text-center text-sm text-muted-foreground">{t("readingHint")}</p> : null}
+14 -1
View File
@@ -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.");
+7 -3
View File
@@ -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": {
+7 -3
View File
@@ -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": {
+7 -3
View File
@@ -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": {
+7 -3
View File
@@ -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": {
+2 -2
View File
@@ -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.<n> 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.<n> 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
+2 -2
View File
@@ -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:
+5
View File
@@ -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.