from flask import current_app
from pathlib import Path

images_extensions = ["png", "jpg", "jpeg", "svg"]


def clean_uploaded_avtar(model, id):
    uploads_path = Path(current_app.root_path).joinpath(
        "uploads", "avatars", model)

    for ext in images_extensions:
        uploads_path = uploads_path.joinpath(f"{id}.{ext}")
        print(str(uploads_path))
        if uploads_path.is_file():
            uploads_path.unlink()


def root_path():
    return Path(__file__).parent.parent.parent


def file_get_content(file: Path):
    if not file.exists():
        return ""

    with open(str(file), "r") as f:
        return f.read()
