1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-08-05 21:45:25 +02:00

fix: Tandoor doesn't import all images (#2487)

* use glob to find files for import

* bark bark

* add catch for invalid image files
This commit is contained in:
Michael Genson 2023-08-09 21:52:32 -05:00 committed by GitHub
parent 04c7e068d8
commit dd947c316a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View file

@ -97,7 +97,11 @@ class TandoorMigrator(BaseMigrator):
if serving_size and serving_text:
recipe_data["recipeYield"] = f"{serving_size} {serving_text}"
recipe_data["image"] = str(source_dir.joinpath("image.jpeg"))
try:
recipe_image_path = next(source_dir.glob("image.*"))
recipe_data["image"] = str(recipe_image_path)
except StopIteration:
pass
return recipe_data
def _migrate(self) -> None:
@ -117,7 +121,11 @@ class TandoorMigrator(BaseMigrator):
recipe_zip.extractall(recipe_dir)
recipe_source_dir = Path(recipe_dir)
recipe_json_path = recipe_source_dir.joinpath("recipe.json")
try:
recipe_json_path = next(recipe_source_dir.glob("*.json"))
except StopIteration as e:
raise Exception("recipe.json not found") from e
with open(recipe_json_path) as f:
recipes_as_dicts.append(self._process_recipe_document(recipe_source_dir, json.load(f)))

View file

@ -2,6 +2,7 @@ import json
from pathlib import Path
import yaml
from PIL import UnidentifiedImageError
from pydantic import UUID4
from mealie.services.recipe.recipe_data_service import RecipeDataService
@ -94,4 +95,8 @@ def import_image(src: str | Path, recipe_id: UUID4):
return
data_service = RecipeDataService(recipe_id=recipe_id)
data_service.write_image(src, src.suffix)
try:
data_service.write_image(src, src.suffix)
except UnidentifiedImageError:
return