mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-22 14:33:33 -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
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
import requests
|
||||
|
@ -6,14 +7,36 @@ from fastapi.logger import logger
|
|||
from mealie.core.config import app_dirs
|
||||
|
||||
|
||||
def read_image(recipe_slug: str) -> Path:
|
||||
if app_dirs.IMG_DIR.joinpath(recipe_slug).is_file():
|
||||
return app_dirs.IMG_DIR.joinpath(recipe_slug)
|
||||
@dataclass
|
||||
class ImageOptions:
|
||||
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 None
|
||||
|
||||
|
||||
def write_image(recipe_slug: str, file_data: bytes, extension: str) -> Path.name:
|
||||
delete_image(recipe_slug)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue