Spaces:
Sleeping
Sleeping
| import uuid, os | |
| from pathlib import Path | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| GENERATED_DIR = Path(os.getenv("GENERATED_PATH", "media")) | |
| HOST_URL = os.getenv("HOST_URL", "http://localhost:8000") | |
| def save_card_image(image_bytes: bytes, extension="png") -> Path: | |
| filename = f"{uuid.uuid4()}.{extension}" | |
| filepath = GENERATED_DIR / filename | |
| filepath.parent.mkdir(parents=True, exist_ok=True) | |
| with open(filepath, "wb") as f: | |
| f.write(image_bytes) | |
| return filepath | |
| def get_card_url(filename: str, base_url: str = "https://yourdomain.com/media") -> str: | |
| return f"{base_url}/{filename}" | |