auto-commit for f98ebdaa-fbba-4c66-9771-4cbcbad2b530

This commit is contained in:
emergent-agent-e1
2026-03-31 17:06:08 +00:00
parent 6488998a87
commit 6f31e2d1bf
+9 -4
View File
@@ -3,6 +3,7 @@ from fastapi.responses import FileResponse
from typing import List
from models.schemas import ContactCreate, NewsletterSubscribe
from datetime import datetime
from pathlib import Path
import uuid
import os
import shutil
@@ -12,6 +13,10 @@ router = APIRouter(prefix="/api", tags=["Other"])
# MongoDB connection will be injected
db = None
# Upload directory setup
UPLOAD_DIR = Path(__file__).parent.parent / 'uploads'
UPLOAD_DIR.mkdir(exist_ok=True)
def set_db(database):
global db
db = database
@@ -55,7 +60,7 @@ async def upload_image(file: UploadFile = File(...)):
# Generate unique filename
unique_filename = f"{uuid.uuid4()}{file_ext}"
file_path = f"/app/backend/uploads/{unique_filename}"
file_path = UPLOAD_DIR / unique_filename
# Save file
with open(file_path, "wb") as buffer:
@@ -69,9 +74,9 @@ async def upload_image(file: UploadFile = File(...)):
@router.get("/uploads/{filename}")
async def get_uploaded_image(filename: str):
"""Serve uploaded images"""
file_path = f"/app/backend/uploads/{filename}"
file_path = UPLOAD_DIR / filename
if not os.path.exists(file_path):
if not file_path.exists():
raise HTTPException(status_code=404, detail="Image not found")
return FileResponse(file_path)
return FileResponse(str(file_path))