fix: get_db_handle()优先选MSG0.db而非MicroMsg.db

This commit is contained in:
hmo
2026-05-20 12:29:17 +08:00
parent 3425ded733
commit 4296af615f
+19 -5
View File
@@ -53,13 +53,27 @@ def get_db_handle():
r = wxpost("/api/getDBInfo", timeout=10)
dbs = r.get("data") or []
# WeChat 3.9.5.81+: messages stored in MSG0.db, MSG1.db, etc.
# Older versions: messages in MicroMsg.db's MSG table
# Also check ChatMsg.db (has ChatMsg table with different schema).
# Prefer MSG*.db over MicroMsg.db (MicroMsg.db has "Msg" in name but no MSG table in new versions).
candidate = None
for db in dbs:
dbname = db.get("databaseName", "")
if "MSG" in dbname or "Msg" in dbname:
db_handle_cache = db.get("handle")
log(f"History DB: {dbname} handle={db_handle_cache}")
return db_handle_cache
# Prefer MSG0.db/MSG1.db over MicroMsg.db
if dbname.upper().startswith("MSG") and dbname.upper().endswith(".DB"):
candidate = db.get("handle")
log(f"History DB: {dbname} handle={candidate}")
break
# Fallback: check if any table is named MSG
for t in (db.get("tables") or []):
if t.get("tableName") == "MSG":
candidate = db.get("handle")
log(f"History DB: {dbname} handle={candidate}")
break
if candidate:
break
if candidate:
db_handle_cache = candidate
return candidate
log("History DB handle: NOT FOUND")
return None