55 lines
2.2 KiB
Python
55 lines
2.2 KiB
Python
import os
|
|
from fastapi import FastAPI
|
|
from fastapi.responses import HTMLResponse
|
|
from fastapi.staticfiles import StaticFiles
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from app.config import settings
|
|
from app.api.v1.audio import router as audio_router
|
|
from app.api.v1.tasks import router as tasks_router
|
|
from app.api.v1.multitrack import router as multitrack_router
|
|
from app.api.v1.auth import router as auth_router
|
|
from app.api.v1.admin import router as admin_router
|
|
from app.api.v1.projects import router as projects_router
|
|
from app.core.auth import seed_admin
|
|
|
|
# Ensure storage directories exist
|
|
os.makedirs(settings.UPLOADS_DIR, exist_ok=True)
|
|
os.makedirs(settings.PROCESSED_DIR, exist_ok=True)
|
|
|
|
app = FastAPI(title="SonicForge API Engine")
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# Mount storage directory (must come before general /static mount)
|
|
app.mount("/static/audio", StaticFiles(directory=settings.STORAGE_DIR), name="audio")
|
|
# Mount app static files (js, css)
|
|
STATIC_DIR = os.path.join(os.path.dirname(__file__), "static")
|
|
app.mount("/static", StaticFiles(directory=STATIC_DIR), name="static")
|
|
|
|
# Include routers
|
|
app.include_router(audio_router, prefix="/api/v1/audio", tags=["audio"])
|
|
app.include_router(tasks_router, prefix="/api/v1/audio", tags=["tasks"])
|
|
app.include_router(multitrack_router, prefix="/api/v1/multitrack", tags=["multitrack"])
|
|
app.include_router(auth_router, prefix="/api/v1/auth", tags=["auth"])
|
|
app.include_router(admin_router, prefix="/api/v1/admin", tags=["admin"])
|
|
app.include_router(projects_router, prefix="/api/v1/projects", tags=["projects"])
|
|
|
|
# Seed admin user on startup
|
|
@app.on_event("startup")
|
|
async def startup_seed_admin():
|
|
seed_admin()
|
|
|
|
@app.get("/", response_class=HTMLResponse)
|
|
async def get_index():
|
|
index_path = os.path.join(settings.TEMPLATES_DIR, "index.html")
|
|
if not os.path.exists(index_path):
|
|
return HTMLResponse(content=f"<h1>SonicForge Studio: index.html not found at {index_path}</h1>", status_code=404)
|
|
with open(index_path, "r", encoding="utf-8") as file:
|
|
return HTMLResponse(content=file.read(), status_code=200)
|