mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-02-07 16:33:10 -05:00
Basic nutrition editor (#288)
* Basic nutrition editor * fix no image on scrape * nutrition display * add recipe images * update by url * new upload options Co-authored-by: hay-kot <hay-kot@pm.me>
This commit is contained in:
@@ -62,12 +62,16 @@ def write_image(recipe_slug: str, file_data: bytes, extension: str) -> Path:
|
||||
extension = extension.replace(".", "")
|
||||
image_path = image_dir.joinpath(f"original.{extension}")
|
||||
|
||||
if isinstance(file_data, bytes):
|
||||
if isinstance(file_data, Path):
|
||||
shutil.copy2(file_data, image_path)
|
||||
elif isinstance(file_data, bytes):
|
||||
with open(image_path, "ab") as f:
|
||||
f.write(file_data)
|
||||
else:
|
||||
shutil.copy2(file_data, image_path)
|
||||
with open(image_path, "ab") as f:
|
||||
shutil.copyfileobj(file_data, f)
|
||||
|
||||
print(image_path)
|
||||
minify.minify_image(image_path)
|
||||
|
||||
return image_path
|
||||
@@ -105,7 +109,7 @@ def scrape_image(image_url: str, slug: str) -> Path:
|
||||
|
||||
write_image(slug, r.raw, filename.suffix)
|
||||
|
||||
filename.unlink()
|
||||
filename.unlink(missing_ok=True)
|
||||
|
||||
return slug
|
||||
|
||||
|
||||
Reference in New Issue
Block a user