* fixes #625

* update dependencies

* bump version

* fix failing tests

Co-authored-by: hay-kot <hay-kot@pm.me>
This commit is contained in:
Hayden
2021-07-25 12:55:30 -08:00
committed by GitHub
parent bf06482b29
commit 940663a22d
14 changed files with 214 additions and 193 deletions

View File

@@ -6,7 +6,7 @@ from typing import Any, Optional, Union
import dotenv
from pydantic import BaseSettings, Field, PostgresDsn, validator
APP_VERSION = "v0.5.1"
APP_VERSION = "v0.5.2"
DB_VERSION = "v0.5.0"
CWD = Path(__file__).parent

View File

@@ -5,5 +5,6 @@ from . import crud, helpers, mealplans
meal_plan_router = APIRouter()
meal_plan_router.include_router(crud.router)
meal_plan_router.include_router(crud.public_router)
meal_plan_router.include_router(helpers.router)
meal_plan_router.include_router(mealplans.router)

View File

@@ -1,4 +1,4 @@
from fastapi import BackgroundTasks, Depends, HTTPException, status
from fastapi import APIRouter, BackgroundTasks, 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
@@ -12,6 +12,7 @@ from sqlalchemy.orm.session import Session
from starlette.responses import FileResponse
router = UserAPIRouter(prefix="/api/meal-plans", tags=["Meal Plan"])
public_router = APIRouter(prefix="/api/meal-plans", tags=["Meal Plan"])
@router.get("/all", response_model=list[MealPlanOut])
@@ -46,7 +47,7 @@ def get_today(session: Session = Depends(generate_session), current_user: UserIn
return recipe
@router.get("/today/image", tags=["Meal Plan"])
@public_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.
@@ -54,16 +55,13 @@ def get_todays_image(session: Session = Depends(generate_session), group_name: s
group_in_db: GroupInDB = db.groups.get(session, group_name, "name")
recipe = get_todays_meal(session, group_in_db)
recipe_image = recipe.image_dir.joinpath(image.ImageOptions.ORIGINAL_IMAGE)
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:
if not recipe and not recipe_image.exists():
raise HTTPException(status.HTTP_404_NOT_FOUND)
return FileResponse(recipe_image)
@router.get("/{id}", response_model=MealPlanOut)
def get_meal_plan(

View File

@@ -84,7 +84,7 @@ def get_recipe(recipe_slug: str, session: Session = Depends(generate_session), i
if not recipe:
raise HTTPException(status.HTTP_404_NOT_FOUND)
print(recipe.settings.public, is_user)
if recipe.settings.public or is_user:
return recipe

View File

@@ -1,5 +1,6 @@
from apscheduler.jobstores.sqlalchemy import SQLAlchemyJobStore
from apscheduler.schedulers.background import BackgroundScheduler
from mealie.core.config import settings
from mealie.core.config import app_dirs, settings
app_dirs.DATA_DIR.joinpath("scheduler.db").unlink(missing_ok=True)
scheduler = BackgroundScheduler(jobstores={"default": SQLAlchemyJobStore(settings.SCHEDULER_DATABASE)})

View File

@@ -36,9 +36,16 @@ def clean(recipe_data: dict, url=None) -> dict:
def clean_string(text: str) -> str:
if isinstance(text, list):
text = text[0]
print(type(text))
if text == "" or text is None:
return ""
print(text)
cleaned_text = html.unescape(text)
cleaned_text = re.sub("<[^<]+?>", "", cleaned_text)
cleaned_text = re.sub(" +", " ", cleaned_text)

View File

@@ -18,7 +18,7 @@ def og_fields(properties: list[Tuple[str, str]], field_name: str) -> list[str]:
def basic_recipe_from_opengraph(html: str, url: str) -> dict:
base_url = get_base_url(html, url)
data = extruct.extract(html, base_url=base_url)
data = extruct.extract(html, base_url=base_url, errors="log")
try:
properties = data["opengraph"][0]["properties"]
except Exception: