feat(export): 支持 CSV 计划导出和稳定导出索引 (#114)

两个核心增强:

1. **CSV 计划导出工作流** (`--write-plan-csv` / `--from-plan-csv`)
   - 支持 blacklist (export=0 跳过) / whitelist (export=1 导出) 两种模式
   - `--size-mode estimate|scan` 控制是否扫本地附件
   - UTF-8 BOM 编码, Excel/WPS 直接打开
   - 解决了之前"动不动全量导出"的痛点

2. **`_export_index.json` 稳定导出索引**
   - 用 username 追踪当前 JSON 文件
   - 联系人备注/群名变化时自动重命名旧文件 (而不是产生孤儿)
   - 同名联系人冲突时自动追加 `__<username>` 后缀
   - atomic write (tmp + os.replace), bootstrap from existing files

3. **JSON metadata 扩展**
   - 新增 `date_first_msg / date_last_msg / contact_remark / contact_nick_name / contact_tags / contact_memo`

测试: 717 行, 20 tests pass, 覆盖 CRUD 索引、黑白名单、命名冲突、incremental rename、UTF-8 BOM。
This commit is contained in:
phoenixray2000
2026-05-19 02:20:30 +08:00
committed by GitHub
parent 4a29841ec1
commit 728dbb72df
8 changed files with 1885 additions and 56 deletions

View File

@@ -315,19 +315,20 @@ def main():
print("[*] 开始解密全部数据库...")
print()
from decrypt_db import main as decrypt_all
_call_with_argv(decrypt_all, ["decrypt_db.py", *sys.argv[2:]])
decrypt_all(sys.argv[2:])
elif cmd in ("export", "all"):
print("[*] 开始解密全部数据库...")
print()
from decrypt_db import main as decrypt_all
_call_with_argv(decrypt_all, ["decrypt_db.py"])
decrypt_all([])
print()
print("[*] 开始批量导出聊天记录...")
print()
from export_all_chats import main as export_all
try:
_call_with_argv(export_all, ["export_all_chats.py"])
export_args = sys.argv[2:] if cmd == "export" else []
export_all(export_args)
except SystemExit:
pass