mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-22 14:33:33 -07:00
bug/image save fix
This commit is contained in:
parent
866e7de498
commit
51ce0e1050
3 changed files with 8 additions and 8 deletions
|
@ -17,7 +17,7 @@ class _Recipes(BaseDocument):
|
||||||
self.primary_key = "slug"
|
self.primary_key = "slug"
|
||||||
self.sql_model = RecipeModel
|
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: RecipeModel = self._query_one(session, match_value=slug)
|
||||||
entry.image = f"{slug}.{extension}"
|
entry.image = f"{slug}.{extension}"
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
|
@ -75,10 +75,13 @@ async def get_recipe_img(recipe_slug: str):
|
||||||
|
|
||||||
@router.put("/{recipe_slug}/image")
|
@router.put("/{recipe_slug}/image")
|
||||||
def update_recipe_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. """
|
""" Removes an existing image and replaces it with the incoming file. """
|
||||||
response = write_image(recipe_slug, image, extension)
|
response = write_image(recipe_slug, image, extension)
|
||||||
Recipe.update_image(recipe_slug, extension)
|
Recipe.update_image(session, recipe_slug, extension)
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
|
@ -115,7 +115,7 @@ class Recipe(BaseModel):
|
||||||
return updated_slug.get("slug")
|
return updated_slug.get("slug")
|
||||||
|
|
||||||
@staticmethod
|
@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
|
"""A helper function to pass the new image name and extension
|
||||||
into the database.
|
into the database.
|
||||||
|
|
||||||
|
@ -123,11 +123,8 @@ class Recipe(BaseModel):
|
||||||
slug (str): The current recipe slug
|
slug (str): The current recipe slug
|
||||||
extension (str): the file extension of the new image
|
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
|
@staticmethod
|
||||||
def get_all(session: Session):
|
def get_all(session: Session):
|
||||||
return db.recipes.get_all(session)
|
return db.recipes.get_all(session)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue