Commit 76fb2115 authored by Aryan Noshirvani's avatar Aryan Noshirvani

Remove root main.py, an exact dead duplicate of src/api/main.py

Missed in the previous reorg commit - byte-identical to src/api/main.py,
nothing imports it, and the live service runs src.api.main:app.
Co-Authored-By: 's avatarClaude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BCxXmJVvDFJVHTUi4QgNzi
parent a70d39b7
import os
import secrets
from fastapi import FastAPI, Depends, Request, Form, Response
from fastapi.responses import HTMLResponse, RedirectResponse
from fastapi.openapi.docs import get_swagger_ui_html
from fastapi.openapi.utils import get_openapi
from fastapi.security import APIKeyCookie
from fastapi.staticfiles import StaticFiles
from src.api.routers import auth, discovery, library, music, social
os.makedirs("/root/antigrav-stax-audio/downloads", exist_ok=True)
os.makedirs("/root/antigrav-stax-audio/temp", exist_ok=True)
cookie_sec = APIKeyCookie(name="session_token", auto_error=False)
def verify_cookie(session_token: str = Depends(cookie_sec)):
if not session_token or session_token != "valid_token_xyz":
return False
return True
app = FastAPI(docs_url=None, redoc_url=None, openapi_url=None)
app.mount("/downloads", StaticFiles(directory="/root/antigrav-stax-audio/downloads"), name="downloads")
app.include_router(auth.router)
app.include_router(discovery.router)
app.include_router(library.router)
app.include_router(music.router)
app.include_router(social.router)
@app.get("/", response_class=HTMLResponse, include_in_schema=False)
async def login_get(request: Request):
token = request.cookies.get("session_token")
if token == "valid_token_xyz":
return RedirectResponse(url="/docs", status_code=302)
html_content = """
<!DOCTYPE html>
<html>
<head>
<title>Stax API Login</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%); margin: 0; }
.login-box { background: white; padding: 40px; border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,0.1); width: 100%; max-width: 320px; text-align: center; }
h2 { margin-top: 0; color: #333; margin-bottom: 24px; font-weight: 600; }
input { width: 100%; padding: 12px; margin: 8px 0 16px 0; border: 1px solid #ddd; border-radius: 6px; box-sizing: border-box; font-size: 15px; transition: border-color 0.3s; }
input:focus { border-color: #007bff; outline: none; }
button { width: 100%; padding: 12px; background: #007bff; color: white; border: none; border-radius: 6px; cursor: pointer; font-size: 16px; font-weight: 600; transition: background 0.3s; }
button:hover { background: #0056b3; }
.error { color: #dc3545; font-size: 14px; margin-bottom: 10px; }
</style>
</head>
<body>
<div class="login-box">
<h2>Stax API Docs</h2>
<form method="post" action="/login">
<input type="text" name="username" placeholder="Username" required autocomplete="username">
<input type="password" name="password" placeholder="Password" required autocomplete="current-password">
<button type="submit">Login to Docs</button>
</form>
</div>
</body>
</html>
"""
return HTMLResponse(content=html_content)
@app.post("/login", include_in_schema=False)
async def login_post(response: Response, username: str = Form(...), password: str = Form(...)):
correct_username = secrets.compare_digest(username, "admin")
correct_password = secrets.compare_digest(password, "stax123")
if correct_username and correct_password:
res = RedirectResponse(url="/docs", status_code=302)
res.set_cookie(key="session_token", value="valid_token_xyz", httponly=True, max_age=86400)
return res
else:
return HTMLResponse("""
<div style="font-family: sans-serif; text-align: center; padding: 50px;">
<h2 style="color: red;">Invalid Credentials</h2>
<a href="/">Try Again</a>
</div>
""", status_code=401)
@app.get("/docs", include_in_schema=False)
async def get_documentation(request: Request):
token = request.cookies.get("session_token")
if token != "valid_token_xyz":
return RedirectResponse(url="/", status_code=302)
return get_swagger_ui_html(openapi_url="/openapi.json", title="Stax API Docs")
@app.get("/openapi.json", include_in_schema=False)
async def openapi(request: Request):
token = request.cookies.get("session_token")
if token != "valid_token_xyz":
return RedirectResponse(url="/", status_code=302)
if app.openapi_schema:
return app.openapi_schema
openapi_schema = get_openapi(
title="Stax Music API",
version="1.0.0",
description="API backend for the Stax App. Features music tagging and batch remixing.",
routes=app.routes,
)
openapi_schema["components"]["securitySchemes"] = {
"BearerAuth": {
"type": "http",
"scheme": "bearer",
"bearerFormat": "JWT"
}
}
app.openapi_schema = openapi_schema
return app.openapi_schema
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment