fix: Add file upload endpoint and fix frontend upload path

This commit is contained in:
empty
2026-01-07 03:17:58 +08:00
parent 49e667cc94
commit 44249889df
2 changed files with 48 additions and 3 deletions

View File

@@ -15,10 +15,13 @@ Provides endpoints for:
- Quality gate evaluation
"""
from fastapi import APIRouter, HTTPException, Path, Body
from fastapi import APIRouter, HTTPException, Path, Body, File, UploadFile, Query
from pydantic import BaseModel, Field
from typing import List, Optional
from loguru import logger
import os
import shutil
from datetime import datetime
router = APIRouter(prefix="/quality", tags=["Quality"])
@@ -255,6 +258,47 @@ async def analyze_character_image(
prompt_description=result.to_prompt_description()
)
@router.post("/upload")
async def upload_file(
file: UploadFile = File(...),
storyboard_id: str = Query(..., description="Storyboard ID"),
type: str = Query("character", description="File type (character, reference)")
):
"""
Upload a file for character reference or other purposes.
Returns the saved file path that can be used for analysis.
"""
try:
# Create output directory
output_dir = f"output/{storyboard_id}"
os.makedirs(output_dir, exist_ok=True)
# Generate filename with timestamp
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S_%f")
ext = os.path.splitext(file.filename)[1] or ".png"
filename = f"{type}_{timestamp}{ext}"
file_path = os.path.join(output_dir, filename)
# Save file
with open(file_path, "wb") as buffer:
content = await file.read()
buffer.write(content)
logger.info(f"Uploaded file to: {file_path}")
return {
"success": True,
"path": file_path,
"file_path": file_path,
"filename": filename
}
except Exception as e:
logger.error(f"Failed to upload file: {e}")
raise HTTPException(status_code=500, detail=str(e))
# ============================================================
# Content Filter Endpoints
# ============================================================