mirror of
https://github.com/myronblair/epic-download
synced 2026-06-30 17:51:00 -05:00
auto-commit for f98ebdaa-fbba-4c66-9771-4cbcbad2b530
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user