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:
1 parent
1f10bd321c
commit
620d3b4fe2
2 files changed
+41
No files matched your search
@@ -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