mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-02-19 22:33:11 -05:00
refactor(backend): ♻️ align variable names, eliminate dead-code, and finalize recipe services
This commit is contained in:
@@ -14,33 +14,33 @@ from mealie.services.image.image import scrape_image, write_image
|
||||
user_router = UserAPIRouter()
|
||||
|
||||
|
||||
@user_router.post("/{recipe_slug}/image")
|
||||
@user_router.post("/{slug}/image")
|
||||
def scrape_image_url(
|
||||
recipe_slug: str,
|
||||
slug: str,
|
||||
url: CreateRecipeByURL,
|
||||
):
|
||||
""" Removes an existing image and replaces it with the incoming file. """
|
||||
|
||||
scrape_image(url.url, recipe_slug)
|
||||
scrape_image(url.url, slug)
|
||||
|
||||
|
||||
@user_router.put("/{recipe_slug}/image")
|
||||
@user_router.put("/{slug}/image")
|
||||
def update_recipe_image(
|
||||
recipe_slug: str,
|
||||
slug: str,
|
||||
image: bytes = File(...),
|
||||
extension: str = Form(...),
|
||||
session: Session = Depends(generate_session),
|
||||
):
|
||||
""" Removes an existing image and replaces it with the incoming file. """
|
||||
write_image(recipe_slug, image, extension)
|
||||
new_version = db.recipes.update_image(session, recipe_slug, extension)
|
||||
write_image(slug, image, extension)
|
||||
new_version = db.recipes.update_image(session, slug, extension)
|
||||
|
||||
return {"image": new_version}
|
||||
|
||||
|
||||
@user_router.post("/{recipe_slug}/assets", response_model=RecipeAsset)
|
||||
@user_router.post("/{slug}/assets", response_model=RecipeAsset)
|
||||
def upload_recipe_asset(
|
||||
recipe_slug: str,
|
||||
slug: str,
|
||||
name: str = Form(...),
|
||||
icon: str = Form(...),
|
||||
extension: str = Form(...),
|
||||
@@ -50,7 +50,7 @@ def upload_recipe_asset(
|
||||
""" Upload a file to store as a recipe asset """
|
||||
file_name = slugify(name) + "." + extension
|
||||
asset_in = RecipeAsset(name=name, icon=icon, file_name=file_name)
|
||||
dest = Recipe(slug=recipe_slug).asset_dir.joinpath(file_name)
|
||||
dest = Recipe(slug=slug).asset_dir.joinpath(file_name)
|
||||
|
||||
with dest.open("wb") as buffer:
|
||||
copyfileobj(file.file, buffer)
|
||||
@@ -58,7 +58,7 @@ def upload_recipe_asset(
|
||||
if not dest.is_file():
|
||||
raise HTTPException(status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||||
|
||||
recipe: Recipe = db.recipes.get(session, recipe_slug)
|
||||
recipe: Recipe = db.recipes.get(session, slug)
|
||||
recipe.assets.append(asset_in)
|
||||
db.recipes.update(session, recipe_slug, recipe.dict())
|
||||
db.recipes.update(session, slug, recipe.dict())
|
||||
return asset_in
|
||||
|
||||
Reference in New Issue
Block a user