fix: Add file upload endpoint and fix frontend upload path
This commit is contained in:
@@ -15,10 +15,13 @@ Provides endpoints for:
|
|||||||
- Quality gate evaluation
|
- 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 pydantic import BaseModel, Field
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
router = APIRouter(prefix="/quality", tags=["Quality"])
|
router = APIRouter(prefix="/quality", tags=["Quality"])
|
||||||
|
|
||||||
@@ -255,6 +258,47 @@ async def analyze_character_image(
|
|||||||
prompt_description=result.to_prompt_description()
|
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
|
# Content Filter Endpoints
|
||||||
# ============================================================
|
# ============================================================
|
||||||
|
|||||||
@@ -70,11 +70,12 @@ export function CharacterPanel({ storyboardId }: CharacterPanelProps) {
|
|||||||
if (!file) return
|
if (!file) return
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Upload to server
|
// Upload to server - use quality API endpoint
|
||||||
const formData = new FormData()
|
const formData = new FormData()
|
||||||
formData.append('file', file)
|
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',
|
method: 'POST',
|
||||||
body: formData,
|
body: formData,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user