mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-02-10 01:43:11 -05:00
Bug Fixes (#467)
* fixes #463 * fixes #465 * fixes #461 * fixes #458 key error * Fixes #459 * Fixes comments shown when printing * fix meal-image not return on API call * return better status * reorganize docs Co-authored-by: hay-kot <hay-kot@pm.me>
This commit is contained in:
@@ -45,6 +45,25 @@ def get_today(session: Session = Depends(generate_session), current_user: UserIn
|
||||
return recipe
|
||||
|
||||
|
||||
@router.get("/today/image", tags=["Meal Plan"])
|
||||
def get_todays_image(session: Session = Depends(generate_session), group_name: str = "Home"):
|
||||
"""
|
||||
Returns the image for todays meal-plan.
|
||||
"""
|
||||
|
||||
group_in_db: GroupInDB = db.groups.get(session, group_name, "name")
|
||||
recipe = get_todays_meal(session, group_in_db)
|
||||
|
||||
if recipe:
|
||||
recipe_image = recipe.image_dir.joinpath(image.ImageOptions.ORIGINAL_IMAGE)
|
||||
else:
|
||||
raise HTTPException(status.HTTP_404_NOT_FOUND)
|
||||
if recipe_image:
|
||||
return FileResponse(recipe_image)
|
||||
else:
|
||||
raise HTTPException(status.HTTP_404_NOT_FOUND)
|
||||
|
||||
|
||||
@router.get("/{id}", response_model=MealPlanOut)
|
||||
def get_meal_plan(
|
||||
id,
|
||||
@@ -106,22 +125,3 @@ def delete_meal_plan(
|
||||
)
|
||||
except Exception:
|
||||
raise HTTPException(status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
|
||||
@router.get("/today/image", tags=["Meal Plan"])
|
||||
def get_todays_image(session: Session = Depends(generate_session), group_name: str = "Home"):
|
||||
"""
|
||||
Returns the image for todays meal-plan.
|
||||
"""
|
||||
|
||||
group_in_db: GroupInDB = db.groups.get(session, group_name, "name")
|
||||
recipe = get_todays_meal(session, group_in_db)
|
||||
|
||||
if recipe:
|
||||
recipe_image = recipe.image_dir.joinpath(image.ImageOptions.ORIGINAL_IMAGE)
|
||||
else:
|
||||
raise HTTPException(status.HTTP_404_NOT_FOUND)
|
||||
if recipe_image:
|
||||
return FileResponse(recipe_image)
|
||||
else:
|
||||
raise HTTPException(status.HTTP_404_NOT_FOUND)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
from mealie.db.database import db
|
||||
from mealie.db.db_setup import generate_session
|
||||
from mealie.routes.deps import get_current_user
|
||||
@@ -35,4 +35,7 @@ def test_webhooks(
|
||||
""" Run the function to test your webhooks """
|
||||
group_entry: GroupInDB = db.groups.get(session, current_user.group, "name")
|
||||
|
||||
return post_webhooks(group_entry.id, session)
|
||||
try:
|
||||
post_webhooks(group_entry.id, session)
|
||||
except Exception:
|
||||
return HTTPException(status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||||
|
||||
@@ -12,9 +12,9 @@ logger = root_logger.get_logger()
|
||||
|
||||
@dataclass
|
||||
class ImageOptions:
|
||||
ORIGINAL_IMAGE: str = "original*"
|
||||
MINIFIED_IMAGE: str = "min-original*"
|
||||
TINY_IMAGE: str = "tiny-original*"
|
||||
ORIGINAL_IMAGE: str = "original.webp"
|
||||
MINIFIED_IMAGE: str = "min-original.webp"
|
||||
TINY_IMAGE: str = "tiny-original.webp"
|
||||
|
||||
|
||||
IMG_OPTIONS = ImageOptions()
|
||||
|
||||
@@ -33,7 +33,7 @@ class Cleaner:
|
||||
|
||||
recipe_data["recipeYield"] = Cleaner.yield_amount(recipe_data.get("recipeYield"))
|
||||
recipe_data["recipeIngredient"] = Cleaner.ingredient(recipe_data.get("recipeIngredient"))
|
||||
recipe_data["recipeInstructions"] = Cleaner.instructions(recipe_data["recipeInstructions"])
|
||||
recipe_data["recipeInstructions"] = Cleaner.instructions(recipe_data.get("recipeInstructions"))
|
||||
recipe_data["image"] = Cleaner.image(recipe_data.get("image"))
|
||||
recipe_data["slug"] = slugify(recipe_data.get("name"))
|
||||
recipe_data["orgURL"] = url
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import json
|
||||
|
||||
import requests
|
||||
from mealie.db.database import db
|
||||
from mealie.db.db_setup import create_session
|
||||
@@ -7,11 +9,11 @@ from mealie.services.meal_services import get_todays_meal
|
||||
from sqlalchemy.orm.session import Session
|
||||
|
||||
|
||||
def post_webhooks(group: int, session: Session = None):
|
||||
def post_webhooks(group: int, session: Session = None, force=True):
|
||||
session = session or create_session()
|
||||
group_settings: GroupInDB = db.groups.get(session, group)
|
||||
|
||||
if not group_settings.webhook_enable:
|
||||
if not group_settings.webhook_enable and not force:
|
||||
return
|
||||
|
||||
todays_recipe = get_todays_meal(session, group)
|
||||
@@ -20,7 +22,7 @@ def post_webhooks(group: int, session: Session = None):
|
||||
return
|
||||
|
||||
for url in group_settings.webhook_urls:
|
||||
requests.post(url, json=todays_recipe.json())
|
||||
requests.post(url, json=json.loads(todays_recipe.json(by_alias=True)))
|
||||
|
||||
create_scheduled_event("Meal Plan Webhook", f"Meal plan webhook executed for group '{group}'")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user