账号导入--可以直接打标签
This commit is contained in:
@@ -186,8 +186,11 @@ def import_accounts(
|
||||
db: Session = Depends(get_db),
|
||||
current: User = Depends(require_permission("account:import")),
|
||||
):
|
||||
"""批量导入账号。格式:用户名|密码|邮箱|邮箱密码|标签(可选)"""
|
||||
accounts, skipped = parse_and_build_accounts(req.text)
|
||||
"""批量导入账号。格式:用户名|密码|邮箱|邮箱密码|标签(可选)
|
||||
|
||||
req.tag 为统一标签兜底:某行未单独写标签时使用该值,行内标签优先。
|
||||
"""
|
||||
accounts, skipped = parse_and_build_accounts(req.text, req.tag)
|
||||
|
||||
if accounts:
|
||||
db.add_all(accounts)
|
||||
|
||||
@@ -80,8 +80,13 @@ class UserUpdate(BaseModel):
|
||||
|
||||
# ---- 账号 ----
|
||||
class AccountImport(BaseModel):
|
||||
"""批量导入,文本格式:用户名|密码|邮箱|邮箱密码"""
|
||||
"""批量导入,文本格式:用户名|密码|邮箱|邮箱密码|标签(可选)
|
||||
|
||||
tag 为本次导入的统一标签兜底:某行未单独写标签时使用该值,
|
||||
行内第5列标签优先。
|
||||
"""
|
||||
text: str
|
||||
tag: str = ""
|
||||
|
||||
|
||||
class AccountAssign(BaseModel):
|
||||
|
||||
@@ -31,15 +31,21 @@ def cookie_account_ids_query(db: Session):
|
||||
).distinct()
|
||||
|
||||
|
||||
def parse_and_build_accounts(text: str) -> tuple[list[Account], int]:
|
||||
def parse_and_build_accounts(text: str, default_tag: str = "") -> tuple[list[Account], int]:
|
||||
"""
|
||||
解析批量导入文本,构建 Account ORM 对象列表。
|
||||
|
||||
Args:
|
||||
text: 批量导入文本,每行格式:用户名|密码|邮箱|邮箱密码|标签(可选)
|
||||
default_tag: 统一标签兜底。某行未单独写标签时使用该值,
|
||||
行内第5列标签优先。
|
||||
|
||||
Returns:
|
||||
(accounts, skipped_count)
|
||||
"""
|
||||
from core.douyu.email_verifier import get_email_config_for_account
|
||||
|
||||
default_tag = (default_tag or "").strip()
|
||||
accounts = []
|
||||
skipped = 0
|
||||
for line in text.strip().split('\n'):
|
||||
@@ -52,7 +58,9 @@ def parse_and_build_accounts(text: str) -> tuple[list[Account], int]:
|
||||
continue
|
||||
|
||||
username, password, email, email_password = [p.strip() for p in parts[:4]]
|
||||
tag = parts[4].strip() if len(parts) > 4 else ""
|
||||
line_tag = parts[4].strip() if len(parts) > 4 else ""
|
||||
# 行内标签优先,未写则用统一兜底标签
|
||||
tag = line_tag or default_tag
|
||||
if not all([username, password, email, email_password]):
|
||||
skipped += 1
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user