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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user