mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 01:10:23 +08:00
feat(oauth): 优化凭据导入,支持多文件选择与更多 JSON 格式
前端:简化导入界面状态管理,支持多文件拖拽/选择并自动合并内容, 移除冗余的 importFileName/manualPasteText 状态。 后端:_parse_tokens_input 新增支持 JSON 对象数组和单个 JSON 对象格式解析。
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user