Spaces:
Sleeping
Sleeping
yu commited on
Commit ·
b97c321
1
Parent(s): 29f0f0e
feat: 账户过期自动禁用功能
Browse files- 账户选择时自动排除已过期账户
- JWT获取时检查过期状态并自动禁用
- 过期账户在管理页面显示为灰色(半透明+灰色背景)
- 状态显示为"过期禁用"
- core/templates.py +16 -4
- main.py +8 -2
core/templates.py
CHANGED
|
@@ -80,12 +80,24 @@ def generate_admin_html(request: Request, multi_account_mgr, show_hide_tip: bool
|
|
| 80 |
remaining_hours = config.get_remaining_hours()
|
| 81 |
status_text, status_color, expire_display = main.format_account_expiration(remaining_hours)
|
| 82 |
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
accounts_html += f"""
|
| 88 |
-
<div class="card account-card">
|
| 89 |
<div class="acc-header">
|
| 90 |
<div class="acc-title">
|
| 91 |
<span class="status-dot" style="background-color: {dot_color};" title="{dot_title}"></span>
|
|
|
|
| 80 |
remaining_hours = config.get_remaining_hours()
|
| 81 |
status_text, status_color, expire_display = main.format_account_expiration(remaining_hours)
|
| 82 |
|
| 83 |
+
# 检查账户是否过期
|
| 84 |
+
is_expired = config.is_expired()
|
| 85 |
+
|
| 86 |
+
# 如果过期,覆盖状态显示为灰色和"过期禁用"
|
| 87 |
+
if is_expired:
|
| 88 |
+
status_text = "过期禁用"
|
| 89 |
+
status_color = "#9e9e9e"
|
| 90 |
+
dot_color = "#9e9e9e"
|
| 91 |
+
dot_title = "过期禁用"
|
| 92 |
+
card_style = 'style="opacity: 0.5; background: #f5f5f5;"' # 灰色样式
|
| 93 |
+
else:
|
| 94 |
+
is_avail = account_manager.is_available
|
| 95 |
+
dot_color = "#34c759" if is_avail else "#ff3b30"
|
| 96 |
+
dot_title = "可用" if is_avail else "不可用"
|
| 97 |
+
card_style = ''
|
| 98 |
|
| 99 |
accounts_html += f"""
|
| 100 |
+
<div class="card account-card" {card_style}>
|
| 101 |
<div class="acc-header">
|
| 102 |
<div class="acc-title">
|
| 103 |
<span class="status-dot" style="background-color: {dot_color};" title="{dot_title}"></span>
|
main.py
CHANGED
|
@@ -263,6 +263,12 @@ class AccountManager:
|
|
| 263 |
|
| 264 |
async def get_jwt(self, request_id: str = "") -> str:
|
| 265 |
"""获取 JWT token (带错误处理)"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 266 |
try:
|
| 267 |
if self.jwt_manager is None:
|
| 268 |
# 延迟初始化 JWTManager (避免循环依赖)
|
|
@@ -380,10 +386,10 @@ class MultiAccountManager:
|
|
| 380 |
raise HTTPException(503, f"Account {account_id} temporarily unavailable")
|
| 381 |
return account
|
| 382 |
|
| 383 |
-
# 轮询选择可用账户
|
| 384 |
available_accounts = [
|
| 385 |
acc_id for acc_id in self.account_list
|
| 386 |
-
if self.accounts[acc_id].should_retry()
|
| 387 |
]
|
| 388 |
|
| 389 |
if not available_accounts:
|
|
|
|
| 263 |
|
| 264 |
async def get_jwt(self, request_id: str = "") -> str:
|
| 265 |
"""获取 JWT token (带错误处理)"""
|
| 266 |
+
# 检查账户是否过期
|
| 267 |
+
if self.config.is_expired():
|
| 268 |
+
self.is_available = False
|
| 269 |
+
logger.warning(f"[ACCOUNT] [{self.config.account_id}] 账户已过期,已自动禁用")
|
| 270 |
+
raise HTTPException(403, f"Account {self.config.account_id} has expired")
|
| 271 |
+
|
| 272 |
try:
|
| 273 |
if self.jwt_manager is None:
|
| 274 |
# 延迟初始化 JWTManager (避免循环依赖)
|
|
|
|
| 386 |
raise HTTPException(503, f"Account {account_id} temporarily unavailable")
|
| 387 |
return account
|
| 388 |
|
| 389 |
+
# 轮询选择可用账户(排除过期账户)
|
| 390 |
available_accounts = [
|
| 391 |
acc_id for acc_id in self.account_list
|
| 392 |
+
if self.accounts[acc_id].should_retry() and not self.accounts[acc_id].config.is_expired()
|
| 393 |
]
|
| 394 |
|
| 395 |
if not available_accounts:
|