解决超话签到中选择性签到的逻辑问题

This commit is contained in:
2026-04-08 08:34:59 +08:00
parent 31d862dfa0
commit 9e69d34f81
8 changed files with 167 additions and 32 deletions

View File

@@ -304,7 +304,34 @@ async def list_topics(
return error_response("Cookie 解密失败", "COOKIE_ERROR", status_code=400)
topics = await _get_super_topics(cookie_str, account.weibo_user_id)
return success_response({"topics": topics, "total": len(topics)})
return success_response({
"topics": topics,
"total": len(topics),
"selected_topics": account.selected_topics,
})
@router.put("/{account_id}/topics")
async def save_selected_topics(
account_id: str,
body: dict = Body(...),
user: User = Depends(get_current_user),
db: AsyncSession = Depends(get_db),
):
"""保存用户选择的签到超话列表。空列表或 null 表示签到全部。"""
account = await _get_owned_account(account_id, user, db)
selected = body.get("selected_topics")
# null 或空列表都表示全部签到
if selected and isinstance(selected, list) and len(selected) > 0:
account.selected_topics = selected
else:
account.selected_topics = None
await db.commit()
await db.refresh(account)
return success_response(
_account_to_dict(account),
f"已保存 {len(selected) if selected else 0} 个超话" if selected else "已设为签到全部超话",
)
# ---- MANUAL SIGNIN ----

View File

@@ -27,6 +27,7 @@ class AccountResponse(BaseModel):
weibo_user_id: str
remark: Optional[str]
status: str
selected_topics: Optional[list] = None
last_checked_at: Optional[datetime]
created_at: Optional[datetime]

View File

@@ -2,7 +2,7 @@
import uuid
from sqlalchemy import Column, DateTime, ForeignKey, String, Text
from sqlalchemy import Column, DateTime, ForeignKey, JSON, String, Text
from sqlalchemy.orm import relationship
from sqlalchemy.sql import func
@@ -19,6 +19,7 @@ class Account(Base):
encrypted_cookies = Column(Text, nullable=False)
iv = Column(String(32), nullable=False)
status = Column(String(20), default="pending")
selected_topics = Column(JSON, nullable=True) # 用户选择的签到超话列表null=全部
last_checked_at = Column(DateTime, nullable=True)
created_at = Column(DateTime, server_default=func.now())

View File

@@ -369,6 +369,7 @@ async def _async_do_signin(account_id: str, cron_expr: str = ""):
return {"status": "failed", "reason": "cookie decryption failed"}
acc_id = str(account.id)
acc_selected_topics = account.selected_topics # 用户选择的超话列表
except Exception as e:
await eng.dispose()
raise e
@@ -387,6 +388,16 @@ async def _async_do_signin(account_id: str, cron_expr: str = ""):
await session.commit()
return {"status": "completed", "signed": 0, "message": "no topics"}
# 如果用户选择了特定超话,只签选中的
if acc_selected_topics and isinstance(acc_selected_topics, list):
selected_cids = {t.get("containerid") for t in acc_selected_topics if t.get("containerid")}
if selected_cids:
topics = [t for t in topics if t["containerid"] in selected_cids]
logger.info(f"📌 按用户选择过滤: {len(topics)} 个超话 (共 {len(selected_cids)} 个已选)")
if not topics:
return {"status": "completed", "signed": 0, "message": "no selected topics"}
signed = already = failed = 0
log_entries = []