mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-02-14 11:53:11 -05:00
feature/finish-recipe-assets (#384)
* add features to readme
* Copy markdown reference
* prop as whole recipe
* parameter as url instead of query
* add card styling to editor
* move images to /recipes/{slug}/images
* add image to breaking changes
* fix delete and import errors
* fix debug/about response
* logger updates
* dashboard ui
* add server side events
* unorganized routes
* default slot
* add backup viewer to dashboard
* format
* add dialog to backup imports
* initial event support
* delete assets when removed
Co-authored-by: hay-kot <hay-kot@pm.me>
This commit is contained in:
0
mealie/services/recipe/__init__.py
Normal file
0
mealie/services/recipe/__init__.py
Normal file
34
mealie/services/recipe/media.py
Normal file
34
mealie/services/recipe/media.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from pathlib import Path
|
||||
from shutil import copytree, rmtree
|
||||
|
||||
from mealie.core.config import app_dirs
|
||||
from mealie.core.root_logger import get_logger
|
||||
from mealie.schema.recipe import Recipe
|
||||
|
||||
logger = get_logger()
|
||||
|
||||
|
||||
def check_assets(original_slug, recipe: Recipe) -> None:
|
||||
if original_slug != recipe.slug:
|
||||
current_dir = app_dirs.RECIPE_DATA_DIR.joinpath(original_slug)
|
||||
|
||||
try:
|
||||
copytree(current_dir, recipe.directory, dirs_exist_ok=True)
|
||||
|
||||
except FileNotFoundError:
|
||||
logger.error(f"Recipe Directory not Found: {original_slug}")
|
||||
logger.info(f"Renaming Recipe Directory: {original_slug} -> {recipe.slug}")
|
||||
|
||||
all_asset_files = [x.file_name for x in recipe.assets]
|
||||
for file in recipe.asset_dir.iterdir():
|
||||
file: Path
|
||||
if file.is_dir():
|
||||
continue
|
||||
if file.name not in all_asset_files:
|
||||
file.unlink()
|
||||
|
||||
|
||||
def delete_assets(recipe_slug):
|
||||
recipe_dir = Recipe(slug=recipe_slug).directory
|
||||
rmtree(recipe_dir, ignore_errors=True)
|
||||
logger.info(f"Recipe Directory Removed: {recipe_slug}")
|
||||
Reference in New Issue
Block a user