diff --git a/api/routers/quality.py b/api/routers/quality.py index 0e84c42..b144128 100644 --- a/api/routers/quality.py +++ b/api/routers/quality.py @@ -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 # ============================================================ diff --git a/frontend/src/components/quality/character-panel.tsx b/frontend/src/components/quality/character-panel.tsx index c285cab..9aef4f2 100644 --- a/frontend/src/components/quality/character-panel.tsx +++ b/frontend/src/components/quality/character-panel.tsx @@ -70,11 +70,12 @@ export function CharacterPanel({ storyboardId }: CharacterPanelProps) { if (!file) return try { - // Upload to server + // Upload to server - use quality API endpoint const formData = new FormData() formData.append('file', file) - const response = await fetch(`/api/upload?storyboard_id=${storyboardId}&type=character`, { + const apiBase = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000/api' + const response = await fetch(`${apiBase}/quality/upload?storyboard_id=${storyboardId}&type=character`, { method: 'POST', body: formData, })