mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-22 22:43:34 -07:00
read image options
This commit is contained in:
parent
1a51e29d4d
commit
8128f2675f
1 changed files with 28 additions and 5 deletions
|
@ -1,4 +1,5 @@
|
||||||
import shutil
|
import shutil
|
||||||
|
from dataclasses import dataclass
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
@ -6,14 +7,36 @@ from fastapi.logger import logger
|
||||||
from mealie.core.config import app_dirs
|
from mealie.core.config import app_dirs
|
||||||
|
|
||||||
|
|
||||||
def read_image(recipe_slug: str) -> Path:
|
@dataclass
|
||||||
if app_dirs.IMG_DIR.joinpath(recipe_slug).is_file():
|
class ImageOptions:
|
||||||
return app_dirs.IMG_DIR.joinpath(recipe_slug)
|
ORIGINAL_IMAGE: str = "original*"
|
||||||
|
MINIFIED_IMAGE: str = "min-original*"
|
||||||
|
TINY_IMAGE: str = "tiny-original*"
|
||||||
|
|
||||||
recipe_slug = recipe_slug.split(".")[0]
|
|
||||||
for file in app_dirs.IMG_DIR.glob(f"{recipe_slug}*"):
|
IMG_OPTIONS = ImageOptions()
|
||||||
|
|
||||||
|
|
||||||
|
def read_image(recipe_slug: str, image_type: str = "original") -> Path:
|
||||||
|
"""returns the path to the image file for the recipe base of image_type
|
||||||
|
|
||||||
|
Args:
|
||||||
|
recipe_slug (str): Recipe Slug
|
||||||
|
image_type (str, optional): Glob Style Matcher "original*" | "min-original* | "tiny-original*"
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Path: [description]
|
||||||
|
"""
|
||||||
|
recipe_slug = recipe_slug.split(".")[0] # Incase of File Name
|
||||||
|
recipe_image_dir = app_dirs.IMG_DIR.joinpath(recipe_slug)
|
||||||
|
|
||||||
|
glob_string = "original*" if image_type else "min-original*"
|
||||||
|
|
||||||
|
for file in recipe_image_dir.glob(glob_string):
|
||||||
return file
|
return file
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def write_image(recipe_slug: str, file_data: bytes, extension: str) -> Path.name:
|
def write_image(recipe_slug: str, file_data: bytes, extension: str) -> Path.name:
|
||||||
delete_image(recipe_slug)
|
delete_image(recipe_slug)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue