Spaces:
Sleeping
Sleeping
update
Browse files
app.py
CHANGED
|
@@ -8,7 +8,7 @@ import os, json, pprint
|
|
| 8 |
from dotenv import load_dotenv
|
| 9 |
from enum import Enum
|
| 10 |
from supabase import create_client, Client
|
| 11 |
-
from datetime import datetime, timezone, time # 导入 datetime 和 timezone
|
| 12 |
|
| 13 |
# 加载环境变量
|
| 14 |
load_dotenv()
|
|
@@ -68,7 +68,12 @@ async def proxy(request: Request, protocol: ProtocolType, host:str, path: str, p
|
|
| 68 |
)
|
| 69 |
|
| 70 |
try:
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
supabase.table("airs_api_keys").update({"ran_at": current_local_time}).eq("id", send_req.get('api_key_info').get('api_key_id')).execute()
|
| 73 |
print('更新成功')
|
| 74 |
except Exception as e:
|
|
@@ -123,6 +128,8 @@ async def make_send_req(request: Request, protocol: ProtocolType, host:str, path
|
|
| 123 |
print(f"读取客户端请求体失败: {e}")
|
| 124 |
return None
|
| 125 |
_api_key_info = await get_api_key_info(_model)
|
|
|
|
|
|
|
| 126 |
_headers["Authorization"] = f"Bearer {_api_key_info['api_key']}"
|
| 127 |
|
| 128 |
send_req={
|
|
|
|
| 8 |
from dotenv import load_dotenv
|
| 9 |
from enum import Enum
|
| 10 |
from supabase import create_client, Client
|
| 11 |
+
from datetime import datetime, timezone, timedelta, time # 导入 datetime 和 timezone
|
| 12 |
|
| 13 |
# 加载环境变量
|
| 14 |
load_dotenv()
|
|
|
|
| 68 |
)
|
| 69 |
|
| 70 |
try:
|
| 71 |
+
# 创建北京时间时区对象(UTC+8)
|
| 72 |
+
beijing_tz = timezone(timedelta(hours=8))
|
| 73 |
+
now_beijing = datetime.now(beijing_tz) # 带时区的datetime对象
|
| 74 |
+
current_local_time = now_beijing.isoformat()
|
| 75 |
+
# current_local_time = int(now_beijing.timestamp()) # 正确的时间戳
|
| 76 |
+
# current_local_time = datetime.now().isoformat()
|
| 77 |
supabase.table("airs_api_keys").update({"ran_at": current_local_time}).eq("id", send_req.get('api_key_info').get('api_key_id')).execute()
|
| 78 |
print('更新成功')
|
| 79 |
except Exception as e:
|
|
|
|
| 128 |
print(f"读取客户端请求体失败: {e}")
|
| 129 |
return None
|
| 130 |
_api_key_info = await get_api_key_info(_model)
|
| 131 |
+
if not _api_key_info:
|
| 132 |
+
raise HTTPException(status_code=400, detail="未找到匹配的API密钥!")
|
| 133 |
_headers["Authorization"] = f"Bearer {_api_key_info['api_key']}"
|
| 134 |
|
| 135 |
send_req={
|