Exemplo n.º 1
0
def delete_recipe(recipe_slug: str, db: Session = Depends(generate_session)):
    """ Deletes a recipe by slug """

    try:
        Recipe.delete(db, recipe_slug)
    except:
        raise HTTPException(
            status_code=404,
            detail=SnackResponse.error("Unable to Delete Recipe"))

    return SnackResponse.error(f"Recipe {recipe_slug} Deleted")
Exemplo n.º 2
0
def delete_backup(file_name: str):
    """ Removes a database backup from the file system """

    try:
        BACKUP_DIR.joinpath(file_name).unlink()
    except:
        HTTPException(
            status_code=400,
            detail=SnackResponse.error(
                "Unable to Delete Backup. See Log File"),
        )

    return SnackResponse.error(f"{file_name} Deleted")
Exemplo n.º 3
0
async def delete_migration_data(file_folder_name: str):
    """ Removes migration data from the file system """

    remove_path = MIGRATION_DIR.joinpath(file_folder_name)

    if remove_path.is_file():
        remove_path.unlink()
    elif remove_path.is_dir():
        shutil.rmtree(remove_path)
    else:
        SnackResponse.error("File/Folder not found.")

    return SnackResponse.info(f"Migration Data Remove: {remove_path.absolute()}")
Exemplo n.º 4
0
async def delete_recipe_tag(tag: str, session: Session = Depends(generate_session)):
    """Removes a recipe tag from the database. Deleting a
    tag does not impact a recipe. The tag will be removed
    from any recipes that contain it"""

    db.tags.delete(session, tag)

    return SnackResponse.error(f"Tag Deleted: {tag}")
Exemplo n.º 5
0
def export_database(data: BackupJob):
    """Generates a backup of the recipe database in json format."""
    export_path = backup_all(data.tag, data.template)
    try:
        return SnackResponse.success("Backup Created at " + export_path)
    except:
        HTTPException(
            status_code=400,
            detail=SnackResponse.error("Error Creating Backup. See Log File"),
        )
Exemplo n.º 6
0
async def upload_nextcloud_zipfile(file_name: str):
    """ Upload a .zip File to later be imported into Mealie """
    file = BACKUP_DIR.joinpath(file_name)

    if file.is_file:
        return FileResponse(file,
                            media_type="application/octet-stream",
                            filename=file_name)
    else:
        return SnackResponse.error("No File Found")
Exemplo n.º 7
0
async def update_theme(theme_name: str, data: SiteTheme):
    """ Update a theme database entry """
    try:
        data.update_document()
    except:
        raise HTTPException(
            status_code=400,
            detail=SnackResponse.error("Unable to Update Theme"))

    return SnackResponse.success("Theme Updated")
Exemplo n.º 8
0
async def delete_theme(theme_name: str):
    """ Returns basic site Settings """
    try:
        SiteTheme.delete_theme(theme_name)
    except:
        raise HTTPException(
            status_code=400,
            detail=SnackResponse.error("Unable to Delete Theme"))

    return SnackResponse.success("Theme Deleted")
Exemplo n.º 9
0
async def delete_theme(theme_name: str):
    """ Deletes theme from the database """
    try:
        SiteTheme.delete_theme(theme_name)
    except:
        raise HTTPException(
            status_code=400,
            detail=SnackResponse.error("Unable to Delete Theme"))

    return SnackResponse.success("Theme Deleted")
Exemplo n.º 10
0
async def create_theme(data: SiteTheme):
    """ Creates a site color theme database entry """

    try:
        data.save_to_db()
    except:
        raise HTTPException(status_code=400,
                            detail=SnackResponse.error("Unable to Save Theme"))

    return SnackResponse.success("Theme Saved")
Exemplo n.º 11
0
async def delete_recipe_category(
    category: str, session: Session = Depends(generate_session)
):
    """Removes a recipe category from the database. Deleting a
    category does not impact a recipe. The category will be removed
    from any recipes that contain it"""

    db.categories.delete(session, category)

    return SnackResponse.error(f"Category Deleted: {category}")
Exemplo n.º 12
0
def delete_recipe(recipe_slug: str):
    """ Deletes a recipe by slug """

    try:
        Recipe.delete(recipe_slug)
    except:
        raise HTTPException(
            status_code=404, detail=SnackResponse.error("Unable to Delete Recipe")
        )

    return SnackResponse.success("Recipe Deleted")
Exemplo n.º 13
0
def import_nextcloud_directory(type: str,
                               file_name: str,
                               session: Session = Depends(generate_session)):
    """ Imports all the recipes in a given directory """
    file_path = MIGRATION_DIR.joinpath(type, file_name)
    if type == "nextcloud":
        return nextcloud_migrate(session, file_path)
    elif type == "chowdown":
        return chowdow_migrate(session, file_path)
    else:
        return SnackResponse.error("Incorrect Migration Type Selected")
Exemplo n.º 14
0
def upload_nextcloud_zipfile(archive: UploadFile = File(...)):
    """ Upload a .zip File to later be imported into Mealie """
    dest = MIGRATION_DIR.joinpath(archive.filename)

    with dest.open("wb") as buffer:
        shutil.copyfileobj(archive.file, buffer)

    if dest.is_file:
        return SnackResponse.success("Migration data uploaded")
    else:
        return SnackResponse.error("Failure uploading file")
Exemplo n.º 15
0
async def export_database(data: BackupJob):

    try:
        export_path = export_db(data.tag, data.template)
    except:
        HTTPException(
            status_code=400,
            detail=SnackResponse.error("Error Creating Backup. See Log File"),
        )

    return SnackResponse.success("Backup Created at " + export_path)
Exemplo n.º 16
0
def upload_backup_zipfile(archive: UploadFile = File(...)):
    """ Upload a .zip File to later be imported into Mealie """
    dest = BACKUP_DIR.joinpath(archive.filename)

    with dest.open("wb") as buffer:
        shutil.copyfileobj(archive.file, buffer)

    if dest.is_file:
        return SnackResponse.success("Backup uploaded")
    else:
        return SnackResponse.error("Failure uploading file")
Exemplo n.º 17
0
async def update_settings(data: SiteSettings):
    """ Returns Site Settings """

    try:
        data.update()
    except:
        raise HTTPException(
            status_code=400,
            detail=SnackResponse.error("Unable to Save Settings"))

    scheduler.reschedule_webhooks()
    return SnackResponse.success("Settings Updated")
Exemplo n.º 18
0
async def export_database(data: BackupJob):
    """ Returns this weeks meal plan """

    try:
        export_db(data.tag, data.template)
    except:
        HTTPException(
            status_code=400,
            detail=SnackResponse.error("Error Creating Backup. See Log File"),
        )

    return SnackResponse.success("Backup Created in /data/backups")
Exemplo n.º 19
0
async def delete_backup(backup_name: str):

    try:
        BACKUP_DIR.joinpath(backup_name).unlink()
    except:
        HTTPException(
            status_code=400,
            detail=SnackResponse.error(
                "Unable to Delete Backup. See Log File"),
        )

    return SnackResponse.success(f"{backup_name} Deleted")
Exemplo n.º 20
0
async def get_recipe_url(url: dict):
    """ Takes in a URL and Attempts to scrape data and load it into the database """

    url = url.get("url")

    try:
        slug = create_from_url(url)
    except:
        raise HTTPException(
            status_code=400, detail=SnackResponse.error("Unable to Parse URL")
        )

    return slug
Exemplo n.º 21
0
async def update_meal_plan(plan_id: str, meal_plan: MealPlan):
    """ Updates a meal plan based off ID """

    try:
        meal_plan.process_meals()
        meal_plan.update(plan_id)
    except:
        raise HTTPException(
            status_code=404,
            detail=SnackResponse.error("Unable to Update Mealplan"),
        )

    return SnackResponse.success("Mealplan Updated")
Exemplo n.º 22
0
def import_chowdown_recipes(repo: ChowdownURL):
    """ Import Chowsdown Recipes from Repo URL """
    try:
        report = chowdow_migrate(repo.url)
        return SnackResponse.success(
            "Recipes Imported from Git Repo, see report for failures.",
            additional_data=report,
        )
    except:
        return HTTPException(
            status_code=400,
            detail=SnackResponse.error(
                "Unable to Migrate Recipes. See Log for Details"),
        )
Exemplo n.º 23
0
def export_database(data: BackupJob,
                    session: Session = Depends(generate_session)):
    """Generates a backup of the recipe database in json format."""
    export_path = backup_all(
        session=session,
        tag=data.tag,
        templates=data.templates,
        export_recipes=data.options.recipes,
        export_settings=data.options.settings,
        export_themes=data.options.themes,
    )
    try:
        return SnackResponse.success("Backup Created at " + export_path)
    except:
        HTTPException(
            status_code=400,
            detail=SnackResponse.error("Error Creating Backup. See Log File"),
        )
Exemplo n.º 24
0
def delete_meal_plan(plan_id, session: Session = Depends(generate_session)):
    """ Removes a meal plan from the database """

    MealPlan.delete(session, plan_id)

    return SnackResponse.error("Mealplan Deleted")
Exemplo n.º 25
0
def delete_theme(theme_name: str,
                 session: Session = Depends(generate_session)):
    """ Deletes theme from the database """
    db.themes.delete(session, theme_name)

    return SnackResponse.error(f"Theme Deleted: {theme_name}")