From 51ce0e105016b8e9b28780d5850ee8051aacfbb2 Mon Sep 17 00:00:00 2001 From: hay-kot Date: Wed, 10 Feb 2021 10:04:53 -0900 Subject: [PATCH] bug/image save fix --- mealie/db/database.py | 2 +- mealie/routes/recipe/recipe_crud_routes.py | 7 +++++-- mealie/services/recipe_services.py | 7 ++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/mealie/db/database.py b/mealie/db/database.py index 1d0d2b737..8b230165c 100644 --- a/mealie/db/database.py +++ b/mealie/db/database.py @@ -17,7 +17,7 @@ class _Recipes(BaseDocument): self.primary_key = "slug" self.sql_model = RecipeModel - def update_image(self, session: Session, slug: str, extension: str) -> str: + def update_image(self, session: Session, slug: str, extension: str = None) -> str: entry: RecipeModel = self._query_one(session, match_value=slug) entry.image = f"{slug}.{extension}" session.commit() diff --git a/mealie/routes/recipe/recipe_crud_routes.py b/mealie/routes/recipe/recipe_crud_routes.py index f42bf0f56..04694e7ce 100644 --- a/mealie/routes/recipe/recipe_crud_routes.py +++ b/mealie/routes/recipe/recipe_crud_routes.py @@ -75,10 +75,13 @@ async def get_recipe_img(recipe_slug: str): @router.put("/{recipe_slug}/image") def update_recipe_image( - recipe_slug: str, image: bytes = File(...), extension: str = Form(...) + recipe_slug: str, + image: bytes = File(...), + extension: str = Form(...), + session: Session = Depends(generate_session), ): """ Removes an existing image and replaces it with the incoming file. """ response = write_image(recipe_slug, image, extension) - Recipe.update_image(recipe_slug, extension) + Recipe.update_image(session, recipe_slug, extension) return response diff --git a/mealie/services/recipe_services.py b/mealie/services/recipe_services.py index f95cb7291..1d0c254fd 100644 --- a/mealie/services/recipe_services.py +++ b/mealie/services/recipe_services.py @@ -115,7 +115,7 @@ class Recipe(BaseModel): return updated_slug.get("slug") @staticmethod - def update_image(slug: str, extension: str) -> str: + def update_image(session: Session, slug: str, extension: str = None) -> str: """A helper function to pass the new image name and extension into the database. @@ -123,11 +123,8 @@ class Recipe(BaseModel): slug (str): The current recipe slug extension (str): the file extension of the new image """ - return db.recipes.update_image(slug, extension) + return db.recipes.update_image(session, slug, extension) @staticmethod def get_all(session: Session): return db.recipes.get_all(session) - - -