mirror of
https://github.com/zc-zhangchen/any-auto-register.git
synced 2026-05-18 11:26:45 +08:00
79 lines
2.4 KiB
Python
79 lines
2.4 KiB
Python
"""account_manager - 多平台账号管理后台"""
|
|
import os
|
|
from contextlib import asynccontextmanager
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from fastapi.staticfiles import StaticFiles
|
|
from fastapi.responses import FileResponse
|
|
from core.db import init_db
|
|
from core.registry import load_all
|
|
from api.accounts import router as accounts_router
|
|
from api.tasks import router as tasks_router
|
|
from api.platforms import router as platforms_router
|
|
from api.proxies import router as proxies_router
|
|
from api.config import router as config_router
|
|
from api.actions import router as actions_router
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
init_db()
|
|
load_all()
|
|
print("[OK] 数据库初始化完成")
|
|
from core.registry import list_platforms
|
|
print(f"[OK] 已加载平台: {[p['name'] for p in list_platforms()]}")
|
|
from core.scheduler import scheduler
|
|
scheduler.start()
|
|
from services.solver_manager import start_async
|
|
start_async()
|
|
yield
|
|
from core.scheduler import scheduler as _scheduler
|
|
_scheduler.stop()
|
|
from services.solver_manager import stop
|
|
stop()
|
|
|
|
|
|
app = FastAPI(title="Account Manager", version="1.0.0", lifespan=lifespan)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
app.include_router(accounts_router, prefix="/api")
|
|
app.include_router(tasks_router, prefix="/api")
|
|
app.include_router(platforms_router, prefix="/api")
|
|
app.include_router(proxies_router, prefix="/api")
|
|
app.include_router(config_router, prefix="/api")
|
|
app.include_router(actions_router, prefix="/api")
|
|
|
|
|
|
@app.get("/api/solver/status")
|
|
def solver_status():
|
|
from services.solver_manager import is_running
|
|
return {"running": is_running()}
|
|
|
|
|
|
@app.post("/api/solver/restart")
|
|
def solver_restart():
|
|
from services.solver_manager import stop, start_async
|
|
stop()
|
|
start_async()
|
|
return {"message": "重启中"}
|
|
|
|
|
|
_static_dir = os.path.join(os.path.dirname(__file__), "static")
|
|
if os.path.isdir(_static_dir):
|
|
app.mount("/assets", StaticFiles(directory=os.path.join(_static_dir, "assets")), name="assets")
|
|
|
|
@app.get("/{full_path:path}", include_in_schema=False)
|
|
def spa_fallback(full_path: str):
|
|
return FileResponse(os.path.join(_static_dir, "index.html"))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)
|