bobocup commited on
Commit
188c240
·
verified ·
1 Parent(s): ddd6667

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -100,10 +100,15 @@ async def admin_page():
100
 
101
  # 验证管理密码
102
  @app.post("/api/admin/login")
103
- async def admin_login(password: str):
104
- if password == Config.ADMIN_PASSWORD:
105
- return {"status": "success"}
106
- raise HTTPException(status_code=401, detail="Invalid password")
 
 
 
 
 
107
 
108
  # 获取所有keys(需要密码)
109
  @app.get("/api/keys")
@@ -111,7 +116,6 @@ async def get_keys(password: str):
111
  if password != Config.ADMIN_PASSWORD:
112
  raise HTTPException(status_code=401, detail="Invalid password")
113
  return {"keys": list(keys)}
114
-
115
  # 检查key是否有效
116
  async def check_key_valid(key: str) -> bool:
117
  headers = {
@@ -296,7 +300,7 @@ async def proxy(path: str, request: Request):
296
  # 获取并处理headers
297
  headers = dict(request.headers)
298
  headers.pop("host", None)
299
- headers["Authorization"] = f"Bearer {get_next_key()}",
300
  headers["Content-Type"] = "application/json"
301
 
302
  # 构建目标URL
 
100
 
101
  # 验证管理密码
102
  @app.post("/api/admin/login")
103
+ async def admin_login(request: Request):
104
+ try:
105
+ body = await request.json()
106
+ password = body.get("password")
107
+ if password == Config.ADMIN_PASSWORD:
108
+ return {"status": "success"}
109
+ raise HTTPException(status_code=401, detail="Invalid password")
110
+ except json.JSONDecodeError:
111
+ raise HTTPException(status_code=400, detail="Invalid JSON")
112
 
113
  # 获取所有keys(需要密码)
114
  @app.get("/api/keys")
 
116
  if password != Config.ADMIN_PASSWORD:
117
  raise HTTPException(status_code=401, detail="Invalid password")
118
  return {"keys": list(keys)}
 
119
  # 检查key是否有效
120
  async def check_key_valid(key: str) -> bool:
121
  headers = {
 
300
  # 获取并处理headers
301
  headers = dict(request.headers)
302
  headers.pop("host", None)
303
+ headers["Authorization"] = f"Bearer {get_next_key()}"
304
  headers["Content-Type"] = "application/json"
305
 
306
  # 构建目标URL