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 typing import List
from models.schemas import ContactCreate, NewsletterSubscribe from models.schemas import ContactCreate, NewsletterSubscribe
from datetime import datetime from datetime import datetime
from pathlib import Path
import uuid import uuid
import os import os
import shutil import shutil
@@ -12,6 +13,10 @@ router = APIRouter(prefix="/api", tags=["Other"])
# MongoDB connection will be injected # MongoDB connection will be injected
db = None db = None
# Upload directory setup
UPLOAD_DIR = Path(__file__).parent.parent / 'uploads'
UPLOAD_DIR.mkdir(exist_ok=True)
def set_db(database): def set_db(database):
global db global db
db = database db = database
@@ -55,7 +60,7 @@ async def upload_image(file: UploadFile = File(...)):
# Generate unique filename # Generate unique filename
unique_filename = f"{uuid.uuid4()}{file_ext}" unique_filename = f"{uuid.uuid4()}{file_ext}"
file_path = f"/app/backend/uploads/{unique_filename}" file_path = UPLOAD_DIR / unique_filename
# Save file # Save file
with open(file_path, "wb") as buffer: with open(file_path, "wb") as buffer:
@@ -69,9 +74,9 @@ async def upload_image(file: UploadFile = File(...)):
@router.get("/uploads/{filename}") @router.get("/uploads/{filename}")
async def get_uploaded_image(filename: str): async def get_uploaded_image(filename: str):
"""Serve uploaded images""" """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") raise HTTPException(status_code=404, detail="Image not found")
return FileResponse(file_path) return FileResponse(str(file_path))