mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-22 06:23:34 -07:00
upgrade to new tag method
This commit is contained in:
parent
046d8e4bc8
commit
c86b7a328b
6 changed files with 49 additions and 45 deletions
|
@ -1,28 +1,33 @@
|
||||||
|
import operator
|
||||||
|
|
||||||
|
from app_config import BACKUP_DIR, TEMPLATE_DIR
|
||||||
from fastapi import APIRouter, HTTPException
|
from fastapi import APIRouter, HTTPException
|
||||||
from models.backup_models import BackupJob, Imports
|
from models.backup_models import BackupJob, ImportJob, Imports, LocalBackup
|
||||||
from services.backups.exports import backup_all
|
from services.backups.exports import backup_all
|
||||||
from services.backups.imports import ImportDatabase
|
from services.backups.imports import ImportDatabase
|
||||||
from settings import BACKUP_DIR, TEMPLATE_DIR
|
|
||||||
from utils.snackbar import SnackResponse
|
from utils.snackbar import SnackResponse
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter(tags=["Import / Export"])
|
||||||
|
|
||||||
|
|
||||||
@router.get("/api/backups/available/", tags=["Import / Export"], response_model=Imports)
|
@router.get("/api/backups/available/", response_model=Imports)
|
||||||
def available_imports():
|
def available_imports():
|
||||||
"""Returns a list of avaiable .zip files for import into Mealie."""
|
"""Returns a list of avaiable .zip files for import into Mealie."""
|
||||||
imports = []
|
imports = []
|
||||||
templates = []
|
templates = []
|
||||||
for archive in BACKUP_DIR.glob("*.zip"):
|
for archive in BACKUP_DIR.glob("*.zip"):
|
||||||
imports.append(archive.name)
|
backup = LocalBackup(name=archive.name, date=archive.stat().st_ctime)
|
||||||
|
imports.append(backup)
|
||||||
|
|
||||||
for template in TEMPLATE_DIR.glob("*.md"):
|
for template in TEMPLATE_DIR.glob("*.md"):
|
||||||
templates.append(template.name)
|
templates.append(template.name)
|
||||||
|
|
||||||
|
imports.sort(key=operator.attrgetter("date"), reverse=True)
|
||||||
|
|
||||||
return Imports(imports=imports, templates=templates)
|
return Imports(imports=imports, templates=templates)
|
||||||
|
|
||||||
|
|
||||||
@router.post("/api/backups/export/database/", tags=["Import / Export"], status_code=201)
|
@router.post("/api/backups/export/database/", status_code=201)
|
||||||
def export_database(data: BackupJob):
|
def export_database(data: BackupJob):
|
||||||
"""Generates a backup of the recipe database in json format."""
|
"""Generates a backup of the recipe database in json format."""
|
||||||
export_path = backup_all(data.tag, data.template)
|
export_path = backup_all(data.tag, data.template)
|
||||||
|
@ -35,17 +40,17 @@ def export_database(data: BackupJob):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@router.post(
|
@router.post("/api/backups/{file_name}/import/", status_code=200)
|
||||||
"/api/backups/{file_name}/import/", tags=["Import / Export"], status_code=200
|
def import_database(file_name: str, import_data: ImportJob):
|
||||||
)
|
|
||||||
def import_database(file_name: str):
|
|
||||||
""" Import a database backup file generated from Mealie. """
|
""" Import a database backup file generated from Mealie. """
|
||||||
|
|
||||||
import_db = ImportDatabase(
|
import_db = ImportDatabase(
|
||||||
zip_archive=file_name,
|
zip_archive=import_data.name,
|
||||||
import_recipes=True,
|
import_recipes=import_data.recipes,
|
||||||
import_settings=False,
|
force_import=import_data.force,
|
||||||
import_themes=False,
|
rebase=import_data.rebase,
|
||||||
|
import_settings=import_data.settings,
|
||||||
|
import_themes=import_data.themes,
|
||||||
)
|
)
|
||||||
|
|
||||||
imported = import_db.run()
|
imported = import_db.run()
|
||||||
|
|
|
@ -1,21 +1,20 @@
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from fastapi import APIRouter, HTTPException
|
from fastapi import APIRouter, HTTPException
|
||||||
from models.recipe_models import SlugResponse
|
|
||||||
from services.meal_services import MealPlan
|
from services.meal_services import MealPlan
|
||||||
from utils.snackbar import SnackResponse
|
from utils.snackbar import SnackResponse
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter(tags=["Meal Plan"])
|
||||||
|
|
||||||
|
|
||||||
@router.get("/api/meal-plan/all/", tags=["Meal Plan"], response_model=List[MealPlan])
|
@router.get("/api/meal-plan/all/", response_model=List[MealPlan])
|
||||||
def get_all_meals():
|
def get_all_meals():
|
||||||
""" Returns a list of all available Meal Plan """
|
""" Returns a list of all available Meal Plan """
|
||||||
|
|
||||||
return MealPlan.get_all()
|
return MealPlan.get_all()
|
||||||
|
|
||||||
|
|
||||||
@router.post("/api/meal-plan/create/", tags=["Meal Plan"])
|
@router.post("/api/meal-plan/create/")
|
||||||
def set_meal_plan(data: MealPlan):
|
def set_meal_plan(data: MealPlan):
|
||||||
""" Creates a meal plan database entry """
|
""" Creates a meal plan database entry """
|
||||||
data.process_meals()
|
data.process_meals()
|
||||||
|
@ -29,7 +28,7 @@ def set_meal_plan(data: MealPlan):
|
||||||
return SnackResponse.success("Mealplan Created")
|
return SnackResponse.success("Mealplan Created")
|
||||||
|
|
||||||
|
|
||||||
@router.post("/api/meal-plan/{plan_id}/update/", tags=["Meal Plan"])
|
@router.post("/api/meal-plan/{plan_id}/update/")
|
||||||
def update_meal_plan(plan_id: str, meal_plan: MealPlan):
|
def update_meal_plan(plan_id: str, meal_plan: MealPlan):
|
||||||
""" Updates a meal plan based off ID """
|
""" Updates a meal plan based off ID """
|
||||||
meal_plan.process_meals()
|
meal_plan.process_meals()
|
||||||
|
@ -46,7 +45,7 @@ def update_meal_plan(plan_id: str, meal_plan: MealPlan):
|
||||||
return SnackResponse.success("Mealplan Updated")
|
return SnackResponse.success("Mealplan Updated")
|
||||||
|
|
||||||
|
|
||||||
@router.delete("/api/meal-plan/{plan_id}/delete/", tags=["Meal Plan"])
|
@router.delete("/api/meal-plan/{plan_id}/delete/")
|
||||||
def delete_meal_plan(plan_id):
|
def delete_meal_plan(plan_id):
|
||||||
""" Removes a meal plan from the database """
|
""" Removes a meal plan from the database """
|
||||||
|
|
||||||
|
@ -68,7 +67,7 @@ def get_today():
|
||||||
return MealPlan.today()
|
return MealPlan.today()
|
||||||
|
|
||||||
|
|
||||||
@router.get("/api/meal-plan/this-week/", tags=["Meal Plan"], response_model=MealPlan)
|
@router.get("/api/meal-plan/this-week/", response_model=MealPlan)
|
||||||
def get_this_week():
|
def get_this_week():
|
||||||
""" Returns the meal plan data for this week """
|
""" Returns the meal plan data for this week """
|
||||||
|
|
||||||
|
|
|
@ -4,14 +4,14 @@ from fastapi import APIRouter, File, HTTPException, UploadFile
|
||||||
from models.migration_models import ChowdownURL
|
from models.migration_models import ChowdownURL
|
||||||
from services.migrations.chowdown import chowdown_migrate as chowdow_migrate
|
from services.migrations.chowdown import chowdown_migrate as chowdow_migrate
|
||||||
from services.migrations.nextcloud import migrate as nextcloud_migrate
|
from services.migrations.nextcloud import migrate as nextcloud_migrate
|
||||||
from settings import MIGRATION_DIR
|
from app_config import MIGRATION_DIR
|
||||||
from utils.snackbar import SnackResponse
|
from utils.snackbar import SnackResponse
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter(tags=["Migration"])
|
||||||
|
|
||||||
|
|
||||||
# Chowdown
|
# Chowdown
|
||||||
@router.post("/api/migration/chowdown/repo/", tags=["Migration"])
|
@router.post("/api/migration/chowdown/repo/")
|
||||||
def import_chowdown_recipes(repo: ChowdownURL):
|
def import_chowdown_recipes(repo: ChowdownURL):
|
||||||
""" Import Chowsdown Recipes from Repo URL """
|
""" Import Chowsdown Recipes from Repo URL """
|
||||||
try:
|
try:
|
||||||
|
@ -30,7 +30,7 @@ def import_chowdown_recipes(repo: ChowdownURL):
|
||||||
|
|
||||||
|
|
||||||
# Nextcloud
|
# Nextcloud
|
||||||
@router.get("/api/migration/nextcloud/available/", tags=["Migration"])
|
@router.get("/api/migration/nextcloud/available/")
|
||||||
def get_avaiable_nextcloud_imports():
|
def get_avaiable_nextcloud_imports():
|
||||||
""" Returns a list of avaiable directories that can be imported into Mealie """
|
""" Returns a list of avaiable directories that can be imported into Mealie """
|
||||||
available = []
|
available = []
|
||||||
|
@ -43,14 +43,14 @@ def get_avaiable_nextcloud_imports():
|
||||||
return available
|
return available
|
||||||
|
|
||||||
|
|
||||||
@router.post("/api/migration/nextcloud/{selection}/import/", tags=["Migration"])
|
@router.post("/api/migration/nextcloud/{selection}/import/")
|
||||||
def import_nextcloud_directory(selection: str):
|
def import_nextcloud_directory(selection: str):
|
||||||
""" Imports all the recipes in a given directory """
|
""" Imports all the recipes in a given directory """
|
||||||
|
|
||||||
return nextcloud_migrate(selection)
|
return nextcloud_migrate(selection)
|
||||||
|
|
||||||
|
|
||||||
@router.delete("/api/migration/{file_folder_name}/delete/", tags=["Migration"])
|
@router.delete("/api/migration/{file_folder_name}/delete/")
|
||||||
def delete_migration_data(file_folder_name: str):
|
def delete_migration_data(file_folder_name: str):
|
||||||
""" Removes migration data from the file system """
|
""" Removes migration data from the file system """
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ def delete_migration_data(file_folder_name: str):
|
||||||
return SnackResponse.info(f"Migration Data Remove: {remove_path.absolute()}")
|
return SnackResponse.info(f"Migration Data Remove: {remove_path.absolute()}")
|
||||||
|
|
||||||
|
|
||||||
@router.post("/api/migration/upload/", tags=["Migration"])
|
@router.post("/api/migration/upload/")
|
||||||
def upload_nextcloud_zipfile(archive: UploadFile = File(...)):
|
def upload_nextcloud_zipfile(archive: UploadFile = File(...)):
|
||||||
""" Upload a .zip File to later be imported into Mealie """
|
""" Upload a .zip File to later be imported into Mealie """
|
||||||
dest = MIGRATION_DIR.joinpath(archive.filename)
|
dest = MIGRATION_DIR.joinpath(archive.filename)
|
||||||
|
|
|
@ -8,10 +8,10 @@ from services.recipe_services import Recipe, read_requested_values
|
||||||
from services.scrape_services import create_from_url
|
from services.scrape_services import create_from_url
|
||||||
from utils.snackbar import SnackResponse
|
from utils.snackbar import SnackResponse
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter(tags=["Recipes"])
|
||||||
|
|
||||||
|
|
||||||
@router.get("/api/all-recipes/", tags=["Recipes"], response_model=List[dict])
|
@router.get("/api/all-recipes/", response_model=List[dict])
|
||||||
def get_all_recipes(keys: Optional[List[str]] = Query(...), num: Optional[int] = 100):
|
def get_all_recipes(keys: Optional[List[str]] = Query(...), num: Optional[int] = 100):
|
||||||
"""
|
"""
|
||||||
Returns key data for all recipes based off the query paramters provided.
|
Returns key data for all recipes based off the query paramters provided.
|
||||||
|
@ -28,7 +28,7 @@ def get_all_recipes(keys: Optional[List[str]] = Query(...), num: Optional[int] =
|
||||||
return all_recipes
|
return all_recipes
|
||||||
|
|
||||||
|
|
||||||
@router.post("/api/all-recipes/", tags=["Recipes"], response_model=List[dict])
|
@router.post("/api/all-recipes/", response_model=List[dict])
|
||||||
def get_all_recipes_post(body: AllRecipeRequest):
|
def get_all_recipes_post(body: AllRecipeRequest):
|
||||||
"""
|
"""
|
||||||
Returns key data for all recipes based off the body data provided.
|
Returns key data for all recipes based off the body data provided.
|
||||||
|
@ -44,7 +44,7 @@ def get_all_recipes_post(body: AllRecipeRequest):
|
||||||
return all_recipes
|
return all_recipes
|
||||||
|
|
||||||
|
|
||||||
@router.get("/api/recipe/{recipe_slug}/", tags=["Recipes"], response_model=Recipe)
|
@router.get("/api/recipe/{recipe_slug}/", response_model=Recipe)
|
||||||
def get_recipe(recipe_slug: str):
|
def get_recipe(recipe_slug: str):
|
||||||
""" Takes in a recipe slug, returns all data for a recipe """
|
""" Takes in a recipe slug, returns all data for a recipe """
|
||||||
recipe = Recipe.get_by_slug(recipe_slug)
|
recipe = Recipe.get_by_slug(recipe_slug)
|
||||||
|
@ -52,7 +52,7 @@ def get_recipe(recipe_slug: str):
|
||||||
return recipe
|
return recipe
|
||||||
|
|
||||||
|
|
||||||
@router.get("/api/recipe/image/{recipe_slug}/", tags=["Recipes"])
|
@router.get("/api/recipe/image/{recipe_slug}/")
|
||||||
def get_recipe_img(recipe_slug: str):
|
def get_recipe_img(recipe_slug: str):
|
||||||
""" Takes in a recipe slug, returns the static image """
|
""" Takes in a recipe slug, returns the static image """
|
||||||
recipe_image = read_image(recipe_slug)
|
recipe_image = read_image(recipe_slug)
|
||||||
|
@ -75,7 +75,7 @@ def parse_recipe_url(url: RecipeURLIn):
|
||||||
return slug
|
return slug
|
||||||
|
|
||||||
|
|
||||||
@router.post("/api/recipe/create/", tags=["Recipes"])
|
@router.post("/api/recipe/create/")
|
||||||
def create_from_json(data: Recipe) -> str:
|
def create_from_json(data: Recipe) -> str:
|
||||||
""" Takes in a JSON string and loads data into the database as a new entry"""
|
""" Takes in a JSON string and loads data into the database as a new entry"""
|
||||||
created_recipe = data.save_to_db()
|
created_recipe = data.save_to_db()
|
||||||
|
@ -83,7 +83,7 @@ def create_from_json(data: Recipe) -> str:
|
||||||
return created_recipe
|
return created_recipe
|
||||||
|
|
||||||
|
|
||||||
@router.post("/api/recipe/{recipe_slug}/update/image/", tags=["Recipes"])
|
@router.post("/api/recipe/{recipe_slug}/update/image/")
|
||||||
def update_recipe_image(
|
def update_recipe_image(
|
||||||
recipe_slug: str, image: bytes = File(...), extension: str = Form(...)
|
recipe_slug: str, image: bytes = File(...), extension: str = Form(...)
|
||||||
):
|
):
|
||||||
|
@ -94,7 +94,7 @@ def update_recipe_image(
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
@router.post("/api/recipe/{recipe_slug}/update/", tags=["Recipes"])
|
@router.post("/api/recipe/{recipe_slug}/update/")
|
||||||
def update_recipe(recipe_slug: str, data: Recipe):
|
def update_recipe(recipe_slug: str, data: Recipe):
|
||||||
""" Updates a recipe by existing slug and data. """
|
""" Updates a recipe by existing slug and data. """
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ def update_recipe(recipe_slug: str, data: Recipe):
|
||||||
return new_slug
|
return new_slug
|
||||||
|
|
||||||
|
|
||||||
@router.delete("/api/recipe/{recipe_slug}/delete/", tags=["Recipes"])
|
@router.delete("/api/recipe/{recipe_slug}/delete/")
|
||||||
def delete_recipe(recipe_slug: str):
|
def delete_recipe(recipe_slug: str):
|
||||||
""" Deletes a recipe by slug """
|
""" Deletes a recipe by slug """
|
||||||
|
|
||||||
|
|
|
@ -4,24 +4,24 @@ from services.settings_services import SiteSettings, SiteTheme
|
||||||
from utils.global_scheduler import scheduler
|
from utils.global_scheduler import scheduler
|
||||||
from utils.snackbar import SnackResponse
|
from utils.snackbar import SnackResponse
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter(tags=["Settings"])
|
||||||
|
|
||||||
|
|
||||||
@router.get("/api/site-settings/", tags=["Settings"])
|
@router.get("/api/site-settings/")
|
||||||
def get_main_settings():
|
def get_main_settings():
|
||||||
""" Returns basic site settings """
|
""" Returns basic site settings """
|
||||||
|
|
||||||
return SiteSettings.get_site_settings()
|
return SiteSettings.get_site_settings()
|
||||||
|
|
||||||
|
|
||||||
@router.post("/api/site-settings/webhooks/test/", tags=["Settings"])
|
@router.post("/api/site-settings/webhooks/test/")
|
||||||
def test_webhooks():
|
def test_webhooks():
|
||||||
""" Run the function to test your webhooks """
|
""" Run the function to test your webhooks """
|
||||||
|
|
||||||
return post_webhooks()
|
return post_webhooks()
|
||||||
|
|
||||||
|
|
||||||
@router.post("/api/site-settings/update/", tags=["Settings"])
|
@router.post("/api/site-settings/update/")
|
||||||
def update_settings(data: SiteSettings):
|
def update_settings(data: SiteSettings):
|
||||||
""" Returns Site Settings """
|
""" Returns Site Settings """
|
||||||
data.update()
|
data.update()
|
||||||
|
|
|
@ -6,19 +6,19 @@ from fastapi.responses import FileResponse
|
||||||
CWD = Path(__file__).parent
|
CWD = Path(__file__).parent
|
||||||
WEB_PATH = CWD.parent.joinpath("dist")
|
WEB_PATH = CWD.parent.joinpath("dist")
|
||||||
BASE_HTML = WEB_PATH.joinpath("index.html")
|
BASE_HTML = WEB_PATH.joinpath("index.html")
|
||||||
router = APIRouter()
|
router = APIRouter(include_in_schema=False)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/favicon.ico", include_in_schema=False)
|
@router.get("/favicon.ico")
|
||||||
def facivon():
|
def facivon():
|
||||||
return responses.RedirectResponse(url="/mealie/favicon.ico")
|
return responses.RedirectResponse(url="/mealie/favicon.ico")
|
||||||
|
|
||||||
|
|
||||||
@router.get("/", include_in_schema=False)
|
@router.get("/")
|
||||||
def root():
|
def root():
|
||||||
return FileResponse(BASE_HTML)
|
return FileResponse(BASE_HTML)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/{full_path:path}", include_in_schema=False)
|
@router.get("/{full_path:path}")
|
||||||
def root_plus(full_path):
|
def root_plus(full_path):
|
||||||
return FileResponse(BASE_HTML)
|
return FileResponse(BASE_HTML)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue