feat(weibo): 增加外部 CK 账号 CRUD 与生命周期

This commit is contained in:
yml2213
2026-11-08 11:07:23 +08:00
parent dd3508d614
commit a0afa430ec
11 changed files with 611 additions and 10 deletions
+58
View File
@@ -135,6 +135,64 @@ def refresh_weibo_account(
return snapshot
def update_weibo_account_metadata(
db: Session,
account: WeiboAccount,
*,
tag: str | None = None,
remark: str | None = None,
) -> dict[str, dict[str, str]]:
"""更新人工维护的账号标签与备注。"""
changes: dict[str, dict[str, str]] = {}
if tag is not None:
clean_tag = tag.strip()
if clean_tag != (account.tag or ""):
changes["tag"] = {"old": account.tag or "", "new": clean_tag}
account.tag = clean_tag
if remark is not None:
clean_remark = remark.strip()
if clean_remark != (account.remark or ""):
changes["remark"] = {
"old": account.remark or "",
"new": clean_remark,
}
account.remark = clean_remark
if changes:
db.commit()
db.refresh(account)
return changes
def disable_weibo_account(
db: Session,
account: WeiboAccount,
*,
reason: str = "",
) -> None:
"""停用账号;保留 CK 和资料,后续可重新启用。"""
if not account.is_enabled:
return
account.is_enabled = False
account.disabled_at = _now()
account.disabled_reason = reason.strip()[:256]
db.commit()
db.refresh(account)
def enable_weibo_account(db: Session, account: WeiboAccount) -> None:
"""启用已通过完整 CK 检测的账号。"""
if account.is_enabled:
return
account.is_enabled = True
account.disabled_at = None
account.disabled_reason = ""
db.commit()
db.refresh(account)
def generate_weibo_bind_schemes(
account: WeiboAccount,
bind_url: str,