fix: Remove hardcoded ports, support custom port configuration

- Replace all hardcoded localhost:8000/3000/8501 with environment variables
- Frontend: Use API_PORT env var in next.config.ts
- Backend: Use API_PORT env var in editor.py and quality.py
- Web UI: Use API_PORT and EDITOR_PORT env vars in all Streamlit pages
- Update dev.sh to pass environment variables to all services
- Add .env.example with port configuration template

Now supports custom ports via environment variables:
  API_PORT=8080 EDITOR_PORT=3001 WEB_PORT=8502 ./dev.sh

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
empty
2026-01-10 16:13:02 +08:00
parent 6bf16936af
commit 3f59b324ad
8 changed files with 61 additions and 18 deletions

View File

@@ -47,24 +47,31 @@ from api.schemas.editor import (
from fastapi import BackgroundTasks
import asyncio
import uuid as uuid_module
import os
router = APIRouter(prefix="/editor", tags=["Editor"])
# Export task storage
_export_tasks: dict = {}
# Get API port from environment
API_PORT = os.getenv("API_PORT", "8000")
def _path_to_url(file_path: str, base_url: str = "http://localhost:8000") -> str:
def _path_to_url(file_path: str, base_url: str = None) -> str:
"""Convert local file path to URL accessible through API"""
if not file_path:
return None
if base_url is None:
base_url = f"http://localhost:{API_PORT}"
import os
from pathlib import Path
# Normalize path separators
file_path = file_path.replace("\\", "/")
# Extract relative path from output directory
parts = file_path.split("/")
try:
@@ -73,7 +80,7 @@ def _path_to_url(file_path: str, base_url: str = "http://localhost:8000") -> str
relative_path = "/".join(relative_parts)
except ValueError:
relative_path = Path(file_path).name
return f"{base_url}/api/files/{relative_path}"
@@ -951,8 +958,9 @@ async def export_video(
for frame in sorted_frames:
path = frame.get("video_segment_path", "")
if path.startswith("http"):
# Extract path from URL
path = path.replace("http://localhost:8000/api/files/", "output/")
# Extract path from URL (format: http://localhost:{port}/api/files/{relative_path})
if "/api/files/" in path:
path = "output/" + path.split("/api/files/")[-1]
video_segments.append(path)
_export_tasks[task_id]["progress"] = 0.3

View File

@@ -349,8 +349,9 @@ async def extract_style(
# Convert URL to file path if needed
actual_path = image_path
if image_path.startswith("http"):
# Extract path from URL like http://localhost:8000/api/files/...
actual_path = image_path.replace("http://localhost:8000/api/files/", "output/")
# Extract path from URL (format: http://localhost:{port}/api/files/{relative_path})
if "/api/files/" in image_path:
actual_path = "output/" + image_path.split("/api/files/")[-1]
# Check if file exists
import os