fix(设备端): 轮询不再用打码名覆盖广播的完整昵称
- push_account_name 成功后把完整名记进 device.cur_account_name - /api/device/agent/account 在 dumpsys 打码名与完整名匹配时返回完整名 - cache_names 不再用匹配的打码名覆盖完整名 - 增加 mask_matches 用例
This commit is contained in:
+59
-1
@@ -179,6 +179,56 @@ def probe_online_dumpsys(serials=None, workers=8):
|
||||
return out
|
||||
|
||||
|
||||
def mask_matches(masked, full):
|
||||
"""MIUI 打码名(`锋哥苏***探访`)是否与完整名(`锋哥苏州百业探访`)匹配。
|
||||
|
||||
按 `*` 分段、**按顺序**在完整名里找;没有 `*` 时按全等比较。
|
||||
```
|
||||
mask_matches("锋哥苏***探访", "锋哥苏州百业探访") -> True
|
||||
mask_matches("锋哥苏***探访", "周周苏州百业探访") -> False
|
||||
```
|
||||
"""
|
||||
masked = (masked or "").strip()
|
||||
full = (full or "").strip()
|
||||
if not masked or not full:
|
||||
return False
|
||||
if "*" not in masked:
|
||||
return masked == full
|
||||
pos = 0
|
||||
for part in [p for p in re.split(r"\*+", masked) if p]:
|
||||
i = full.find(part, pos)
|
||||
if i < 0:
|
||||
return False
|
||||
pos = i + len(part)
|
||||
return True
|
||||
|
||||
|
||||
def remember_name(serial, name):
|
||||
"""把**完整昵称**记到 `device.cur_account_name`(广播下发成功后调用)。
|
||||
|
||||
轮询接口会拿它和 dumpsys 的打码名比对:对得上就返回完整名,
|
||||
避免设备端每 2 秒轮询把广播推的完整昵称覆盖成 `***`。
|
||||
必须在 Flask app context 里写库(worker 线程里自动推一个)。
|
||||
"""
|
||||
name = (name or "").strip()
|
||||
if not serial or not name:
|
||||
return False
|
||||
try:
|
||||
from core import account_folder as _af
|
||||
from core.models import Device, db
|
||||
with _af._ctx():
|
||||
row = Device.query.get(serial)
|
||||
if row is None:
|
||||
return False
|
||||
row.cur_account_name = name[:80]
|
||||
row.cur_name_at = time.strftime("%Y-%m-%d %H:%M:%S")
|
||||
db.session.commit()
|
||||
return True
|
||||
except Exception as e:
|
||||
_log.warning(f"[{serial}] 记录完整账号名失败(不影响广播): {e}")
|
||||
return False
|
||||
|
||||
|
||||
def push_account_name(serial, name=None):
|
||||
"""把当前抖音账号推给设备端 Agent(素材页/身份页显示)。
|
||||
|
||||
@@ -207,6 +257,8 @@ def push_account_name(serial, name=None):
|
||||
)
|
||||
ok = "broadcast completed" in (out or "").lower()
|
||||
if ok:
|
||||
# 平台侧记住完整昵称:设备端轮询时用它盖掉 dumpsys 的打码名
|
||||
remember_name(serial, name)
|
||||
_log.info(f"[{serial}] 已下发当前账号: {name}")
|
||||
return True, f"已下发 {name}"
|
||||
_log.warning(f"[{serial}] 下发账号名失败: {(out or '')[:120]}")
|
||||
@@ -271,7 +323,13 @@ def cache_names(result):
|
||||
row = Device.query.get(serial)
|
||||
if not row:
|
||||
continue
|
||||
row.cur_account_name = name[:80]
|
||||
old = (row.cur_account_name or "").strip()
|
||||
# dumpsys 探测到的是打码名:若与已缓存的完整名一致,**保留完整名**
|
||||
# (否则设备端每次轮询都会把广播推的完整昵称覆盖成 `***`)
|
||||
if "*" not in old and mask_matches(name, old):
|
||||
pass
|
||||
else:
|
||||
row.cur_account_name = name[:80]
|
||||
row.cur_name_at = now
|
||||
db.session.commit()
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user