feat(oauth): 优化凭据导入,支持多文件选择与更多 JSON 格式

前端:简化导入界面状态管理,支持多文件拖拽/选择并自动合并内容,
移除冗余的 importFileName/manualPasteText 状态。
后端:_parse_tokens_input 新增支持 JSON 对象数组和单个 JSON 对象格式解析。
This commit is contained in:
fawney19
2026-02-28 22:06:21 +08:00
parent 85a126f48a
commit fbcb54a8a5
2 changed files with 125 additions and 105 deletions

View File

@@ -1214,8 +1214,10 @@ def _parse_tokens_input(raw_input: str) -> list[str]:
支持的格式:
1. 单个 Token 字符串
2. JSON 数组: ["token1", "token2", ...]
3. 纯 Token 导入(一行一个): "token1\\ntoken2\\ntoken3"
2. JSON 字符串数组: ["token1", "token2", ...]
3. JSON 对象数组: [{"refresh_token": "token1", ...}, ...]
4. 单个 JSON 对象: {"refresh_token": "token1", ...}
5. 纯 Token 导入(一行一个): "token1\\ntoken2\\ntoken3"
返回: Token 字符串列表
"""
@@ -1233,10 +1235,25 @@ def _parse_tokens_input(raw_input: str) -> list[str]:
for item in parsed:
if isinstance(item, str) and item.strip():
result.append(item.strip())
elif isinstance(item, dict):
token = item.get("refresh_token", "")
if isinstance(token, str) and token.strip():
result.append(token.strip())
return result
except json.JSONDecodeError:
pass # 不是有效 JSON继续尝试其他格式
# 单个 JSON 对象
if raw.startswith("{"):
try:
parsed = json.loads(raw)
if isinstance(parsed, dict):
token = parsed.get("refresh_token", "")
if isinstance(token, str) and token.strip():
return [token.strip()]
except json.JSONDecodeError:
pass
# 纯 Token 导入(一行一个)
lines = raw.splitlines()
for line in lines: