mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-05-14 13:57:29 -04:00
feat: Add DELETE /{slug}/image (#6259)
Co-authored-by: Michael Genson <71845777+michael-genson@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
7bb0f0801a
commit
bb67d993a0
@@ -8,6 +8,7 @@ from pydantic import UUID4
|
||||
from mealie.pkgs import img, safehttp
|
||||
from mealie.pkgs.safehttp.transport import AsyncSafeTransport
|
||||
from mealie.schema.recipe.recipe import Recipe
|
||||
from mealie.schema.recipe.recipe_image_types import RecipeImageTypes
|
||||
from mealie.services._base_service import BaseService
|
||||
from mealie.services.scraper.user_agents_manager import get_user_agents_manager
|
||||
|
||||
@@ -104,6 +105,14 @@ class RecipeDataService(BaseService):
|
||||
|
||||
return image_path
|
||||
|
||||
def delete_image(self, image_dir: Path | None = None):
|
||||
if not image_dir:
|
||||
image_dir = self.dir_image
|
||||
|
||||
for img_type in RecipeImageTypes:
|
||||
image_path = image_dir.joinpath(img_type.value)
|
||||
image_path.unlink(missing_ok=True)
|
||||
|
||||
async def scrape_image(self, image_url: str | dict[str, str] | list[str]) -> None:
|
||||
self.logger.info(f"Image URL: {image_url}")
|
||||
user_agent = get_user_agents_manager().user_agents[0]
|
||||
|
||||
@@ -418,6 +418,17 @@ class RecipeService(RecipeServiceBase):
|
||||
|
||||
return self.group_recipes.update_image(slug, extension)
|
||||
|
||||
def delete_recipe_image(self, slug: str) -> None:
|
||||
recipe = self.get_one(slug)
|
||||
if not self.can_update(recipe):
|
||||
raise exceptions.PermissionDenied("You do not have permission to edit this recipe.")
|
||||
|
||||
data_service = RecipeDataService(recipe.id)
|
||||
data_service.delete_image()
|
||||
|
||||
self.group_recipes.delete_image(slug)
|
||||
return None
|
||||
|
||||
def patch_one(self, slug_or_id: str | UUID, patch_data: Recipe) -> Recipe:
|
||||
recipe: Recipe = self._pre_update_check(slug_or_id, patch_data)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user