Reject malformed text imports before creating junk recipes

Co-authored-by: fredamn76 <[email protected]>
Signed-off-by: fredamn76 <[email protected]>
This commit is contained in:
Honeyandfredamn76 authored and fredamn76 committed 2026-07-31 09:32:59 +02:00
1 parent 1f10bd321c
commit 620d3b4fe2
2 files changed
+41

No files matched your search

+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