Reject malformed text imports before creating junk recipes

Co-authored-by: fredamn76 <fredrik.fallman@gmail.com>
Signed-off-by: fredamn76 <fredrik.fallman@gmail.com>
This commit is contained in:
2026-07-31 09:32:59 +02:00
committed by fredamn76
parent 1f10bd321c
commit 620d3b4fe2
2 changed files with 41 additions and 0 deletions
+11
View File
@@ -288,6 +288,17 @@ def import_recipe_text(text: str, source_url: str | None = None) -> dict[str, An
roundup, a YouTube description, or a social caption. Build the text in Swedish
with ``Titel`` / ``Portioner`` / ``Ingredienser`` / ``Gör så här`` sections.
"""
required = ("Titel", "Ingredienser", "Gör så här")
missing = [
heading
for heading in required
if not re.search(rf"(?im)^\s*{re.escape(heading)}\s*:", text)
]
if missing:
raise ValueError(
"Text import requires explicit Swedish section headings; missing: "
+ ", ".join(missing)
)
payload: dict[str, Any] = {"data": text}
if source_url:
payload["url"] = source_url