feat(资产管理): 账号状态列 + 任务变量回写;通用任务 App 回退
- device_account 新增 account_status(schema v21),资产表可手改 - 任务「读取文字」var=account_status 自动回写当前账号;元素不存在=正常 - 计划:任务段没有 open_app 时回退到唯一 App(创作者中心这类通用任务) - 测试/文档同步
This commit is contained in:
@@ -171,6 +171,7 @@ def list_accounts(prof=None):
|
||||
"unscanned": max(0, media - total),
|
||||
"has_dir": has_dir,
|
||||
"device_name": rr.get("device_name") or "",
|
||||
"account_status": rr.get("account_status") or "",
|
||||
"serial": rr.get("serial") or "",
|
||||
"pooled": bool(rr.get("pooled")),
|
||||
"online": bool(rr.get("online")),
|
||||
@@ -1142,6 +1143,28 @@ def roster_rows():
|
||||
return out
|
||||
|
||||
|
||||
def set_account_status(name, status=""):
|
||||
"""按账号名写账号库的「账号状态」(任务变量回写用)。
|
||||
|
||||
名字先精确匹配昵称,再按抖音号兜底;账号库里没有这个号 → 返回 False(**不新建行**)。
|
||||
供任务里的「读取文字」在变量名是 `account_status` 时调用:读到什么写什么,
|
||||
读不到(元素不存在)写「正常」。
|
||||
"""
|
||||
from core.models import db, DeviceAccount
|
||||
key = (name or "").strip()
|
||||
if not key:
|
||||
return False
|
||||
with _ctx():
|
||||
row = (DeviceAccount.query.filter_by(nickname=key).first()
|
||||
or DeviceAccount.query.filter_by(douyin_id=key).first())
|
||||
if row is None:
|
||||
return False
|
||||
row.account_status = (status or "").strip()[:80]
|
||||
row.updated_at = _now()
|
||||
db.session.commit()
|
||||
return True
|
||||
|
||||
|
||||
def device_of_name(name, rows=None):
|
||||
"""账号名 → 设备信息。**精确匹配名字**;名字对不上时再拿抖音号试一次。
|
||||
|
||||
|
||||
@@ -520,6 +520,9 @@ class DeviceAccount(db.Model):
|
||||
can_post_video = db.Column(db.Boolean, default=False) # 可发视频(空=否)
|
||||
bio = db.Column(db.Text, default="") # 简介
|
||||
note = db.Column(db.Text, default="") # 备注
|
||||
# 账号状态(正常 / 账号异常 / 限流…):资产管理里可手改;任务里「读取文字」
|
||||
# 存到变量 `account_status` 时会自动回写这一列(见 tasks/generic/task.py)。
|
||||
account_status = db.Column(db.String(80), default="")
|
||||
created_at = db.Column(db.String(20), default="")
|
||||
updated_at = db.Column(db.String(20), default="")
|
||||
|
||||
@@ -531,6 +534,7 @@ class DeviceAccount(db.Model):
|
||||
"sim_in_device": bool(self.sim_in_device),
|
||||
"can_post_video": bool(self.can_post_video),
|
||||
"bio": self.bio or "", "note": self.note or "",
|
||||
"account_status": self.account_status or "",
|
||||
"created_at": self.created_at or "", "updated_at": self.updated_at or ""}
|
||||
|
||||
def __repr__(self):
|
||||
@@ -993,6 +997,8 @@ SCHEMA_MIGRATIONS = [
|
||||
"每段可配发布素材/循环/前后回主页/简单条件),空 = 老计划按 action_id 单动作组跑", None),
|
||||
(20, "计划调度·内置切号可编辑:ae_plan 新增 ready(账号就绪/切号的参数覆盖:"
|
||||
"选择器/超时/切后等待/重试/登录页处置;enabled=false = 关闭内置切号)", None),
|
||||
(21, "账号状态:device_account 新增 account_status(资产管理可手改;任务里"
|
||||
"「读取文字」写变量 account_status 时自动回写,用于创作者中心/异常检测)", None),
|
||||
]
|
||||
|
||||
# 当前 schema 版本(备份/恢复用它判断新旧,也写进 app_meta.schema_version)
|
||||
|
||||
@@ -543,6 +543,13 @@ def build_plan_job(plan, device, plan_run_id=""):
|
||||
app_row = AeApp.query.get(act.app_id)
|
||||
if not segs and act is None:
|
||||
return None, "动作组不存在(去「动作」里检查一下)"
|
||||
if app_row is None:
|
||||
# 通用任务段可能没有 `open_app`(例如「抖音创作者中心」直接在「我」页操作)→
|
||||
# 从步骤里反查不到 App。此时若只登记了一个 App,就用它(开场仍要冷启动 App);
|
||||
# 多个 App 时不猜,继续报错让用户明确归属。
|
||||
_apps = AeApp.query.limit(2).all()
|
||||
if len(_apps) == 1:
|
||||
app_row = _apps[0]
|
||||
if app_row is None:
|
||||
return None, "App 不存在(去「动作」里检查一下动作的归属 App)"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user