Update main.py
Browse files
main.py
CHANGED
|
@@ -468,22 +468,22 @@ async def control_panel(data: PanelActionRequest, x_api_key: str = Header(None))
|
|
| 468 |
raise HTTPException(status_code=500, detail=res["error"])
|
| 469 |
return res
|
| 470 |
|
| 471 |
-
PANEL_USER = os.getenv("PANEL_USER")
|
| 472 |
-
PANEL_PASS = os.getenv("PANEL_PASS")
|
| 473 |
-
SERVER_UUID = "45feca4d-3f79-4bcc-ae11-114335a1c77e"
|
| 474 |
-
|
| 475 |
@app.get("/api/v1/panel/refresh")
|
| 476 |
-
async def refresh_panel_token(x_api_key: str = Header(None)):
|
| 477 |
-
|
|
|
|
|
|
|
|
|
|
| 478 |
|
| 479 |
-
login_svc = PanelLogin(PANEL_USER, PANEL_PASS,
|
| 480 |
result = await login_svc.fetch_ws_credentials()
|
| 481 |
|
| 482 |
-
if result["ok"]:
|
| 483 |
-
|
| 484 |
-
return {"ok":
|
| 485 |
-
|
| 486 |
-
|
|
|
|
| 487 |
|
| 488 |
@app.get("/api/v1/panel/debug-img")
|
| 489 |
async def get_debug_img():
|
|
|
|
| 468 |
raise HTTPException(status_code=500, detail=res["error"])
|
| 469 |
return res
|
| 470 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 471 |
@app.get("/api/v1/panel/refresh")
|
| 472 |
+
async def refresh_panel_token(apikey: str = Query(None), x_api_key: str = Header(None, alias="X-API-Key")):
|
| 473 |
+
# Kiểm tra API Key (Sửa lại logic so sánh cho chắc chắn)
|
| 474 |
+
key = x_api_key or apikey
|
| 475 |
+
if not API_KEY or key != API_KEY:
|
| 476 |
+
raise HTTPException(status_code=403, detail="API key invalid. Check your params.")
|
| 477 |
|
| 478 |
+
login_svc = PanelLogin(PANEL_USER, PANEL_PASS, "45feca4d-3f79-4bcc-ae11-114335a1c77e")
|
| 479 |
result = await login_svc.fetch_ws_credentials()
|
| 480 |
|
| 481 |
+
if not result["ok"]:
|
| 482 |
+
# Trả về lỗi chi tiết từ Playwright để debug
|
| 483 |
+
return {"ok": False, "error": result["error"], "debug_img": "/api/v1/panel/debug-img"}
|
| 484 |
+
|
| 485 |
+
panel_app.update_token(result["token"])
|
| 486 |
+
return {"ok": True, "token_preview": result["token"][:20] + "..."}
|
| 487 |
|
| 488 |
@app.get("/api/v1/panel/debug-img")
|
| 489 |
async def get_debug_img():
|