fix(huya): 优化账号密码导入交互并将导入类型严格限制为四段格式

- 交互优化:将账号标签选择器移至弹窗顶部,避免下拉列表向下展开时遮挡底部的'确定'/'导入'按钮
- 格式限制:严格限制仅允许'账号----密码----手机号----接码链接'四段格式导入
- 前后端校验:前端逐行校验格式并提示具体错误行号,后端限制 require_four_segments=True 兜底
This commit is contained in:
yml2213
2026-09-06 14:00:24 +08:00
parent d3005478a9
commit cbc7f7c9c5
4 changed files with 110 additions and 29 deletions
+10 -3
View File
@@ -693,11 +693,18 @@ def import_password_accounts(
db: Session = Depends(get_db),
current: User = Depends(get_current_user),
):
"""导入虎牙账号密码,只入库不立即登录。"""
"""导入虎牙账号密码,只入库不立即登录(仅允许四段格式)。"""
_require_huya_perm(current, "huya:import")
count, skipped = import_huya_password_accounts(db, req.text, req.tag)
count, skipped = import_huya_password_accounts(
db, req.text, req.tag, require_four_segments=True
)
if count == 0 and skipped > 0:
raise HTTPException(
status_code=400,
detail="导入失败:当前仅允许四段格式(账号----密码----手机号----接码链接)",
)
return {
"message": f"导入/更新 {count} 个虎牙账号,跳过 {skipped} 条",
"message": f"成功导入/更新 {count} 个虎牙账号,跳过 {skipped} 条",
"success": True,
"count": count,
"skipped": skipped,
+22 -5
View File
@@ -136,8 +136,13 @@ def _looks_like_url(value: str) -> bool:
return parsed.scheme in {"http", "https"} and bool(parsed.netloc)
def split_huya_password_line(line: str) -> HuyaPasswordLine | None:
"""拆分虎牙账号密码行,兼容账号----密码----手机号----验证码链接。"""
def split_huya_password_line(
line: str, require_four_segments: bool = False
) -> HuyaPasswordLine | None:
"""拆分虎牙账号密码行,兼容账号----密码----手机号----验证码链接。
若 require_four_segments 为 True,则严格限制必须包含手机号和有效接码链接。
"""
raw = (line or "").strip()
if not raw or raw.startswith("#"):
return None
@@ -174,6 +179,10 @@ def split_huya_password_line(line: str) -> HuyaPasswordLine | None:
cookie = "----".join(extra)
if not username or not password:
return None
if require_four_segments and (
not phone or not sms_url or not _looks_like_url(sms_url)
):
return None
return HuyaPasswordLine(
username=username,
password=password,
@@ -184,15 +193,23 @@ def split_huya_password_line(line: str) -> HuyaPasswordLine | None:
def import_huya_password_accounts(
db: Session, text: str, tag: str = ""
db: Session,
text: str,
tag: str = "",
require_four_segments: bool = True,
) -> tuple[int, int]:
"""导入虎牙账号密码,返回 (导入/更新数, 跳过数)。"""
"""导入虎牙账号密码,返回 (导入/更新数, 跳过数)。
默认仅允许四段格式(账号----密码----手机号----接码链接)。
"""
created_or_updated = 0
skipped = 0
tag = (tag or "").strip()
for line in (text or "").splitlines():
parsed = split_huya_password_line(line)
parsed = split_huya_password_line(
line, require_four_segments=require_four_segments
)
if not parsed:
if line.strip():
skipped += 1