File size: 3,070 Bytes
133609a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8d7d15e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# uvicorn app:app --host 0.0.0.0 --port 7860 --reload

import os
import sys # Import sys
from fastapi import FastAPI
from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles

# Optional: Import python-multipart to ensure it's loaded
try:
    import python_multipart
except ImportError:
    print("Warning: python-multipart is not installed. File uploads may fail.")

from routes import auth, api_keys, proxies, admin # Import admin router

# Environment check: Ensure we are running in the correct Conda environment
# This helps catch issues where uvicorn might be using a different python interpreter
conda_prefix = os.environ.get("CONDA_PREFIX")
if conda_prefix:
    expected_python_path = os.path.join(conda_prefix, "bin", "python")
    if sys.executable != expected_python_path:
        print(f"Warning: Python interpreter is not from the expected Conda environment 'airs'.")
        print(f"Expected: {expected_python_path}")
        print(f"Actual: {sys.executable}")
        # Optionally, you could raise an exception here to prevent startup in wrong environment
        # raise RuntimeError("Incorrect Python environment detected. Please activate 'airs' conda environment.")
else:
    print("Warning: CONDA_PREFIX environment variable not set. Cannot verify Conda environment.")

# Initialize FastAPI app
app = FastAPI()

# Mount static files
app.mount("/static", StaticFiles(directory="static"), name="static")

# Include routers
app.include_router(auth.router, prefix="/api/auth", tags=["auth"])
app.include_router(api_keys.router, prefix="/api/user", tags=["api_keys"])
app.include_router(proxies.router, prefix="/api/proxies", tags=["proxies"])
app.include_router(admin.router, prefix="/api/admin", tags=["admin"]) # Include admin router

# Root and HTML routes
@app.get("/", response_class=HTMLResponse)
async def read_root():
    with open("static/index.html", "r") as f:
        return f.read()

@app.get("/login", response_class=HTMLResponse)
async def read_login():
    with open("static/login.html", "r") as f:
        return f.read()

@app.get("/reset-password", response_class=HTMLResponse)
async def read_reset_password():
    with open("static/reset-password.html", "r") as f:
        return f.read()

@app.get("/signup", response_class=HTMLResponse)
async def read_signup():
    with open("static/signup.html", "r") as f:
        return f.read()

@app.get("/admin", response_class=HTMLResponse)
async def read_admin():
    with open("static/admin.html", "r") as f:
        return f.read()

@app.get("/admin/users", response_class=HTMLResponse)
async def read_admin_users():
    with open("static/admin/users.html", "r") as f:
        return f.read()

@app.get("/static/components/admin_navbar.html", response_class=HTMLResponse)
async def get_admin_navbar():
    with open("static/components/admin_navbar.html", "r") as f:
        return f.read()

@app.get("/admin/pictures", response_class=HTMLResponse)
async def read_admin_pictures():
    with open("static/admin/pictures.html", "r") as f:
        return f.read()