mirror of
https://wget.la/https://github.com/Wxw-Gu/WechatExplorer
synced 2026-08-18 20:19:09 +08:00
Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a0b163823d | ||
|
|
3eb4438f4c | ||
|
|
7932ea2f54 | ||
|
|
7f7d673abb | ||
|
|
4bba8bd871 | ||
|
|
30c47af1f9 | ||
|
|
77aa74dd92 | ||
|
|
f96ada906c | ||
|
|
a50e903e55 |
@@ -1,7 +1,6 @@
|
|||||||
node_modules
|
node_modules
|
||||||
dist
|
dist
|
||||||
out
|
out
|
||||||
docs/
|
|
||||||
.env
|
.env
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.eslintcache
|
.eslintcache
|
||||||
|
|||||||
@@ -50,8 +50,7 @@ MAC系统 获取微信聊天记录 AI一键生成群聊总结
|
|||||||
### 使用前置要求
|
### 使用前置要求
|
||||||
|
|
||||||
- **微信版本**:
|
- **微信版本**:
|
||||||
- 微信 <= 4.0: 可正常使用,获取数据库密码方式参考:[Mac 导出微信聊天记录](https://blog.vcvit.me/2024/08/02/mac-export-wechat-chat-records/)
|
- 微信 4.0+: 已支持部分能力,仍在持续迭代与兼容性验证中;如需更成熟的完整方案,推荐使用 [WeFlow](https://github.com/hicccc77/WeFlow) [Chatlog](https://github.com/sjzar/chatlog)
|
||||||
- 微信 >= 4.0: 已支持部分能力,仍在持续迭代与兼容性验证中;如需更成熟的完整方案,推荐使用 [WeFlow](https://github.com/hicccc77/WeFlow) [Chatlog](https://github.com/sjzar/chatlog)
|
|
||||||
- 如无法获取本地数据库密码,则无法使用当前项目
|
- 如无法获取本地数据库密码,则无法使用当前项目
|
||||||
- Node.js (推荐 v16+)
|
- Node.js (推荐 v16+)
|
||||||
- pnpm@7
|
- pnpm@7
|
||||||
@@ -84,6 +83,74 @@ MAC系统 获取微信聊天记录 AI一键生成群聊总结
|
|||||||
1. 从 WeFlow/Chatlog 设置中导出
|
1. 从 WeFlow/Chatlog 设置中导出
|
||||||
2. 使用内存扫描工具从微信进程中自动提取(待实现)
|
2. 使用内存扫描工具从微信进程中自动提取(待实现)
|
||||||
|
|
||||||
|
## 🤖 AI 集成(本地 HTTP API)
|
||||||
|
|
||||||
|
WechatExplorer 内置了一个本地 HTTP API 服务,默认监听 `127.0.0.1:6131`(纯本地,无鉴权),让你能够从 **Claude Desktop / Claude Code / Codex / curl / 任何脚本** 读取已经解锁的微信聊天记录。
|
||||||
|
|
||||||
|
### 启用本地 API
|
||||||
|
|
||||||
|
API 服务在 WechatExplorer 启动时自动启用,**不需要任何配置**。只需要:
|
||||||
|
1. 安装并启动 WechatExplorer
|
||||||
|
2. 完成首次密钥配置(主窗口第一步),解锁 WCDB 数据库
|
||||||
|
3. API 即在 `http://127.0.0.1:6131` 可用
|
||||||
|
|
||||||
|
### 7×24 提供 API(菜单栏常驻模式)
|
||||||
|
|
||||||
|
默认情况下,关闭主窗口时 macOS 会让 app 继续运行,但 Windows / Linux 会退出。如果希望主窗口关闭后 API 服务仍可用,启用菜单栏模式:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 任选一种方式
|
||||||
|
WXE_TRAY=1 open /Applications/WechatExplorer.app
|
||||||
|
/Applications/WechatExplorer.app/Contents/MacOS/WechatExplorer --tray
|
||||||
|
```
|
||||||
|
|
||||||
|
启用后:
|
||||||
|
- macOS dock 图标自动隐藏
|
||||||
|
- 菜单栏出现 WechatExplorer 图标(可点击重新打开主窗口、查看 API 状态)
|
||||||
|
- 主窗口关闭后 API 服务继续运行
|
||||||
|
|
||||||
|
### API 端点一览
|
||||||
|
|
||||||
|
| 端点 | 说明 |
|
||||||
|
|------|------|
|
||||||
|
| `GET /api/v1/health` | 健康检查 |
|
||||||
|
| `GET /api/v1/current_time` | 获取当前本地时间(用于"今天/昨天"换算) |
|
||||||
|
| `GET /api/v1/contact?filter=xxx` | 联系人 / 群聊列表 |
|
||||||
|
| `GET /api/v1/chatroom?keyword=xxx` | 搜索群聊 |
|
||||||
|
| `GET /api/v1/chatlog?talker=xxx&time=2026-07-03` | 聊天记录 |
|
||||||
|
| `GET /api/v1/group_snapshot?md5=xxx` | 群成员快照 |
|
||||||
|
| `GET /api/v1/resolve?q=群昵称` | 把昵称/wxid/md5 解析成 md5 |
|
||||||
|
|
||||||
|
详细参数、返回结构、时间格式见 [`docs/skill/wechatexplorer-reader/SKILL.md`](./docs/skill/wechatexplorer-reader/SKILL.md)。
|
||||||
|
|
||||||
|
### 让 Claude 自动总结你的群聊
|
||||||
|
|
||||||
|
复制 [`docs/skill/wechatexplorer-reader/SKILL.md`](./docs/skill/wechatexplorer-reader/SKILL.md) 到 `~/.claude/skills/`,然后在 Claude Desktop 里说:
|
||||||
|
|
||||||
|
> "今天 技术交流群 聊了啥?"
|
||||||
|
|
||||||
|
Claude 会自动:
|
||||||
|
1. 调 `current_time` 拿到今天日期
|
||||||
|
2. 调 `chatroom` 找到目标群
|
||||||
|
3. 调 `chatlog` 拿 JSON 聊天记录
|
||||||
|
4. 自己用 LLM 生成总结报告
|
||||||
|
|
||||||
|
### curl 示例
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 健康检查
|
||||||
|
curl http://127.0.0.1:6131/api/v1/health
|
||||||
|
|
||||||
|
# 今天 摸鱼交流群 的聊天记录
|
||||||
|
curl -G "http://127.0.0.1:6131/api/v1/chatlog" \
|
||||||
|
--data-urlencode "talker=摸鱼交流群" \
|
||||||
|
--data-urlencode "time=$(date +%Y-%m-%d)"
|
||||||
|
|
||||||
|
# 把群昵称解析成 md5
|
||||||
|
curl -G "http://127.0.0.1:6131/api/v1/resolve" \
|
||||||
|
--data-urlencode "q=摸鱼交流群"
|
||||||
|
```
|
||||||
|
|
||||||
## ⚠️ 免责声明
|
## ⚠️ 免责声明
|
||||||
|
|
||||||
本项目仅供学习和研究使用。请勿用于非法用途。开发者不对使用本项目造成的任何后果负责。请遵守相关法律法规和微信使用协议。
|
本项目仅供学习和研究使用。请勿用于非法用途。开发者不对使用本项目造成的任何后果负责。请遵守相关法律法规和微信使用协议。
|
||||||
|
|||||||
@@ -0,0 +1,336 @@
|
|||||||
|
---
|
||||||
|
name: wechatexplorer-reader
|
||||||
|
description: 通过本地 HTTP API 读取 WechatExplorer 解锁后的微信聊天数据(本地服务由 WechatExplorer.app 提供)。当用户提到微信聊天记录、群消息、看看群里说了什么、查一下微信、分析微信对话、总结群聊等场景时,使用此技能。注意:此技能的数据源是用户本机 WechatExplorer app,而非 chatlog/WeFlow。
|
||||||
|
---
|
||||||
|
|
||||||
|
# WechatExplorer Reader
|
||||||
|
|
||||||
|
通过本地 HTTP API(`http://127.0.0.1:6131`)读取 WechatExplorer 已经解锁的微信数据库内容。
|
||||||
|
|
||||||
|
## 数据源
|
||||||
|
|
||||||
|
- **本服务由 WechatExplorer.app 提供**,数据完全在本地处理,不会上传任何服务器
|
||||||
|
- 用户必须在 WechatExplorer 主窗口完成**首次密钥配置**(解锁 WCDB 数据库)
|
||||||
|
- 默认监听 `127.0.0.1:6131`,仅本机可访问,无需鉴权
|
||||||
|
|
||||||
|
## 前置条件
|
||||||
|
|
||||||
|
1. **安装并启动 WechatExplorer.app**(从项目 release 页面下载)
|
||||||
|
2. **首次启动时完成密钥配置**:在主界面第一步输入微信数据库密钥(64 位 hex),完成 WCDB 初始化
|
||||||
|
3. **如需 7×24 提供 API**:用 `WXE_TRAY=1` 或 `--tray` 参数启动 app,启用菜单栏常驻模式(主窗口关闭后服务仍在)
|
||||||
|
|
||||||
|
## API 列表
|
||||||
|
|
||||||
|
GET 用于读取数据,`POST /api/v1/report` 用于生成群日报(HTML + 长图)。所有端点返回 JSON。
|
||||||
|
|
||||||
|
| 端点 | 用途 | 关键参数 |
|
||||||
|
|------|------|---------|
|
||||||
|
| `GET /api/v1/health` | 健康检查 + 是否已初始化 | — |
|
||||||
|
| `GET /api/v1/current_time` | 获取当前本地时间(用于"今天/昨天"换算) | — |
|
||||||
|
| `GET /api/v1/contact` | 联系人 / 群聊列表 | `filter`(昵称模糊)、`type`(`user` \| `group`) |
|
||||||
|
| `GET /api/v1/chatroom` | 群聊列表(等同 contact?type=group) | `keyword` |
|
||||||
|
| `GET /api/v1/recent_chat` | 最近会话 | `limit`(默认 50) |
|
||||||
|
| `GET /api/v1/chatlog` | 聊天记录 | `talker`、`time` 或 `startTime`/`endTime` |
|
||||||
|
| `GET /api/v1/group_snapshot` | 群成员快照 | `md5` |
|
||||||
|
| `GET /api/v1/resolve` | 把昵称/wxid/md5 解析成 md5 | `q` |
|
||||||
|
| `POST /api/v1/report` | 生成群聊日报 HTML + 长图 PNG | JSON body(见下文,推荐传 `metadata.talker` 让服务端自动反推真头像) |
|
||||||
|
|
||||||
|
### `talker` 参数可接受的值
|
||||||
|
|
||||||
|
`chatlog` 和 `recent_chat` 的 `talker` / 列表项 ID 支持以下三种形式,服务端会按 `nickname → wxid → md5` 顺序匹配:
|
||||||
|
|
||||||
|
1. **群昵称 / 好友备注**(模糊匹配,如 `技术交流`、`摸鱼群`)
|
||||||
|
2. **微信 wxid**(如 `wxid_abc123`、`gh_xxxxx@chatroom`)
|
||||||
|
3. **会话 md5**(如 `49023470180@chatroom` 的 md5 哈希,可在 `contact` 接口里看到)
|
||||||
|
|
||||||
|
不确定时先调 `GET /api/v1/resolve?q=<输入>` 校验,返回 `{ md5, m_nsUsrName, m_nsNickName, type, ... }`。
|
||||||
|
|
||||||
|
### `chatroom` 与 `contact?type=group` 字段一致性
|
||||||
|
|
||||||
|
`/chatroom` 和 `/contact?type=group` 返回的是**同一个集合**(都是 `listContacts().filter(type==='group')`),字段也完全一致:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"m_nsUsrName": "49023470180@chatroom", // wxid, 用作 chatlog 的 talker
|
||||||
|
"m_nsNickName": { "buffer": "...", "type": "Buffer" }, // nickname 原 buffer
|
||||||
|
"type": "group",
|
||||||
|
"md5": "..."
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
需要 `displayName` 时从 `m_nsNickName` 里解析;需要拉消息就传 `m_nsUsrName` 当 talker。
|
||||||
|
|
||||||
|
## 时间范围格式(`time` 参数)
|
||||||
|
|
||||||
|
支持以下格式:
|
||||||
|
|
||||||
|
| 输入 | 含义 |
|
||||||
|
|------|------|
|
||||||
|
| `2026-07-03` | 单日 00:00:00 ~ 23:59:59 |
|
||||||
|
| `2026-07-01~2026-07-03` | 日期范围(闭区间) |
|
||||||
|
| `2026-07-03/14:30` | 单分钟(从 14:30:00 起 60 秒) |
|
||||||
|
| `2026-07-03/14:30~2026-07-03/15:30` | 精确到分钟的范围 |
|
||||||
|
|
||||||
|
也可以直接传 unix 秒级时间戳作为 `startTime` 和 `endTime`。
|
||||||
|
|
||||||
|
### "今天 / 昨天 / 本周" 的时区语义
|
||||||
|
|
||||||
|
所有 `time` / `startTime` / `endTime` 都按**用户本机时区**解析(由 `current_time` 里的 `timezone` 字段给出,典型为 `Asia/Shanghai`)。含义如下:
|
||||||
|
|
||||||
|
- "今天 2026-07-03" → 本机 2026-07-03 00:00:00 ~ 23:59:59(北京时间 24 小时),**不是** UTC 当天
|
||||||
|
- "昨天" → 本机昨天 0 点 ~ 23:59:59
|
||||||
|
- "本周" → 本周一 0 点 ~ 当前时刻(按本机时区所在周的周一)
|
||||||
|
|
||||||
|
跨时区时(如用户在国外):仍以本机时区为准,需要按 UTC 处理时显式传 unix 时间戳。
|
||||||
|
|
||||||
|
## 时间预检工作流(Time-Aware Workflow)
|
||||||
|
|
||||||
|
**重要**:只要用户请求中包含"今天"、"昨天"、"本周"、"刚才"等相对时间概念,**禁止**直接生成日期字符串。
|
||||||
|
|
||||||
|
**步骤 1**:先调用 `current_time` 工具获取本地 RFC3339 时间。
|
||||||
|
**步骤 2**:根据返回的时间计算对应的 `time` 参数。
|
||||||
|
**步骤 3**:用计算后的参数调 `chatlog`。
|
||||||
|
|
||||||
|
示例:
|
||||||
|
- 用户: "今天 摸鱼交流群 聊了啥?"
|
||||||
|
- AI: 先 `GET /api/v1/current_time` → 得到 `2026-07-03T14:30:00+08:00` → 计算 `time=2026-07-03` → `GET /api/v1/chatlog?talker=摸鱼交流群&time=2026-07-03`
|
||||||
|
|
||||||
|
## 多步上下文检索(强制)
|
||||||
|
|
||||||
|
当查询特定话题或特定发送者发言时,**必须**按以下流程操作:
|
||||||
|
|
||||||
|
1. **初步定位**:用 `contact` 或 `chatroom` 端点确定群聊 md5 / wxid
|
||||||
|
2. **粗查**:用 `chatlog` + 较宽时间范围找到相关消息时间点
|
||||||
|
3. **精查**:对每个关键时间点分别查前后 15-30 分钟(不带任何 keyword 过滤),用完整上下文分析
|
||||||
|
|
||||||
|
**禁止**:仅凭一次粗查结果直接回答用户。
|
||||||
|
|
||||||
|
## 生成群日报(POST /api/v1/report)
|
||||||
|
|
||||||
|
当用户希望输出**可视化群日报**(长图 PNG + HTML 邮件版)时,用这个端点。WechatExplorer 内置 `mobile_daily_report.html` 模板,渲染后会同时落盘 `htmlPath` 和 `pngPath`,并返回 `imageDataUrl` 可直接预览。
|
||||||
|
|
||||||
|
### 请求体(`GroupReportExportRequest`)
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"report": {
|
||||||
|
"overview": "一句话总览,20-80 字",
|
||||||
|
"topics": [
|
||||||
|
{
|
||||||
|
"title": "话题标题",
|
||||||
|
"timeRange": "10:00-12:30",
|
||||||
|
"heat": "高", // "高" | "中" | "低"
|
||||||
|
"participants": ["张三", "李四"],
|
||||||
|
"summary": "本话题讨论了什么",
|
||||||
|
"conclusion": "可选,达成的结论",
|
||||||
|
"keywords": ["关键词1", "关键词2"]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"resources": [
|
||||||
|
{ "title": "链接/文件标题", "description": "为什么重要", "sender": "张三" }
|
||||||
|
],
|
||||||
|
"importantMessages": [
|
||||||
|
{ "sender": "张三", "time": "10:23", "content": "原消息文本", "note": "为什么重要" }
|
||||||
|
],
|
||||||
|
"quotes": [
|
||||||
|
{
|
||||||
|
"messages": [{ "sender": "李四", "content": "原话1" }, { "sender": "王五", "content": "原话2" }],
|
||||||
|
"note": "为什么这些话值得引用"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"qa": [
|
||||||
|
{ "question": "Q", "answer": "A", "answerer": "解答人(可选)" }
|
||||||
|
],
|
||||||
|
"analytics": {
|
||||||
|
"topicHeat": [{ "topic": "话题1", "score": 9.5 }],
|
||||||
|
"activeTimeline": "10:00-12:00 为最活跃时段",
|
||||||
|
"topSpeakers": [{ "name": "张三", "count": 58 }]
|
||||||
|
},
|
||||||
|
"keywords": ["高频词1", "高频词2"]
|
||||||
|
},
|
||||||
|
"metadata": {
|
||||||
|
"groupName": "技术交流",
|
||||||
|
"reportDate": "2026-07-03",
|
||||||
|
"dateRange": "2026-07-03 全天",
|
||||||
|
"messageCount": 1234,
|
||||||
|
"activeUsers": 56,
|
||||||
|
"timeSpan": "00:00-23:59",
|
||||||
|
"generatedAt": "2026-07-03 22:00",
|
||||||
|
"recordNote": "本日报由 WechatExplorer 自动生成",
|
||||||
|
"footerNote": "底部附加说明",
|
||||||
|
"heroParticipants": ["张三", "李四"],
|
||||||
|
"avatars": {},
|
||||||
|
"talker": "技术交流",
|
||||||
|
"timeRange": "2026-07-03"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 响应(`GroupReportExportResult`)
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"htmlPath": "/Users/.../Desktop/技术交流_日报_2026-07-03.html",
|
||||||
|
"pngPath": "/Users/.../Desktop/技术交流_日报_2026-07-03.png",
|
||||||
|
"imageDataUrl": "data:image/png;base64,iVBORw0K..."
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
成功返回 200;失败返回 500 + `{ success: false, error: "..." }`。HTML 和 PNG 用 `mobile_daily_report.html` 模板渲染,长图宽度自适应移动端预览。
|
||||||
|
|
||||||
|
### 典型工作流
|
||||||
|
|
||||||
|
1. 调 `current_time` + `chatlog` 拉取当天/目标时间段消息
|
||||||
|
2. LLM 总结生成 `report` + `metadata`(直接走 AI 总结即可,无需自己造数据)
|
||||||
|
3. POST 到 `/api/v1/report` 拿到 `htmlPath` / `pngPath`,把文件路径告诉用户即可在 Finder 打开
|
||||||
|
4. **不要**自己拼 HTML/PNG,模板已内置,只需组织好 report/metadata 字段
|
||||||
|
|
||||||
|
### 必填字段与隐式约束(踩坑提示)
|
||||||
|
|
||||||
|
`metadata` 的以下字段**必填**,缺一返回 500:
|
||||||
|
|
||||||
|
- `groupName`、`reportDate`、`dateRange`、`generatedAt`
|
||||||
|
- `heroParticipants`:数组,模板会把每个名字当 key 去 `metadata.avatars[name]` 取头像图
|
||||||
|
- `avatars`:对象,**每个 `heroParticipants` 里的名字都必须有这个 key**(没有就传 `""`,**不要省略整段**),否则模板渲染会抛 `Cannot read properties of undefined (reading '<名字>')` 报 500
|
||||||
|
|
||||||
|
`report` 的以下字段**必须存在**(空就传 `[]`,**不能省略**),否则模板遍历时会抛 `Cannot read properties of undefined (reading 'map')` 报 500:
|
||||||
|
|
||||||
|
- `report.topics`(至少 1 个,完全没话题就改用纯文本总结,不要硬生成空日报)
|
||||||
|
- `report.resources`
|
||||||
|
- `report.importantMessages`
|
||||||
|
- `report.quotes`
|
||||||
|
- `report.qa`
|
||||||
|
- `report.analytics.topicHeat`
|
||||||
|
- `report.analytics.topSpeakers`(至少 1 个)
|
||||||
|
- `report.keywords`
|
||||||
|
|
||||||
|
最小安全示例:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"report": {
|
||||||
|
"overview": "...",
|
||||||
|
"topics": [],
|
||||||
|
"resources": [],
|
||||||
|
"importantMessages": [],
|
||||||
|
"quotes": [],
|
||||||
|
"qa": [],
|
||||||
|
"analytics": { "topicHeat": [], "activeTimeline": "", "topSpeakers": [] },
|
||||||
|
"keywords": []
|
||||||
|
},
|
||||||
|
"metadata": {
|
||||||
|
"groupName": "技术交流",
|
||||||
|
"reportDate": "2026-07-07",
|
||||||
|
"dateRange": "2026-07-07 全天",
|
||||||
|
"heroParticipants": ["张三", "李四"],
|
||||||
|
"avatars": { "张三": "", "李四": "" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
`report.importantMessages[].time` 用 `HH:mm` 格式(不要 ISO 时间戳);`report.analytics.topicHeat[].score` 数字 0-10。
|
||||||
|
|
||||||
|
### 4 个数字格子的内容必须紧凑(避免塌陷)
|
||||||
|
|
||||||
|
模板顶部的 4 个统计格(`消息数 / 活跃人数 / 时间跨度 / 主要话题`)宽度均分,内容过长会被截断或换行:
|
||||||
|
|
||||||
|
| 字段 | 推荐格式 | 反例(会撑爆格子) |
|
||||||
|
|------|---------|----------------|
|
||||||
|
| `metadata.messageCount` | 纯数字 `"1234"` | `"约 1.2k 条"` |
|
||||||
|
| `metadata.activeUsers` | 纯数字 `"56"` | `"大约 50 多人"` |
|
||||||
|
| `metadata.timeSpan` | **持续时长紧凑半角** `"1 h"` / `"30 min"` / `"2 d"` | `"1 小时"` / `"7 小时"` / `"1天3小时"` |
|
||||||
|
| `metadata.topicCount` 等 | 数字 / 短中文 | 长句子 |
|
||||||
|
|
||||||
|
`timeSpan` 是**首条到末条消息的持续时长**,不是时间区间。**单位用半角空格分隔**:
|
||||||
|
|
||||||
|
- `< 1 h` → `"30 min"`
|
||||||
|
- `1~24 h` → `"1 h"` / `"7 h"`(整数,向上取整)
|
||||||
|
- `> 24 h` → `"2 d"`(整数,向上取整)
|
||||||
|
|
||||||
|
**首末条消息的具体时间点**:`dateRange` 字段会显示完整日期 + 起止时间(无长度限制),模板里 dateRange 是 hero 区的副标题,跟 stat 格子分开。
|
||||||
|
|
||||||
|
**区间叙事**(如"主要集中在上午 10 点-12 点")放 `report.analytics.activeTimeline`,那是模板里单独一段的描述,不被 stat 格子限制。
|
||||||
|
|
||||||
|
**不传 timeSpan**:服务端会用空字符串渲染(stat 格会空),subagent 应当总是算好时长填进来,或者 renderer 端会自动算(见 renderer 源码)。
|
||||||
|
|
||||||
|
### 头像:服务端自动反推(推荐)
|
||||||
|
|
||||||
|
**v1.4 起无需手动拼 `avatars` 字典**。在 `metadata` 里加 `talker`(群昵称/wxid/md5 都行),服务端会用 `getGroupSnapshot` 拉全量群成员,按 `nickname → avatar` 自动反推填进 `metadata.avatars`。LLM 总结里出现的 `heroParticipants` / `topics[].participants` / `topSpeakers[].name` 等所有名字都会被覆盖。
|
||||||
|
|
||||||
|
**优先级**:客户端传的 `avatars[name]`(非空字符串) > 服务端反推 > 占位 SVG(姓名首字母 + 随机色块)。
|
||||||
|
|
||||||
|
**回退**:不传 `talker` 时按 `metadata.avatars` 字典取;还取不到则生成 SVG 占位(`fallbackAvatar`),**不会变空白方块**(v1.4 修了 data URL 正则,SVG 占位能正常嵌入)。
|
||||||
|
|
||||||
|
**手动覆盖**:仍可传 `avatars` 字典强制使用自定义头像,例如 `{"张三": "data:image/jpeg;base64,..."}`。
|
||||||
|
|
||||||
|
**P2 风险**:群里有两人同名(如"杨伟")时,服务端只取首条;客户端可手动覆盖。
|
||||||
|
|
||||||
|
## 隐私安全原则
|
||||||
|
|
||||||
|
1. **最小化原则**:只返回用户明确请求的内容,不过度展开无关聊天
|
||||||
|
2. **本地处理**:所有数据来自用户本机,API 不缓存、不转发
|
||||||
|
3. **摘要优先**:对于大量聊天记录,先提供摘要而非完整 dump
|
||||||
|
4. **用户确认**:涉及敏感内容时,先展示摘要,让用户决定是否继续深入
|
||||||
|
|
||||||
|
## 典型工作流示例
|
||||||
|
|
||||||
|
**示例 1:今日群聊总结(纯文本)**
|
||||||
|
1. `GET /api/v1/current_time` → 获取今天日期
|
||||||
|
2. `GET /api/v1/chatroom?keyword=技术交流` → 找到目标群 md5
|
||||||
|
3. `GET /api/v1/chatlog?talker=技术交流&time=2026-07-03` → 拉取今天的聊天
|
||||||
|
4. AI 用 LLM 生成总结报告(话题 TOP N、最活跃发言者等)
|
||||||
|
|
||||||
|
**示例 2:搜索特定消息上下文**
|
||||||
|
1. `GET /api/v1/chatlog?talker=摸鱼群&time=2026-07-01~2026-07-03` → 粗查近 3 天
|
||||||
|
2. 在返回的消息中定位关键词出现的时间点 T1, T2, ...
|
||||||
|
3. 对每个 Ti 分别查 `chatlog?talker=摸鱼群&time=Ti-15min~Ti+15min`,分析上下文
|
||||||
|
|
||||||
|
**示例 3:群日报(可视化长图)**
|
||||||
|
1. `GET /api/v1/chatlog?talker=技术交流&time=2026-07-03` → 拉今天聊天
|
||||||
|
2. LLM 按上方 `GroupDailyReport` schema 总结出 `report` + `metadata`
|
||||||
|
3. `POST /api/v1/report` body = 上述 JSON → 拿到 `htmlPath` / `pngPath` / `imageDataUrl`
|
||||||
|
4. 把 `imageDataUrl` 给用户预览,把 `pngPath` 路径告诉用户用 Finder 打开
|
||||||
|
|
||||||
|
## 错误处理
|
||||||
|
|
||||||
|
- `503` → WechatExplorer 未初始化(密钥未配置),提示用户在主窗口完成配置
|
||||||
|
- `404 talker not found` → talker 不存在,先调 `contact` 或 `resolve` 确认 md5/wxid
|
||||||
|
- `400 missing required parameter` → 检查必填参数(talker / md5 / q)
|
||||||
|
- `200` 但 `result.warnings: ['enrich skipped: talker "X" not found']` → `/report` 的 `metadata.talker` 解析失败,头像走 SVG fallback(不阻断生成)
|
||||||
|
- `200` 但 `result.warnings: ['enriched N member avatars from snapshot (M members)']` → enrich 成功(诊断用)
|
||||||
|
- `400 请求体为空 / 需包含 report 和 metadata` → 调用 `/report` 时 body 必须是非空 JSON,且有这两个顶层字段
|
||||||
|
- `500 success=false` → 模板渲染失败,通常因 `report` 字段缺失或 `metadata.groupName/reportDate` 为空,检查后重试
|
||||||
|
|
||||||
|
## 配置 Claude Desktop
|
||||||
|
|
||||||
|
把以下加入 `~/Library/Application Support/Claude/claude_desktop_config.json`:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"mcpServers": {
|
||||||
|
"wechatexplorer": {
|
||||||
|
"command": "npx",
|
||||||
|
"args": ["-y", "@wechatexplorer/mcp-bridge"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
(待 P3 实现 — MCP bridge 包,在此之前可直接用 `curl` 调用 HTTP API,或通过 mcp-remote 桥接。)
|
||||||
|
|
||||||
|
## 配置 Claude Code / Codex
|
||||||
|
|
||||||
|
在 `~/.claude/settings.json` 或项目级 `.claude/settings.local.json` 中:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"mcpServers": {
|
||||||
|
"wechatexplorer": {
|
||||||
|
"url": "http://127.0.0.1:6131"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
(视 MCP over HTTP 支持情况调整)
|
||||||
+14
-9
@@ -1,5 +1,6 @@
|
|||||||
appId: com.electron.app
|
appId: com.wechatexplorer.app
|
||||||
productName: wechatexplorer
|
productName: WechatExplorer
|
||||||
|
afterPack: scripts/after-pack.cjs
|
||||||
directories:
|
directories:
|
||||||
buildResources: build
|
buildResources: build
|
||||||
files:
|
files:
|
||||||
@@ -29,13 +30,17 @@ nsis:
|
|||||||
mac:
|
mac:
|
||||||
entitlementsInherit: build/entitlements.mac.plist
|
entitlementsInherit: build/entitlements.mac.plist
|
||||||
extendInfo:
|
extendInfo:
|
||||||
- NSCameraUsageDescription: Application requests access to the device's camera.
|
# The bundled WCDB bridge accepts Electron as its internal host name. The
|
||||||
- NSMicrophoneUsageDescription: Application requests access to the device's microphone.
|
# public app name and bundle identifier remain WechatExplorer-specific.
|
||||||
- NSDocumentsFolderUsageDescription: Application requests access to the user's Documents folder.
|
CFBundleName: Electron
|
||||||
- NSDownloadsFolderUsageDescription: Application requests access to the user's Downloads folder.
|
CFBundleDisplayName: WechatExplorer
|
||||||
|
NSCameraUsageDescription: Application requests access to the device's camera.
|
||||||
|
NSMicrophoneUsageDescription: Application requests access to the device's microphone.
|
||||||
|
NSDocumentsFolderUsageDescription: Application requests access to the user's Documents folder.
|
||||||
|
NSDownloadsFolderUsageDescription: Application requests access to the user's Downloads folder.
|
||||||
notarize: false
|
notarize: false
|
||||||
dmg:
|
dmg:
|
||||||
artifactName: ${name}-${version}.${ext}
|
artifactName: ${name}-${version}-${arch}.${ext}
|
||||||
linux:
|
linux:
|
||||||
target:
|
target:
|
||||||
- AppImage
|
- AppImage
|
||||||
@@ -47,5 +52,5 @@ appImage:
|
|||||||
artifactName: ${name}-${version}.${ext}
|
artifactName: ${name}-${version}.${ext}
|
||||||
npmRebuild: false
|
npmRebuild: false
|
||||||
publish:
|
publish:
|
||||||
provider: generic
|
provider: github
|
||||||
url: https://example.com/auto-updates
|
releaseType: draft
|
||||||
|
|||||||
+7
-17
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "wechatexplorer",
|
"name": "wechatexplorer",
|
||||||
"version": "1.1.0",
|
"version": "2.0.1",
|
||||||
"description": "mac 版本获取微信聊天记录, AI群聊总结助手",
|
"description": "mac 版本获取微信聊天记录, AI群聊总结助手",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"wechat",
|
"wechat",
|
||||||
@@ -21,17 +21,16 @@
|
|||||||
"dev": "electron-vite dev",
|
"dev": "electron-vite dev",
|
||||||
"build": "npm run typecheck && electron-vite build",
|
"build": "npm run typecheck && electron-vite build",
|
||||||
"postinstall": "electron-builder install-app-deps",
|
"postinstall": "electron-builder install-app-deps",
|
||||||
"build:unpack": "npm run build && electron-builder --dir",
|
"build:unpack": "npm run build && electron-builder --config electron-builder.yml --dir",
|
||||||
"build:win": "npm run build && electron-builder --win",
|
"build:win": "npm run build && electron-builder --config electron-builder.yml --win",
|
||||||
"build:mac:x64": "electron-vite build && electron-builder --mac --x64",
|
"build:mac:x64": "electron-vite build && electron-builder --config electron-builder.yml --mac --x64",
|
||||||
"build:mac:arm64": "electron-vite build && electron-builder --mac --arm64",
|
"build:mac:arm64": "electron-vite build && electron-builder --config electron-builder.yml --mac --arm64",
|
||||||
"release:mac": "electron-vite build && electron-builder --mac --x64 --arm64 --publish always",
|
"release:mac": "electron-vite build && electron-builder --config electron-builder.yml --mac --x64 --arm64 --publish always",
|
||||||
"build:linux": "electron-vite build && electron-builder --linux"
|
"build:linux": "electron-vite build && electron-builder --config electron-builder.yml --linux"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@electron-toolkit/preload": "^3.0.2",
|
"@electron-toolkit/preload": "^3.0.2",
|
||||||
"@electron-toolkit/utils": "^4.0.0",
|
"@electron-toolkit/utils": "^4.0.0",
|
||||||
"better-sqlite3-multiple-ciphers": "^12.5.0",
|
|
||||||
"fs-extra": "^11.3.2",
|
"fs-extra": "^11.3.2",
|
||||||
"fzstd": "^0.1.1",
|
"fzstd": "^0.1.1",
|
||||||
"koffi": "^2.9.0",
|
"koffi": "^2.9.0",
|
||||||
@@ -66,14 +65,5 @@
|
|||||||
"electron",
|
"electron",
|
||||||
"esbuild"
|
"esbuild"
|
||||||
]
|
]
|
||||||
},
|
|
||||||
"build": {
|
|
||||||
"artifactName": "${productName}-${version}-${os}-${arch}.${ext}",
|
|
||||||
"mac": {
|
|
||||||
"target": [
|
|
||||||
"dmg",
|
|
||||||
"zip"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+12
-126
@@ -16,7 +16,6 @@ specifiers:
|
|||||||
'@types/react': ^19.2.7
|
'@types/react': ^19.2.7
|
||||||
'@types/react-dom': ^19.2.3
|
'@types/react-dom': ^19.2.3
|
||||||
'@vitejs/plugin-react': ^5.1.1
|
'@vitejs/plugin-react': ^5.1.1
|
||||||
better-sqlite3-multiple-ciphers: ^12.5.0
|
|
||||||
electron: ^39.2.6
|
electron: ^39.2.6
|
||||||
electron-builder: ^26.0.12
|
electron-builder: ^26.0.12
|
||||||
electron-vite: ^5.0.0
|
electron-vite: ^5.0.0
|
||||||
@@ -38,7 +37,6 @@ specifiers:
|
|||||||
dependencies:
|
dependencies:
|
||||||
'@electron-toolkit/preload': 3.0.2_electron@39.2.6
|
'@electron-toolkit/preload': 3.0.2_electron@39.2.6
|
||||||
'@electron-toolkit/utils': 4.0.0_electron@39.2.6
|
'@electron-toolkit/utils': 4.0.0_electron@39.2.6
|
||||||
better-sqlite3-multiple-ciphers: 12.5.0
|
|
||||||
fs-extra: 11.3.2
|
fs-extra: 11.3.2
|
||||||
fzstd: 0.1.1
|
fzstd: 0.1.1
|
||||||
koffi: 2.16.2
|
koffi: 2.16.2
|
||||||
@@ -1578,32 +1576,20 @@ packages:
|
|||||||
|
|
||||||
/base64-js/1.5.1:
|
/base64-js/1.5.1:
|
||||||
resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==}
|
resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==}
|
||||||
|
dev: true
|
||||||
|
|
||||||
/baseline-browser-mapping/2.9.5:
|
/baseline-browser-mapping/2.9.5:
|
||||||
resolution: {integrity: sha512-D5vIoztZOq1XM54LUdttJVc96ggEsIfju2JBvht06pSzpckp3C7HReun67Bghzrtdsq9XdMGbSSB3v3GhMNmAA==}
|
resolution: {integrity: sha512-D5vIoztZOq1XM54LUdttJVc96ggEsIfju2JBvht06pSzpckp3C7HReun67Bghzrtdsq9XdMGbSSB3v3GhMNmAA==}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/better-sqlite3-multiple-ciphers/12.5.0:
|
|
||||||
resolution: {integrity: sha512-bYbiV0TdCIQFqlI122+wIFnc3yXWHyz8A/026Y/YfiA3vKcC0wLnHqqociNehpFmbRSowuY3Ko8SyUhBXI9+4A==}
|
|
||||||
engines: {node: 20.x || 22.x || 23.x || 24.x}
|
|
||||||
dependencies:
|
|
||||||
bindings: 1.5.0
|
|
||||||
prebuild-install: 7.1.3
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/bindings/1.5.0:
|
|
||||||
resolution: {integrity: sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==}
|
|
||||||
dependencies:
|
|
||||||
file-uri-to-path: 1.0.0
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/bl/4.1.0:
|
/bl/4.1.0:
|
||||||
resolution: {integrity: sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==}
|
resolution: {integrity: sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==}
|
||||||
dependencies:
|
dependencies:
|
||||||
buffer: 5.7.1
|
buffer: 5.7.1
|
||||||
inherits: 2.0.4
|
inherits: 2.0.4
|
||||||
readable-stream: 3.6.2
|
readable-stream: 3.6.2
|
||||||
|
dev: true
|
||||||
|
|
||||||
/boolean/3.2.0:
|
/boolean/3.2.0:
|
||||||
resolution: {integrity: sha512-d0II/GO9uf9lfUHH2BQsjxzRJZBdsjgsBiW4BvhWk/3qoKwQFjIDVN19PfX8F2D/r9PCMTtLWjYVCFrpeYUzsw==}
|
resolution: {integrity: sha512-d0II/GO9uf9lfUHH2BQsjxzRJZBdsjgsBiW4BvhWk/3qoKwQFjIDVN19PfX8F2D/r9PCMTtLWjYVCFrpeYUzsw==}
|
||||||
@@ -1647,6 +1633,7 @@ packages:
|
|||||||
dependencies:
|
dependencies:
|
||||||
base64-js: 1.5.1
|
base64-js: 1.5.1
|
||||||
ieee754: 1.2.1
|
ieee754: 1.2.1
|
||||||
|
dev: true
|
||||||
|
|
||||||
/builder-util-runtime/9.3.1:
|
/builder-util-runtime/9.3.1:
|
||||||
resolution: {integrity: sha512-2/egrNDDnRaxVwK3A+cJq6UOlqOdedGA7JPqCeJjN2Zjk1/QB/6QUi3b714ScIGS7HafFXTyzJEOr5b44I3kvQ==}
|
resolution: {integrity: sha512-2/egrNDDnRaxVwK3A+cJq6UOlqOdedGA7JPqCeJjN2Zjk1/QB/6QUi3b714ScIGS7HafFXTyzJEOr5b44I3kvQ==}
|
||||||
@@ -1772,10 +1759,6 @@ packages:
|
|||||||
supports-color: 7.2.0
|
supports-color: 7.2.0
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/chownr/1.1.4:
|
|
||||||
resolution: {integrity: sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg==}
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/chownr/2.0.0:
|
/chownr/2.0.0:
|
||||||
resolution: {integrity: sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==}
|
resolution: {integrity: sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==}
|
||||||
engines: {node: '>=10'}
|
engines: {node: '>=10'}
|
||||||
@@ -1947,11 +1930,6 @@ packages:
|
|||||||
dependencies:
|
dependencies:
|
||||||
mimic-response: 3.1.0
|
mimic-response: 3.1.0
|
||||||
|
|
||||||
/deep-extend/0.6.0:
|
|
||||||
resolution: {integrity: sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==}
|
|
||||||
engines: {node: '>=4.0.0'}
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/deep-is/0.1.4:
|
/deep-is/0.1.4:
|
||||||
resolution: {integrity: sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==}
|
resolution: {integrity: sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==}
|
||||||
dev: true
|
dev: true
|
||||||
@@ -1990,6 +1968,7 @@ packages:
|
|||||||
/detect-libc/2.1.2:
|
/detect-libc/2.1.2:
|
||||||
resolution: {integrity: sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==}
|
resolution: {integrity: sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==}
|
||||||
engines: {node: '>=8'}
|
engines: {node: '>=8'}
|
||||||
|
dev: true
|
||||||
|
|
||||||
/detect-node/2.1.0:
|
/detect-node/2.1.0:
|
||||||
resolution: {integrity: sha512-T0NIuQpnTvFDATNuHN5roPwSBG83rFsuO+MXXH9/3N1eFbn4wcPjttvjMLEPWJ0RGUYgQE7cGgS3tNxbqCGM7g==}
|
resolution: {integrity: sha512-T0NIuQpnTvFDATNuHN5roPwSBG83rFsuO+MXXH9/3N1eFbn4wcPjttvjMLEPWJ0RGUYgQE7cGgS3tNxbqCGM7g==}
|
||||||
@@ -2528,11 +2507,6 @@ packages:
|
|||||||
engines: {node: '>=0.10.0'}
|
engines: {node: '>=0.10.0'}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/expand-template/2.0.3:
|
|
||||||
resolution: {integrity: sha512-XYfuKMvj4O35f/pOXLObndIRvyQ+/+6AhODh+OKWj9S9498pHHn/IMszH+gt0fBCRWMNfk1ZSp5x3AifmnI2vg==}
|
|
||||||
engines: {node: '>=6'}
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/exponential-backoff/3.1.3:
|
/exponential-backoff/3.1.3:
|
||||||
resolution: {integrity: sha512-ZgEeZXj30q+I0EN+CbSSpIyPaJ5HVQD18Z1m+u1FXbAeT94mr1zw50q4q6jiiC447Nl/YTcIYSAftiGqetwXCA==}
|
resolution: {integrity: sha512-ZgEeZXj30q+I0EN+CbSSpIyPaJ5HVQD18Z1m+u1FXbAeT94mr1zw50q4q6jiiC447Nl/YTcIYSAftiGqetwXCA==}
|
||||||
dev: true
|
dev: true
|
||||||
@@ -2596,10 +2570,6 @@ packages:
|
|||||||
flat-cache: 4.0.1
|
flat-cache: 4.0.1
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/file-uri-to-path/1.0.0:
|
|
||||||
resolution: {integrity: sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==}
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/filelist/1.0.4:
|
/filelist/1.0.4:
|
||||||
resolution: {integrity: sha512-w1cEuf3S+DrLCQL7ET6kz+gmlJdbq9J7yXCSjK/OZCPA+qEN1WyF4ZAf0YYJa4/shHJra2t/d/r8SV4Ji+x+8Q==}
|
resolution: {integrity: sha512-w1cEuf3S+DrLCQL7ET6kz+gmlJdbq9J7yXCSjK/OZCPA+qEN1WyF4ZAf0YYJa4/shHJra2t/d/r8SV4Ji+x+8Q==}
|
||||||
dependencies:
|
dependencies:
|
||||||
@@ -2652,10 +2622,6 @@ packages:
|
|||||||
mime-types: 2.1.35
|
mime-types: 2.1.35
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/fs-constants/1.0.0:
|
|
||||||
resolution: {integrity: sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==}
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/fs-extra/10.1.0:
|
/fs-extra/10.1.0:
|
||||||
resolution: {integrity: sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==}
|
resolution: {integrity: sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==}
|
||||||
engines: {node: '>=12'}
|
engines: {node: '>=12'}
|
||||||
@@ -2787,10 +2753,6 @@ packages:
|
|||||||
get-intrinsic: 1.3.0
|
get-intrinsic: 1.3.0
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/github-from-package/0.0.0:
|
|
||||||
resolution: {integrity: sha512-SyHy3T1v2NUXn29OsWdxmK6RwHD+vkj3v8en8AOBZ1wBQ/hCAQ5bAQTD02kW4W9tUp/3Qh6J8r9EvntiyCmOOw==}
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/glob-parent/6.0.2:
|
/glob-parent/6.0.2:
|
||||||
resolution: {integrity: sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==}
|
resolution: {integrity: sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==}
|
||||||
engines: {node: '>=10.13.0'}
|
engines: {node: '>=10.13.0'}
|
||||||
@@ -3020,6 +2982,7 @@ packages:
|
|||||||
|
|
||||||
/ieee754/1.2.1:
|
/ieee754/1.2.1:
|
||||||
resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==}
|
resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==}
|
||||||
|
dev: true
|
||||||
|
|
||||||
/ignore/5.3.2:
|
/ignore/5.3.2:
|
||||||
resolution: {integrity: sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==}
|
resolution: {integrity: sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==}
|
||||||
@@ -3063,10 +3026,7 @@ packages:
|
|||||||
|
|
||||||
/inherits/2.0.4:
|
/inherits/2.0.4:
|
||||||
resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==}
|
resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==}
|
||||||
|
dev: true
|
||||||
/ini/1.3.8:
|
|
||||||
resolution: {integrity: sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==}
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/internal-slot/1.1.0:
|
/internal-slot/1.1.0:
|
||||||
resolution: {integrity: sha512-4gd7VpWNQNB4UKKCFFVcp1AVv+FMOgs9NKzjHKusc8jTMhd5eL1NqQqOpE0KzMds804/yHlglp3uxgluOqAPLw==}
|
resolution: {integrity: sha512-4gd7VpWNQNB4UKKCFFVcp1AVv+FMOgs9NKzjHKusc8jTMhd5eL1NqQqOpE0KzMds804/yHlglp3uxgluOqAPLw==}
|
||||||
@@ -3574,6 +3534,7 @@ packages:
|
|||||||
|
|
||||||
/minimist/1.2.8:
|
/minimist/1.2.8:
|
||||||
resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==}
|
resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==}
|
||||||
|
dev: true
|
||||||
|
|
||||||
/minipass-collect/1.0.2:
|
/minipass-collect/1.0.2:
|
||||||
resolution: {integrity: sha512-6T6lH0H8OG9kITm/Jm6tdooIbogG9e0tLgpY6mphXSm/A9u8Nq1ryBG+Qspiub9LjWlBPsPS3tWQ/Botq4FdxA==}
|
resolution: {integrity: sha512-6T6lH0H8OG9kITm/Jm6tdooIbogG9e0tLgpY6mphXSm/A9u8Nq1ryBG+Qspiub9LjWlBPsPS3tWQ/Botq4FdxA==}
|
||||||
@@ -3639,10 +3600,6 @@ packages:
|
|||||||
yallist: 4.0.0
|
yallist: 4.0.0
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/mkdirp-classic/0.5.3:
|
|
||||||
resolution: {integrity: sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==}
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/mkdirp/1.0.4:
|
/mkdirp/1.0.4:
|
||||||
resolution: {integrity: sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==}
|
resolution: {integrity: sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==}
|
||||||
engines: {node: '>=10'}
|
engines: {node: '>=10'}
|
||||||
@@ -3658,10 +3615,6 @@ packages:
|
|||||||
hasBin: true
|
hasBin: true
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/napi-build-utils/2.0.0:
|
|
||||||
resolution: {integrity: sha512-GEbrYkbfF7MoNaoh2iGG84Mnf/WZfB0GdGEsM8wz7Expx/LlWf5U8t9nvJKXSp3qr5IsEbK04cBGhol/KwOsWA==}
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/natural-compare/1.4.0:
|
/natural-compare/1.4.0:
|
||||||
resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==}
|
resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==}
|
||||||
dev: true
|
dev: true
|
||||||
@@ -3676,6 +3629,7 @@ packages:
|
|||||||
engines: {node: '>=10'}
|
engines: {node: '>=10'}
|
||||||
dependencies:
|
dependencies:
|
||||||
semver: 7.7.3
|
semver: 7.7.3
|
||||||
|
dev: true
|
||||||
|
|
||||||
/node-addon-api/1.7.2:
|
/node-addon-api/1.7.2:
|
||||||
resolution: {integrity: sha512-ibPK3iA+vaY1eEjESkQkM0BbCqFOaZMiXRTtdB0u7b4djtY6JnsjvPdUHVMg6xQt3B8fpTTWHI9A+ADjM9frzg==}
|
resolution: {integrity: sha512-ibPK3iA+vaY1eEjESkQkM0BbCqFOaZMiXRTtdB0u7b4djtY6JnsjvPdUHVMg6xQt3B8fpTTWHI9A+ADjM9frzg==}
|
||||||
@@ -3924,25 +3878,6 @@ packages:
|
|||||||
source-map-js: 1.2.1
|
source-map-js: 1.2.1
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/prebuild-install/7.1.3:
|
|
||||||
resolution: {integrity: sha512-8Mf2cbV7x1cXPUILADGI3wuhfqWvtiLA1iclTDbFRZkgRQS0NqsPZphna9V+HyTEadheuPmjaJMsbzKQFOzLug==}
|
|
||||||
engines: {node: '>=10'}
|
|
||||||
hasBin: true
|
|
||||||
dependencies:
|
|
||||||
detect-libc: 2.1.2
|
|
||||||
expand-template: 2.0.3
|
|
||||||
github-from-package: 0.0.0
|
|
||||||
minimist: 1.2.8
|
|
||||||
mkdirp-classic: 0.5.3
|
|
||||||
napi-build-utils: 2.0.0
|
|
||||||
node-abi: 3.85.0
|
|
||||||
pump: 3.0.3
|
|
||||||
rc: 1.2.8
|
|
||||||
simple-get: 4.0.1
|
|
||||||
tar-fs: 2.1.4
|
|
||||||
tunnel-agent: 0.6.0
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/prelude-ls/1.2.1:
|
/prelude-ls/1.2.1:
|
||||||
resolution: {integrity: sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==}
|
resolution: {integrity: sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==}
|
||||||
engines: {node: '>= 0.8.0'}
|
engines: {node: '>= 0.8.0'}
|
||||||
@@ -4010,16 +3945,6 @@ packages:
|
|||||||
resolution: {integrity: sha512-WuyALRjWPDGtt/wzJiadO5AXY+8hZ80hVpe6MyivgraREW751X3SbhRvG3eLKOYN+8VEvqLcf3wdnt44Z4S4SA==}
|
resolution: {integrity: sha512-WuyALRjWPDGtt/wzJiadO5AXY+8hZ80hVpe6MyivgraREW751X3SbhRvG3eLKOYN+8VEvqLcf3wdnt44Z4S4SA==}
|
||||||
engines: {node: '>=10'}
|
engines: {node: '>=10'}
|
||||||
|
|
||||||
/rc/1.2.8:
|
|
||||||
resolution: {integrity: sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==}
|
|
||||||
hasBin: true
|
|
||||||
dependencies:
|
|
||||||
deep-extend: 0.6.0
|
|
||||||
ini: 1.3.8
|
|
||||||
minimist: 1.2.8
|
|
||||||
strip-json-comments: 2.0.1
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/react-dom/19.2.1_react@19.2.1:
|
/react-dom/19.2.1_react@19.2.1:
|
||||||
resolution: {integrity: sha512-ibrK8llX2a4eOskq1mXKu/TGZj9qzomO+sNfO98M6d9zIPOEhlBkMkBUBLd1vgS0gQsLDBzA+8jJBVXDnfHmJg==}
|
resolution: {integrity: sha512-ibrK8llX2a4eOskq1mXKu/TGZj9qzomO+sNfO98M6d9zIPOEhlBkMkBUBLd1vgS0gQsLDBzA+8jJBVXDnfHmJg==}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
@@ -4059,6 +3984,7 @@ packages:
|
|||||||
inherits: 2.0.4
|
inherits: 2.0.4
|
||||||
string_decoder: 1.3.0
|
string_decoder: 1.3.0
|
||||||
util-deprecate: 1.0.2
|
util-deprecate: 1.0.2
|
||||||
|
dev: true
|
||||||
|
|
||||||
/reflect.getprototypeof/1.0.10:
|
/reflect.getprototypeof/1.0.10:
|
||||||
resolution: {integrity: sha512-00o4I+DVrefhv+nX0ulyi3biSHCPDe+yLv5o/p6d/UVlirijB8E16FtfwSAi4g3tcqrQ4lRAqQSoFEZJehYEcw==}
|
resolution: {integrity: sha512-00o4I+DVrefhv+nX0ulyi3biSHCPDe+yLv5o/p6d/UVlirijB8E16FtfwSAi4g3tcqrQ4lRAqQSoFEZJehYEcw==}
|
||||||
@@ -4198,6 +4124,7 @@ packages:
|
|||||||
|
|
||||||
/safe-buffer/5.2.1:
|
/safe-buffer/5.2.1:
|
||||||
resolution: {integrity: sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==}
|
resolution: {integrity: sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==}
|
||||||
|
dev: true
|
||||||
|
|
||||||
/safe-push-apply/1.0.0:
|
/safe-push-apply/1.0.0:
|
||||||
resolution: {integrity: sha512-iKE9w/Z7xCzUMIZqdBsp6pEQvwuEebH4vdpjcDWnyzaI6yl6O9FHvVpmGelvEHNsoY6wGblkxR6Zty/h00WiSA==}
|
resolution: {integrity: sha512-iKE9w/Z7xCzUMIZqdBsp6pEQvwuEebH4vdpjcDWnyzaI6yl6O9FHvVpmGelvEHNsoY6wGblkxR6Zty/h00WiSA==}
|
||||||
@@ -4356,18 +4283,6 @@ packages:
|
|||||||
engines: {node: '>=16.11.0'}
|
engines: {node: '>=16.11.0'}
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/simple-concat/1.0.1:
|
|
||||||
resolution: {integrity: sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q==}
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/simple-get/4.0.1:
|
|
||||||
resolution: {integrity: sha512-brv7p5WgH0jmQJr1ZDDfKDOSeWWg+OVypG99A/5vYGPqJ6pxiaHLy8nxtFjBA7oMa01ebA9gfh1uMCFqOuXxvA==}
|
|
||||||
dependencies:
|
|
||||||
decompress-response: 6.0.0
|
|
||||||
once: 1.4.0
|
|
||||||
simple-concat: 1.0.1
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/simple-update-notifier/2.0.0:
|
/simple-update-notifier/2.0.0:
|
||||||
resolution: {integrity: sha512-a2B9Y0KlNXl9u/vsW6sTIu9vGEpfKu2wRV6l1H3XEas/0gUIzGzBoP/IouTcUQbm9JWZLH3COxyn03TYlFax6w==}
|
resolution: {integrity: sha512-a2B9Y0KlNXl9u/vsW6sTIu9vGEpfKu2wRV6l1H3XEas/0gUIzGzBoP/IouTcUQbm9JWZLH3COxyn03TYlFax6w==}
|
||||||
engines: {node: '>=10'}
|
engines: {node: '>=10'}
|
||||||
@@ -4530,6 +4445,7 @@ packages:
|
|||||||
resolution: {integrity: sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==}
|
resolution: {integrity: sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==}
|
||||||
dependencies:
|
dependencies:
|
||||||
safe-buffer: 5.2.1
|
safe-buffer: 5.2.1
|
||||||
|
dev: true
|
||||||
|
|
||||||
/strip-ansi/6.0.1:
|
/strip-ansi/6.0.1:
|
||||||
resolution: {integrity: sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==}
|
resolution: {integrity: sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==}
|
||||||
@@ -4545,11 +4461,6 @@ packages:
|
|||||||
ansi-regex: 6.2.2
|
ansi-regex: 6.2.2
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/strip-json-comments/2.0.1:
|
|
||||||
resolution: {integrity: sha512-4gB8na07fecVVkOI6Rs4e7T6NOTki5EmL7TUduTs6bu3EdnSycntVJ4re8kgZA+wx9IueI2Y11bfbgwtzuE0KQ==}
|
|
||||||
engines: {node: '>=0.10.0'}
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/strip-json-comments/3.1.1:
|
/strip-json-comments/3.1.1:
|
||||||
resolution: {integrity: sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==}
|
resolution: {integrity: sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==}
|
||||||
engines: {node: '>=8'}
|
engines: {node: '>=8'}
|
||||||
@@ -4582,26 +4493,6 @@ packages:
|
|||||||
'@pkgr/core': 0.2.9
|
'@pkgr/core': 0.2.9
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/tar-fs/2.1.4:
|
|
||||||
resolution: {integrity: sha512-mDAjwmZdh7LTT6pNleZ05Yt65HC3E+NiQzl672vQG38jIrehtJk/J3mNwIg+vShQPcLF/LV7CMnDW6vjj6sfYQ==}
|
|
||||||
dependencies:
|
|
||||||
chownr: 1.1.4
|
|
||||||
mkdirp-classic: 0.5.3
|
|
||||||
pump: 3.0.3
|
|
||||||
tar-stream: 2.2.0
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/tar-stream/2.2.0:
|
|
||||||
resolution: {integrity: sha512-ujeqbceABgwMZxEJnk2HDY2DlnUZ+9oEcb1KzTVfYHio0UE6dG71n60d8D2I4qNvleWrrXpmjpt7vZeF1LnMZQ==}
|
|
||||||
engines: {node: '>=6'}
|
|
||||||
dependencies:
|
|
||||||
bl: 4.1.0
|
|
||||||
end-of-stream: 1.4.5
|
|
||||||
fs-constants: 1.0.0
|
|
||||||
inherits: 2.0.4
|
|
||||||
readable-stream: 3.6.2
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/tar/6.2.1:
|
/tar/6.2.1:
|
||||||
resolution: {integrity: sha512-DZ4yORTwrbTj/7MZYq2w+/ZFdI6OZ/f9SFHR+71gIVUZhOQPHzVCLpvRnPgyaMpfWxxk/4ONva3GQSyNIKRv6A==}
|
resolution: {integrity: sha512-DZ4yORTwrbTj/7MZYq2w+/ZFdI6OZ/f9SFHR+71gIVUZhOQPHzVCLpvRnPgyaMpfWxxk/4ONva3GQSyNIKRv6A==}
|
||||||
engines: {node: '>=10'}
|
engines: {node: '>=10'}
|
||||||
@@ -4661,12 +4552,6 @@ packages:
|
|||||||
typescript: 5.9.3
|
typescript: 5.9.3
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/tunnel-agent/0.6.0:
|
|
||||||
resolution: {integrity: sha512-McnNiV1l8RYeY8tBgEpuodCC1mLUdbSN+CYBL7kJsJNInOP8UjDDEwdk6Mw60vdLLrr5NHKZhMAOSrR2NZuQ+w==}
|
|
||||||
dependencies:
|
|
||||||
safe-buffer: 5.2.1
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/type-check/0.4.0:
|
/type-check/0.4.0:
|
||||||
resolution: {integrity: sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==}
|
resolution: {integrity: sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==}
|
||||||
engines: {node: '>= 0.8.0'}
|
engines: {node: '>= 0.8.0'}
|
||||||
@@ -4805,6 +4690,7 @@ packages:
|
|||||||
|
|
||||||
/util-deprecate/1.0.2:
|
/util-deprecate/1.0.2:
|
||||||
resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==}
|
resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==}
|
||||||
|
dev: true
|
||||||
|
|
||||||
/verror/1.10.1:
|
/verror/1.10.1:
|
||||||
resolution: {integrity: sha512-veufcmxri4e3XSrT0xwfUR7kguIkaxBeosDg00yDWhk49wdwkSUrvvsm7nc75e1PUyvIeZj6nS8VQRYz2/S4Xg==}
|
resolution: {integrity: sha512-veufcmxri4e3XSrT0xwfUR7kguIkaxBeosDg00yDWhk49wdwkSUrvvsm7nc75e1PUyvIeZj6nS8VQRYz2/S4Xg==}
|
||||||
|
|||||||
@@ -44,6 +44,11 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
gap: 14px;
|
gap: 14px;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
.hero-top > div:first-child {
|
||||||
|
min-width: 0;
|
||||||
|
flex: 1 1 auto;
|
||||||
}
|
}
|
||||||
.hero h1 {
|
.hero h1 {
|
||||||
font-size: 23px;
|
font-size: 23px;
|
||||||
@@ -82,11 +87,15 @@
|
|||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
padding: 10px 6px;
|
padding: 10px 6px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
min-width: 0;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
.stat b {
|
.stat b {
|
||||||
display: block;
|
display: block;
|
||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
color: #07a352;
|
color: #07a352;
|
||||||
|
white-space: nowrap;
|
||||||
|
line-height: 1.25;
|
||||||
}
|
}
|
||||||
.stat span {
|
.stat span {
|
||||||
font-size: 11px;
|
font-size: 11px;
|
||||||
@@ -420,7 +429,7 @@
|
|||||||
<div class="stats">
|
<div class="stats">
|
||||||
<div class="stat"><b>{{MESSAGE_COUNT}}</b><span>消息数</span></div>
|
<div class="stat"><b>{{MESSAGE_COUNT}}</b><span>消息数</span></div>
|
||||||
<div class="stat"><b>{{ACTIVE_USERS}}</b><span>活跃人数</span></div>
|
<div class="stat"><b>{{ACTIVE_USERS}}</b><span>活跃人数</span></div>
|
||||||
<div class="stat"><b>{{TIME_SPAN}}</b><span>时间跨度</span></div>
|
<div class="stat"><b>{{TIME_SPAN}}</b><span>持续时长</span></div>
|
||||||
<div class="stat"><b>{{TOPIC_COUNT}}</b><span>主要话题</span></div>
|
<div class="stat"><b>{{TOPIC_COUNT}}</b><span>主要话题</span></div>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
const { existsSync, renameSync } = require('node:fs')
|
||||||
|
const { execFileSync } = require('node:child_process')
|
||||||
|
const path = require('node:path')
|
||||||
|
|
||||||
|
const COMPATIBILITY_NAME = 'Electron'
|
||||||
|
const HELPER_SUFFIXES = ['', ' (Plugin)', ' (Renderer)', ' (GPU)']
|
||||||
|
|
||||||
|
function setPlistValue(plistPath, key, value) {
|
||||||
|
execFileSync('/usr/libexec/PlistBuddy', ['-c', `Set :${key} ${value}`, plistPath])
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.default = async function afterPack(context) {
|
||||||
|
if (context.electronPlatformName !== 'darwin') return
|
||||||
|
|
||||||
|
const productName = context.packager.appInfo.productFilename
|
||||||
|
const appPath = path.join(context.appOutDir, `${productName}.app`)
|
||||||
|
const contentsPath = path.join(appPath, 'Contents')
|
||||||
|
const sourceExecutable = path.join(contentsPath, 'MacOS', productName)
|
||||||
|
const targetExecutable = path.join(contentsPath, 'MacOS', COMPATIBILITY_NAME)
|
||||||
|
|
||||||
|
if (existsSync(sourceExecutable)) renameSync(sourceExecutable, targetExecutable)
|
||||||
|
if (!existsSync(targetExecutable)) {
|
||||||
|
throw new Error(`Missing Electron main executable: ${sourceExecutable}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const appPlistPath = path.join(contentsPath, 'Info.plist')
|
||||||
|
setPlistValue(appPlistPath, 'CFBundleExecutable', COMPATIBILITY_NAME)
|
||||||
|
setPlistValue(appPlistPath, 'CFBundleName', COMPATIBILITY_NAME)
|
||||||
|
|
||||||
|
const frameworksPath = path.join(contentsPath, 'Frameworks')
|
||||||
|
|
||||||
|
for (const suffix of HELPER_SUFFIXES) {
|
||||||
|
const sourceName = `${productName} Helper${suffix}`
|
||||||
|
const targetName = `${COMPATIBILITY_NAME} Helper${suffix}`
|
||||||
|
const sourceBundle = path.join(frameworksPath, `${sourceName}.app`)
|
||||||
|
const targetBundle = path.join(frameworksPath, `${targetName}.app`)
|
||||||
|
|
||||||
|
if (existsSync(sourceBundle)) renameSync(sourceBundle, targetBundle)
|
||||||
|
if (!existsSync(targetBundle)) {
|
||||||
|
throw new Error(`Missing Electron helper bundle: ${sourceBundle}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const sourceExecutable = path.join(targetBundle, 'Contents', 'MacOS', sourceName)
|
||||||
|
const targetExecutable = path.join(targetBundle, 'Contents', 'MacOS', targetName)
|
||||||
|
if (existsSync(sourceExecutable)) renameSync(sourceExecutable, targetExecutable)
|
||||||
|
if (!existsSync(targetExecutable)) {
|
||||||
|
throw new Error(`Missing Electron helper executable: ${sourceExecutable}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const plistPath = path.join(targetBundle, 'Contents', 'Info.plist')
|
||||||
|
setPlistValue(plistPath, 'CFBundleExecutable', targetName)
|
||||||
|
setPlistValue(plistPath, 'CFBundleName', targetName)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,8 +5,10 @@ import path from 'path'
|
|||||||
import {
|
import {
|
||||||
GroupReportExportRequest,
|
GroupReportExportRequest,
|
||||||
GroupReportExportResult,
|
GroupReportExportResult,
|
||||||
|
GroupReportMetadata,
|
||||||
ReportHeat
|
ReportHeat
|
||||||
} from '../shared/group-report'
|
} from '../shared/group-report'
|
||||||
|
import { resolveMd5, getGroupSnapshot } from './services/chat-service'
|
||||||
|
|
||||||
const TEMPLATE_NAME = 'mobile_daily_report.html'
|
const TEMPLATE_NAME = 'mobile_daily_report.html'
|
||||||
|
|
||||||
@@ -48,7 +50,7 @@ const imageMimeType = (contentType: string | null, source: string): string => {
|
|||||||
|
|
||||||
const embedAvatar = async (source: string | undefined, name: string): Promise<string> => {
|
const embedAvatar = async (source: string | undefined, name: string): Promise<string> => {
|
||||||
if (!source) return fallbackAvatar(name)
|
if (!source) return fallbackAvatar(name)
|
||||||
if (/^data:image\/[a-z0-9.+-]+;base64,[a-z0-9+/=]+$/i.test(source)) return source
|
if (/^data:image\/[a-z0-9.+/-]+;base64,[a-z0-9+/=]+$/i.test(source)) return source
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (/^https?:\/\//i.test(source)) {
|
if (/^https?:\/\//i.test(source)) {
|
||||||
@@ -84,6 +86,51 @@ const templatePath = (): string => {
|
|||||||
return found
|
return found
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从群成员快照反推真头像,填进 metadata.avatars。
|
||||||
|
* - 没传 talker → 跳过(向后兼容)
|
||||||
|
* - talker 解析失败 / snapshot 拿不到 → 200 + warn,继续走 fallback
|
||||||
|
* - 客户端传的 avatars[name](非空)优先;否则从 snapshot 的 m_nsHeadImgUrl 补
|
||||||
|
* - 同名取首条(P2 风险:群里两人同名)
|
||||||
|
*/
|
||||||
|
const enrichAvatarsFromGroup = async (metadata: GroupReportMetadata): Promise<void> => {
|
||||||
|
if (!metadata.talker) return
|
||||||
|
|
||||||
|
const resolved = resolveMd5(metadata.talker)
|
||||||
|
if (!resolved) {
|
||||||
|
metadata.warnings = metadata.warnings ?? []
|
||||||
|
metadata.warnings.push(`enrich skipped: talker "${metadata.talker}" not found`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const snapshot = getGroupSnapshot(resolved.md5)
|
||||||
|
if (!snapshot) {
|
||||||
|
metadata.warnings = metadata.warnings ?? []
|
||||||
|
metadata.warnings.push(
|
||||||
|
`enrich skipped: group snapshot not available for "${metadata.talker}"`
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const index = new Map<string, string>()
|
||||||
|
for (const member of snapshot.members) {
|
||||||
|
if (member.nickname && member.avatar && !index.has(member.nickname)) {
|
||||||
|
index.set(member.nickname, member.avatar)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
metadata.avatars = metadata.avatars ?? {}
|
||||||
|
for (const [name, url] of index) {
|
||||||
|
if (metadata.avatars[name]) continue
|
||||||
|
metadata.avatars[name] = url
|
||||||
|
}
|
||||||
|
|
||||||
|
metadata.warnings = metadata.warnings ?? []
|
||||||
|
metadata.warnings.push(
|
||||||
|
`enriched ${index.size} member avatars from snapshot (${snapshot.memberCount} members)`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const heatClass = (heat: ReportHeat): string => {
|
const heatClass = (heat: ReportHeat): string => {
|
||||||
if (heat === '高') return 'hot'
|
if (heat === '高') return 'hot'
|
||||||
if (heat === '低') return 'blue'
|
if (heat === '低') return 'blue'
|
||||||
@@ -208,7 +255,7 @@ const renderReportHtml = async (request: GroupReportExportRequest): Promise<stri
|
|||||||
HERO_AVATARS: heroAvatars,
|
HERO_AVATARS: heroAvatars,
|
||||||
MESSAGE_COUNT: String(metadata.messageCount),
|
MESSAGE_COUNT: String(metadata.messageCount),
|
||||||
ACTIVE_USERS: String(metadata.activeUsers),
|
ACTIVE_USERS: String(metadata.activeUsers),
|
||||||
TIME_SPAN: escapeHtml(metadata.timeSpan),
|
TIME_SPAN: escapeHtml(metadata.timeSpan || ''),
|
||||||
TOPIC_COUNT: String(report.topics.length),
|
TOPIC_COUNT: String(report.topics.length),
|
||||||
TOPIC_CARDS: topicCards,
|
TOPIC_CARDS: topicCards,
|
||||||
RESOURCES_EMPTY_CLASS: report.resources.length ? '' : 'empty-section',
|
RESOURCES_EMPTY_CLASS: report.resources.length ? '' : 'empty-section',
|
||||||
@@ -280,6 +327,9 @@ export const exportGroupReport = async (
|
|||||||
request: GroupReportExportRequest
|
request: GroupReportExportRequest
|
||||||
): Promise<GroupReportExportResult> => {
|
): Promise<GroupReportExportResult> => {
|
||||||
try {
|
try {
|
||||||
|
// === enrich 在 render 之前:从群成员快照反推真头像 ===
|
||||||
|
await enrichAvatarsFromGroup(request.metadata)
|
||||||
|
|
||||||
const outputDir = path.join(os.homedir(), 'Documents', '微信聊天记录')
|
const outputDir = path.join(os.homedir(), 'Documents', '微信聊天记录')
|
||||||
await fs.ensureDir(outputDir)
|
await fs.ensureDir(outputDir)
|
||||||
const baseName = `${sanitizeFileName(request.metadata.groupName)}日报_${request.metadata.reportDate}_可视化长图`
|
const baseName = `${sanitizeFileName(request.metadata.groupName)}日报_${request.metadata.reportDate}_可视化长图`
|
||||||
@@ -288,7 +338,13 @@ export const exportGroupReport = async (
|
|||||||
const html = await renderReportHtml(request)
|
const html = await renderReportHtml(request)
|
||||||
await fs.writeFile(htmlPath, html, 'utf8')
|
await fs.writeFile(htmlPath, html, 'utf8')
|
||||||
const imageDataUrl = await captureFullPage(htmlPath, pngPath)
|
const imageDataUrl = await captureFullPage(htmlPath, pngPath)
|
||||||
return { success: true, htmlPath, pngPath, imageDataUrl }
|
return {
|
||||||
|
success: true,
|
||||||
|
htmlPath,
|
||||||
|
pngPath,
|
||||||
|
imageDataUrl,
|
||||||
|
warnings: request.metadata.warnings?.length ? request.metadata.warnings : undefined
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('[GroupReport] export failed:', error)
|
console.error('[GroupReport] export failed:', error)
|
||||||
return { success: false, error: error instanceof Error ? error.message : String(error) }
|
return { success: false, error: error instanceof Error ? error.message : String(error) }
|
||||||
|
|||||||
@@ -0,0 +1,382 @@
|
|||||||
|
import http, { IncomingMessage, ServerResponse, Server } from 'http'
|
||||||
|
import {
|
||||||
|
isReady,
|
||||||
|
listContacts,
|
||||||
|
listMessages,
|
||||||
|
getGroupSnapshot,
|
||||||
|
listRecentChat,
|
||||||
|
resolveMd5
|
||||||
|
} from './services/chat-service'
|
||||||
|
import { exportGroupReport } from './group-report-service'
|
||||||
|
import { GroupReportExportRequest } from '../shared/group-report'
|
||||||
|
import { safeError, safeLog, safeWarn } from './safe-log'
|
||||||
|
|
||||||
|
export const DEFAULT_HTTP_HOST = '127.0.0.1'
|
||||||
|
export const DEFAULT_HTTP_PORT = 6131
|
||||||
|
|
||||||
|
export interface HttpServerHandle {
|
||||||
|
host: string
|
||||||
|
port: number
|
||||||
|
close(): Promise<void>
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RouteContext {
|
||||||
|
req: IncomingMessage
|
||||||
|
res: ServerResponse
|
||||||
|
url: URL
|
||||||
|
body?: unknown
|
||||||
|
}
|
||||||
|
|
||||||
|
type RouteHandler = (ctx: RouteContext) => void | Promise<void>
|
||||||
|
|
||||||
|
function sendJson(res: ServerResponse, status: number, payload: unknown): void {
|
||||||
|
const body = JSON.stringify(payload, null, 2)
|
||||||
|
res.writeHead(status, {
|
||||||
|
'Content-Type': 'application/json; charset=utf-8',
|
||||||
|
'Content-Length': Buffer.byteLength(body),
|
||||||
|
'Access-Control-Allow-Origin': '*',
|
||||||
|
'Cache-Control': 'no-store'
|
||||||
|
})
|
||||||
|
res.end(body)
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendError(res: ServerResponse, status: number, message: string, extra?: unknown): void {
|
||||||
|
sendJson(res, status, { error: message, status, ...(extra ? { details: extra } : {}) })
|
||||||
|
}
|
||||||
|
|
||||||
|
function readBody(req: IncomingMessage): Promise<string> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const chunks: Buffer[] = []
|
||||||
|
req.on('data', (chunk: Buffer) => chunks.push(chunk))
|
||||||
|
req.on('end', () => resolve(Buffer.concat(chunks).toString('utf-8')))
|
||||||
|
req.on('error', reject)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function rangeToSec(input: string, endOfUnit = false): number | null {
|
||||||
|
const m = input.match(/^(\d{4})-(\d{2})-(\d{2})(?:\/(\d{2}):(\d{2}))?$/)
|
||||||
|
if (!m) return null
|
||||||
|
const [, y, mo, d, hStr, miStr] = m
|
||||||
|
const hasTime = hStr !== undefined
|
||||||
|
|
||||||
|
let hh: number, mi: number, ss: number, ms: number
|
||||||
|
if (hasTime) {
|
||||||
|
hh = Number(hStr)
|
||||||
|
mi = Number(miStr)
|
||||||
|
ss = endOfUnit ? 59 : 0
|
||||||
|
ms = endOfUnit ? 999 : 0
|
||||||
|
} else if (endOfUnit) {
|
||||||
|
hh = 23
|
||||||
|
mi = 59
|
||||||
|
ss = 59
|
||||||
|
ms = 999
|
||||||
|
} else {
|
||||||
|
hh = 0
|
||||||
|
mi = 0
|
||||||
|
ss = 0
|
||||||
|
ms = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
const date = new Date(Number(y), Number(mo) - 1, Number(d), hh, mi, ss, ms)
|
||||||
|
return Math.floor(date.getTime() / 1000)
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseTimeRange(value: string | null): { startTime?: number; endTime?: number } {
|
||||||
|
if (!value) return {}
|
||||||
|
const trimmed = value.trim()
|
||||||
|
if (!trimmed) return {}
|
||||||
|
|
||||||
|
if (/^\d{10,13}$/.test(trimmed)) {
|
||||||
|
const n = Number(trimmed)
|
||||||
|
if (!Number.isFinite(n)) return {}
|
||||||
|
return { startTime: n > 1e12 ? Math.floor(n / 1000) : Math.floor(n) }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (trimmed.includes('~')) {
|
||||||
|
const [a, b] = trimmed.split('~').map((s) => s.trim())
|
||||||
|
const start = rangeToSec(a, false)
|
||||||
|
const end = rangeToSec(b, true)
|
||||||
|
return {
|
||||||
|
startTime: start ?? undefined,
|
||||||
|
endTime: end ?? undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const start = rangeToSec(trimmed, false)
|
||||||
|
const end = rangeToSec(trimmed, true)
|
||||||
|
return {
|
||||||
|
startTime: start ?? undefined,
|
||||||
|
endTime: end ?? undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseNumeric(value: string | null, fallback: number): number {
|
||||||
|
if (!value) return fallback
|
||||||
|
const n = Number(value)
|
||||||
|
return Number.isFinite(n) ? n : fallback
|
||||||
|
}
|
||||||
|
|
||||||
|
const routes: Record<string, RouteHandler> = {
|
||||||
|
'/api/v1/health': ({ res }) => {
|
||||||
|
sendJson(res, 200, {
|
||||||
|
ok: true,
|
||||||
|
ready: isReady(),
|
||||||
|
service: 'WechatExplorer Reader',
|
||||||
|
version: '1.0.0',
|
||||||
|
timestamp: new Date().toISOString()
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
'/api/v1/current_time': ({ res }) => {
|
||||||
|
const now = new Date()
|
||||||
|
sendJson(res, 200, {
|
||||||
|
time: now.toISOString(),
|
||||||
|
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
||||||
|
timestamp: Math.floor(now.getTime() / 1000),
|
||||||
|
localDate: `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(
|
||||||
|
now.getDate()
|
||||||
|
).padStart(2, '0')}`
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
'/api/v1/contact': ({ res, url }) => {
|
||||||
|
if (!isReady()) return sendError(res, 503, 'WechatExplorer 数据库未初始化')
|
||||||
|
const filter = url.searchParams.get('filter') || undefined
|
||||||
|
const type = url.searchParams.get('type') || undefined
|
||||||
|
let contacts = listContacts(filter)
|
||||||
|
if (type === 'user' || type === 'group') {
|
||||||
|
contacts = contacts.filter((c) => c.type === type)
|
||||||
|
}
|
||||||
|
sendJson(res, 200, { count: contacts.length, contacts })
|
||||||
|
},
|
||||||
|
|
||||||
|
'/api/v1/chatroom': ({ res, url }) => {
|
||||||
|
if (!isReady()) return sendError(res, 503, 'WechatExplorer 数据库未初始化')
|
||||||
|
const keyword = url.searchParams.get('keyword') || ''
|
||||||
|
let groups = listContacts().filter((c) => c.type === 'group')
|
||||||
|
if (keyword) {
|
||||||
|
const lower = keyword.toLowerCase()
|
||||||
|
groups = groups.filter(
|
||||||
|
(c) => c.m_nsNickName.toLowerCase().includes(lower) || c.m_nsUsrName.toLowerCase().includes(lower)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
sendJson(res, 200, { count: groups.length, chatrooms: groups })
|
||||||
|
},
|
||||||
|
|
||||||
|
'/api/v1/recent_chat': ({ res, url }) => {
|
||||||
|
if (!isReady()) return sendError(res, 503, 'WechatExplorer 数据库未初始化')
|
||||||
|
const limit = parseNumeric(url.searchParams.get('limit'), 50)
|
||||||
|
const items = listRecentChat(limit)
|
||||||
|
sendJson(res, 200, { count: items.length, items })
|
||||||
|
},
|
||||||
|
|
||||||
|
'/api/v1/chatlog': ({ res, url }) => {
|
||||||
|
if (!isReady()) return sendError(res, 503, 'WechatExplorer 数据库未初始化')
|
||||||
|
const talker = url.searchParams.get('talker')
|
||||||
|
if (!talker) return sendError(res, 400, '缺少必要参数 talker')
|
||||||
|
|
||||||
|
const resolved = resolveMd5(talker)
|
||||||
|
if (!resolved) return sendError(res, 404, `未找到会话: ${talker}`)
|
||||||
|
|
||||||
|
const timeParam = url.searchParams.get('time')
|
||||||
|
const startParam = url.searchParams.get('startTime')
|
||||||
|
const endParam = url.searchParams.get('endTime')
|
||||||
|
|
||||||
|
let startTime: number | undefined
|
||||||
|
let endTime: number | undefined
|
||||||
|
if (timeParam) {
|
||||||
|
const range = parseTimeRange(timeParam)
|
||||||
|
startTime = range.startTime
|
||||||
|
endTime = range.endTime
|
||||||
|
} else {
|
||||||
|
if (startParam) {
|
||||||
|
const r = parseTimeRange(startParam)
|
||||||
|
startTime = r.startTime
|
||||||
|
}
|
||||||
|
if (endParam) {
|
||||||
|
const r = parseTimeRange(endParam)
|
||||||
|
endTime = r.endTime
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const messages = listMessages(resolved.md5, startTime, endTime)
|
||||||
|
sendJson(res, 200, {
|
||||||
|
contact: resolved,
|
||||||
|
query: { talker, time: timeParam, startTime, endTime },
|
||||||
|
count: messages.length,
|
||||||
|
messages
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
'/api/v1/group_snapshot': ({ res, url }) => {
|
||||||
|
if (!isReady()) return sendError(res, 503, 'WechatExplorer 数据库未初始化')
|
||||||
|
const md5 = url.searchParams.get('md5')
|
||||||
|
if (!md5) return sendError(res, 400, '缺少必要参数 md5')
|
||||||
|
const snapshot = getGroupSnapshot(md5)
|
||||||
|
if (!snapshot) return sendError(res, 404, `未找到群聊: ${md5}`)
|
||||||
|
sendJson(res, 200, snapshot)
|
||||||
|
},
|
||||||
|
|
||||||
|
'/api/v1/resolve': ({ res, url }) => {
|
||||||
|
if (!isReady()) return sendError(res, 503, 'WechatExplorer 数据库未初始化')
|
||||||
|
const q = url.searchParams.get('q')
|
||||||
|
if (!q) return sendError(res, 400, '缺少必要参数 q')
|
||||||
|
const contact = resolveMd5(q)
|
||||||
|
if (!contact) return sendError(res, 404, `未匹配到联系人: ${q}`)
|
||||||
|
sendJson(res, 200, contact)
|
||||||
|
},
|
||||||
|
|
||||||
|
'/api/v1/report': async ({ req, res, body }) => {
|
||||||
|
if (req.method !== 'POST') return sendError(res, 405, '需要 POST 请求')
|
||||||
|
if (!isReady()) return sendError(res, 503, 'WechatExplorer 数据库未初始化')
|
||||||
|
if (typeof body !== 'string' || !body.trim()) {
|
||||||
|
return sendError(res, 400, '请求体为空,需 POST GroupReportExportRequest JSON')
|
||||||
|
}
|
||||||
|
let request: GroupReportExportRequest
|
||||||
|
try {
|
||||||
|
request = JSON.parse(body) as GroupReportExportRequest
|
||||||
|
} catch (error) {
|
||||||
|
return sendError(res, 400, '请求体 JSON 解析失败', error instanceof Error ? error.message : String(error))
|
||||||
|
}
|
||||||
|
if (!request?.report || !request?.metadata) {
|
||||||
|
return sendError(res, 400, '请求体需包含 report 和 metadata 字段')
|
||||||
|
}
|
||||||
|
const result = await exportGroupReport(request)
|
||||||
|
sendJson(res, result.success ? 200 : 500, result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function startHttpServer(
|
||||||
|
host: string = DEFAULT_HTTP_HOST,
|
||||||
|
port: number = DEFAULT_HTTP_PORT
|
||||||
|
): Promise<HttpServerHandle> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const server: Server = http.createServer(async (req, res) => {
|
||||||
|
try {
|
||||||
|
const url = new URL(req.url || '/', `http://${host}:${port}`)
|
||||||
|
if (req.method === 'OPTIONS') {
|
||||||
|
res.writeHead(204, {
|
||||||
|
'Access-Control-Allow-Origin': '*',
|
||||||
|
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
|
||||||
|
'Access-Control-Allow-Headers': '*'
|
||||||
|
})
|
||||||
|
return res.end()
|
||||||
|
}
|
||||||
|
const handler = routes[url.pathname]
|
||||||
|
if (!handler) {
|
||||||
|
return sendError(res, 404, `端点不存在: ${url.pathname}`)
|
||||||
|
}
|
||||||
|
let body: string | undefined
|
||||||
|
if (req.method && req.method !== 'GET' && req.method !== 'HEAD') {
|
||||||
|
body = await readBody(req)
|
||||||
|
}
|
||||||
|
const ctx: RouteContext = { req, res, url, body }
|
||||||
|
await handler(ctx)
|
||||||
|
} catch (error) {
|
||||||
|
safeError('[HttpServer] 请求处理失败:', error)
|
||||||
|
if (!res.headersSent) {
|
||||||
|
sendError(res, 500, error instanceof Error ? error.message : String(error))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
server.once('error', (error: NodeJS.ErrnoException) => {
|
||||||
|
const message =
|
||||||
|
error.code === 'EADDRINUSE'
|
||||||
|
? `端口 ${port} 已被占用,请关闭占用进程或在设置中更换端口`
|
||||||
|
: error.message
|
||||||
|
reject(Object.assign(error, { friendlyMessage: message }))
|
||||||
|
})
|
||||||
|
server.listen(port, host, () => {
|
||||||
|
server.off('error', () => undefined)
|
||||||
|
const actualPort = (server.address() as { port: number } | null)?.port ?? port
|
||||||
|
safeLog(`[HttpServer] Listening on http://${host}:${actualPort}`)
|
||||||
|
resolve({
|
||||||
|
host,
|
||||||
|
port: actualPort,
|
||||||
|
close: () =>
|
||||||
|
new Promise<void>((res) => {
|
||||||
|
server.close(() => res())
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ApiServerState {
|
||||||
|
running: boolean
|
||||||
|
host: string
|
||||||
|
port: number
|
||||||
|
error?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
let singleton: HttpServerHandle | null = null
|
||||||
|
let singletonState: ApiServerState = { running: false, host: DEFAULT_HTTP_HOST, port: DEFAULT_HTTP_PORT }
|
||||||
|
|
||||||
|
function sleep(ms: number): Promise<void> {
|
||||||
|
return new Promise((resolve) => setTimeout(resolve, ms))
|
||||||
|
}
|
||||||
|
|
||||||
|
export const apiServer = {
|
||||||
|
isRunning(): boolean {
|
||||||
|
return singleton !== null
|
||||||
|
},
|
||||||
|
|
||||||
|
getState(): ApiServerState {
|
||||||
|
return { ...singletonState }
|
||||||
|
},
|
||||||
|
|
||||||
|
async start(host: string = DEFAULT_HTTP_HOST, port: number = DEFAULT_HTTP_PORT): Promise<ApiServerState> {
|
||||||
|
if (singleton) {
|
||||||
|
return this.getState()
|
||||||
|
}
|
||||||
|
|
||||||
|
const maxAttempts = 4
|
||||||
|
let lastError: (NodeJS.ErrnoException & { friendlyMessage?: string }) | null = null
|
||||||
|
for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
|
||||||
|
try {
|
||||||
|
singleton = await startHttpServer(host, port)
|
||||||
|
singletonState = {
|
||||||
|
running: true,
|
||||||
|
host: singleton.host,
|
||||||
|
port: singleton.port
|
||||||
|
}
|
||||||
|
safeLog(`[ApiServer] started on http://${singleton.host}:${singleton.port}`)
|
||||||
|
return { ...singletonState }
|
||||||
|
} catch (error) {
|
||||||
|
lastError = error as NodeJS.ErrnoException & { friendlyMessage?: string }
|
||||||
|
if ((error as NodeJS.ErrnoException).code !== 'EADDRINUSE' || attempt === maxAttempts) break
|
||||||
|
// Brief wait to let the OS release the port (TIME_WAIT / concurrent dev session).
|
||||||
|
await sleep(400 * attempt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const message =
|
||||||
|
lastError?.friendlyMessage ||
|
||||||
|
(lastError instanceof Error ? lastError.message : String(lastError)) ||
|
||||||
|
'API 启动失败'
|
||||||
|
singletonState = {
|
||||||
|
running: false,
|
||||||
|
host,
|
||||||
|
port,
|
||||||
|
error: message
|
||||||
|
}
|
||||||
|
safeError('[ApiServer] start failed:', message)
|
||||||
|
return { ...singletonState }
|
||||||
|
},
|
||||||
|
|
||||||
|
async stop(): Promise<ApiServerState> {
|
||||||
|
if (!singleton) {
|
||||||
|
return this.getState()
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await singleton.close()
|
||||||
|
} catch (error) {
|
||||||
|
safeWarn('[ApiServer] close failed:', error)
|
||||||
|
}
|
||||||
|
singleton = null
|
||||||
|
singletonState = { ...singletonState, running: false }
|
||||||
|
safeLog('[ApiServer] stopped')
|
||||||
|
return { ...singletonState }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -241,15 +241,11 @@ export class ImageDecryptService {
|
|||||||
)
|
)
|
||||||
|
|
||||||
let decrypted: Buffer
|
let decrypted: Buffer
|
||||||
if (version === 0) {
|
if (version === 1) {
|
||||||
console.log('[ImageDecrypt] using V3 (XOR only)')
|
|
||||||
decrypted = this.decryptDatV3(datPath)
|
|
||||||
} else if (version === 1) {
|
|
||||||
console.log('[ImageDecrypt] using V1 (default AES key)')
|
console.log('[ImageDecrypt] using V1 (default AES key)')
|
||||||
const key = Buffer.from(this.defaultV1AesKey, 'ascii')
|
const key = Buffer.from(this.defaultV1AesKey, 'ascii')
|
||||||
decrypted = this.decryptDatV4(datPath, key)
|
decrypted = this.decryptDatV4(datPath, key)
|
||||||
} else {
|
} else if (version === 2) {
|
||||||
// version === 2
|
|
||||||
console.log('[ImageDecrypt] using V2 (user AES key)')
|
console.log('[ImageDecrypt] using V2 (user AES key)')
|
||||||
if (!this.aesKey) {
|
if (!this.aesKey) {
|
||||||
console.log('[ImageDecrypt] no AES key configured')
|
console.log('[ImageDecrypt] no AES key configured')
|
||||||
@@ -257,6 +253,9 @@ export class ImageDecryptService {
|
|||||||
}
|
}
|
||||||
const key = Buffer.from(this.aesKey, 'ascii').slice(0, 16)
|
const key = Buffer.from(this.aesKey, 'ascii').slice(0, 16)
|
||||||
decrypted = this.decryptDatV4(datPath, key)
|
decrypted = this.decryptDatV4(datPath, key)
|
||||||
|
} else {
|
||||||
|
console.log('[ImageDecrypt] unsupported dat version:', version)
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return decrypted
|
return decrypted
|
||||||
@@ -310,18 +309,6 @@ export class ImageDecryptService {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* V3 解密 - 仅 XOR
|
|
||||||
*/
|
|
||||||
private decryptDatV3(inputPath: string): Buffer {
|
|
||||||
const data = readFileSync(inputPath)
|
|
||||||
const out = Buffer.alloc(data.length)
|
|
||||||
for (let i = 0; i < data.length; i += 1) {
|
|
||||||
out[i] = data[i] ^ this.xorKey
|
|
||||||
}
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* V4 解密 - AES + XOR
|
* V4 解密 - AES + XOR
|
||||||
*/
|
*/
|
||||||
|
|||||||
+160
-229
@@ -1,61 +1,47 @@
|
|||||||
import { app, shell, BrowserWindow, ipcMain, nativeImage, clipboard } from 'electron'
|
import { app, shell, BrowserWindow, ipcMain, nativeImage, clipboard, Menu, Tray } from 'electron'
|
||||||
import { join } from 'path'
|
import { join } from 'path'
|
||||||
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
|
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
|
||||||
import icon from '../../resources/icon.png?asset'
|
import icon from '../../resources/icon.png?asset'
|
||||||
import { WechatDb, Contact, WechatMessage } from './wechat-db'
|
import { WechatDb } from './wechat-db'
|
||||||
import { VoiceService } from './voice-service'
|
import { VoiceService } from './voice-service'
|
||||||
import { StickerService } from './sticker-service'
|
import { StickerService } from './sticker-service'
|
||||||
import {
|
import { parseMessageContent } from './message-parser'
|
||||||
parseImageDatNameFromRow,
|
|
||||||
parseMessageContent,
|
|
||||||
parseStickerMessageFromRow
|
|
||||||
} from './message-parser'
|
|
||||||
import { ImageDecryptService } from './image-decrypt-service'
|
import { ImageDecryptService } from './image-decrypt-service'
|
||||||
import { exportGroupReport } from './group-report-service'
|
import { exportGroupReport } from './group-report-service'
|
||||||
import { GroupReportExportRequest } from '../shared/group-report'
|
import { GroupReportExportRequest } from '../shared/group-report'
|
||||||
import { DatabaseKeyStore } from './database-key-store'
|
import { DatabaseKeyStore } from './database-key-store'
|
||||||
import { KeyServiceMac } from './key-service-mac'
|
import { KeyServiceMac } from './key-service-mac'
|
||||||
|
import * as chat from './services/chat-service'
|
||||||
|
import {
|
||||||
|
apiServer
|
||||||
|
} from './http-server'
|
||||||
|
import {
|
||||||
|
loadSettings,
|
||||||
|
saveSettings,
|
||||||
|
getSettingsPath,
|
||||||
|
AppSettings
|
||||||
|
} from './services/settings-store'
|
||||||
|
import { installSafeConsole } from './safe-log'
|
||||||
|
|
||||||
|
// electron-vite can close the child's stdout/stderr after spawning Electron.
|
||||||
|
// Plain console.error then throws EPIPE on a closed pipe and crashes the IPC
|
||||||
|
// handler. Wrap console.* before any other module logs anything.
|
||||||
|
installSafeConsole()
|
||||||
|
|
||||||
let wechatDb: WechatDb | null = null
|
|
||||||
let voiceService: VoiceService | null = null
|
let voiceService: VoiceService | null = null
|
||||||
let imageDecryptService: ImageDecryptService | null = null
|
let imageDecryptService: ImageDecryptService | null = null
|
||||||
let stickerService: StickerService | null = null
|
let stickerService: StickerService | null = null
|
||||||
const databaseKeyStore = new DatabaseKeyStore()
|
const databaseKeyStore = new DatabaseKeyStore()
|
||||||
const keyServiceMac = new KeyServiceMac()
|
const keyServiceMac = new KeyServiceMac()
|
||||||
const BUILD_MARK = 'wechat4-open-account-continues-after-init-1000'
|
let tray: Tray | null = null
|
||||||
|
const BUILD_MARK = 'wechat4-local-http-api-2026-07-03'
|
||||||
|
const TRAY_MODE =
|
||||||
|
process.argv.includes('--tray') || (process.env['WXE_TRAY'] || '').toString() === '1'
|
||||||
|
|
||||||
// WechatExplorer's WCDB native library runs InitProtection before wcdb_init.
|
// WechatExplorer's WCDB native library runs InitProtection before wcdb_init.
|
||||||
// In dev, matching the host app name avoids failing the native protection gate.
|
// In dev, matching the host app name avoids failing the native protection gate.
|
||||||
app.setName('WechatExplorer')
|
app.setName('WechatExplorer')
|
||||||
|
|
||||||
const MSG_TYPE_DICT: Record<number, string> = {
|
|
||||||
1: '普通文本',
|
|
||||||
3: '图片',
|
|
||||||
34: '语音',
|
|
||||||
42: '名片',
|
|
||||||
43: '视频',
|
|
||||||
47: '表情包',
|
|
||||||
48: '位置',
|
|
||||||
49: '分享消息',
|
|
||||||
50: '通话',
|
|
||||||
10000: '系统消息'
|
|
||||||
}
|
|
||||||
|
|
||||||
function normalizeMsgType(value: string | number | undefined): number {
|
|
||||||
const raw = String(value ?? '').trim()
|
|
||||||
if (!raw) return 0
|
|
||||||
|
|
||||||
try {
|
|
||||||
const parsed = BigInt(raw)
|
|
||||||
const low32 = Number(parsed & 0xffffffffn)
|
|
||||||
return low32 || Number(parsed)
|
|
||||||
} catch {
|
|
||||||
const parsed = Number(raw)
|
|
||||||
if (!Number.isFinite(parsed)) return 0
|
|
||||||
return parsed > 0xffffffff ? parsed >>> 0 : parsed
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function createWindow(): void {
|
function createWindow(): void {
|
||||||
// 创建浏览器窗口
|
// 创建浏览器窗口
|
||||||
const mainWindow = new BrowserWindow({
|
const mainWindow = new BrowserWindow({
|
||||||
@@ -90,7 +76,7 @@ function createWindow(): void {
|
|||||||
|
|
||||||
// 当 Electron 完成初始化并准备好创建浏览器窗口时,将调用此方法
|
// 当 Electron 完成初始化并准备好创建浏览器窗口时,将调用此方法
|
||||||
// 某些 API 只能在此事件发生后使用
|
// 某些 API 只能在此事件发生后使用
|
||||||
app.whenReady().then(() => {
|
app.whenReady().then(async () => {
|
||||||
console.log(`WechatExplorer main build: ${BUILD_MARK}`)
|
console.log(`WechatExplorer main build: ${BUILD_MARK}`)
|
||||||
// 为窗口设置应用程序用户模型 ID
|
// 为窗口设置应用程序用户模型 ID
|
||||||
electronApp.setAppUserModelId('com.electron')
|
electronApp.setAppUserModelId('com.electron')
|
||||||
@@ -110,19 +96,15 @@ app.whenReady().then(() => {
|
|||||||
const trimmedKey = String(key || '').trim()
|
const trimmedKey = String(key || '').trim()
|
||||||
console.log(`db:init build=${BUILD_MARK} keyLength=${trimmedKey.length}`)
|
console.log(`db:init build=${BUILD_MARK} keyLength=${trimmedKey.length}`)
|
||||||
const nextWechatDb = new WechatDb(key)
|
const nextWechatDb = new WechatDb(key)
|
||||||
wechatDb?.close()
|
chat.setChatDb(nextWechatDb)
|
||||||
wechatDb = nextWechatDb
|
|
||||||
const wcdb4Client = nextWechatDb.getWcdb4Client()
|
const wcdb4Client = nextWechatDb.getWcdb4Client()
|
||||||
let monitoring = false
|
voiceService = new VoiceService(wcdb4Client)
|
||||||
if (wcdb4Client) {
|
stickerService = new StickerService(wcdb4Client)
|
||||||
voiceService = new VoiceService(wcdb4Client)
|
const monitoring = wcdb4Client.startMonitor((type, json) => {
|
||||||
stickerService = new StickerService(wcdb4Client)
|
for (const window of BrowserWindow.getAllWindows()) {
|
||||||
monitoring = wcdb4Client.startMonitor((type, json) => {
|
if (!window.isDestroyed()) window.webContents.send('wcdb-change', { type, json })
|
||||||
for (const window of BrowserWindow.getAllWindows()) {
|
}
|
||||||
if (!window.isDestroyed()) window.webContents.send('wcdb-change', { type, json })
|
})
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
imageDecryptService = null
|
imageDecryptService = null
|
||||||
return { success: true, monitoring }
|
return { success: true, monitoring }
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -138,6 +120,8 @@ app.whenReady().then(() => {
|
|||||||
return databaseKeyStore.save(clipboardKey)
|
return databaseKeyStore.save(clipboardKey)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('key:saveDbKey', async (_, key: string) => databaseKeyStore.save(String(key || '')))
|
||||||
|
|
||||||
ipcMain.handle('key:clearSavedDbKey', async () => databaseKeyStore.clear())
|
ipcMain.handle('key:clearSavedDbKey', async () => databaseKeyStore.clear())
|
||||||
|
|
||||||
ipcMain.handle('key:autoGetDbKey', async (event) => {
|
ipcMain.handle('key:autoGetDbKey', async (event) => {
|
||||||
@@ -154,183 +138,15 @@ app.whenReady().then(() => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.handle('db:getContacts', (_, filter?: string) => {
|
ipcMain.handle('db:getContacts', (_, filter?: string) => chat.listContacts(filter))
|
||||||
if (!wechatDb) return []
|
|
||||||
|
|
||||||
const contacts: Contact[] = []
|
ipcMain.handle('db:getMessages', (_, userMd5: string, startTime?: number, endTime?: number) =>
|
||||||
const groupContacts = wechatDb.getAllGroupContacts()
|
chat.listMessages(userMd5, startTime, endTime)
|
||||||
const userList = wechatDb.getUserList(filter)
|
)
|
||||||
const existingMd5s = new Set<string>()
|
|
||||||
|
|
||||||
// 1. 处理普通联系人
|
ipcMain.handle('db:getGroupSnapshot', (_, userMd5: string) => chat.getGroupSnapshot(userMd5))
|
||||||
for (const user of userList) {
|
|
||||||
const md5 = wechatDb.md5(user.m_nsUsrName)
|
|
||||||
const isGroup = user.m_nsUsrName.endsWith('@chatroom')
|
|
||||||
existingMd5s.add(md5)
|
|
||||||
contacts.push({
|
|
||||||
m_nsUsrName: user.m_nsUsrName,
|
|
||||||
m_nsNickName: user.nickname || '未知用户',
|
|
||||||
md5: md5,
|
|
||||||
type: isGroup ? 'group' : 'user',
|
|
||||||
avatar: typeof user.avatar === 'string' ? user.avatar : undefined
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. 处理聊天表
|
ipcMain.handle('db:search', (_, keyword: string) => chat.searchMessages(keyword))
|
||||||
const chatTables = wechatDb.getAllChatTables()
|
|
||||||
for (const table of chatTables) {
|
|
||||||
if (!table.name.startsWith('Chat_')) continue
|
|
||||||
const md5 = table.name.substring(5)
|
|
||||||
|
|
||||||
if (!existingMd5s.has(md5)) {
|
|
||||||
if (groupContacts[md5]) {
|
|
||||||
contacts.push({
|
|
||||||
m_nsUsrName: `Group_${md5}`,
|
|
||||||
m_nsNickName: groupContacts[md5],
|
|
||||||
md5: md5,
|
|
||||||
type: 'group'
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
contacts.push({
|
|
||||||
m_nsUsrName: `Unknown_${md5}`,
|
|
||||||
m_nsNickName: `Chat_${md5}`,
|
|
||||||
md5: md5,
|
|
||||||
type: 'user'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return contacts
|
|
||||||
})
|
|
||||||
|
|
||||||
ipcMain.handle('db:getMessages', (_, userMd5: string, startTime?: number, endTime?: number) => {
|
|
||||||
if (!wechatDb) return []
|
|
||||||
const wcdb4Client = wechatDb.getWcdb4Client()
|
|
||||||
const username = wcdb4Client?.getUsernameByMd5(userMd5)
|
|
||||||
const rawMessages = wechatDb.getUserMessages(userMd5, startTime, endTime)
|
|
||||||
const groupMembers = wechatDb.getGroupMembersForChat(userMd5)
|
|
||||||
const myAvatar = wechatDb.getMyAvatarUrl()
|
|
||||||
const myGroupNickname =
|
|
||||||
username?.endsWith('@chatroom') && wcdb4Client
|
|
||||||
? wcdb4Client.getMyGroupNickname(username)
|
|
||||||
: undefined
|
|
||||||
|
|
||||||
return rawMessages.map((msg: WechatMessage) => {
|
|
||||||
const rawMsgType = parseInt(msg.messageType)
|
|
||||||
const msgType = normalizeMsgType(msg.messageType)
|
|
||||||
const createTime = parseInt(msg.msgCreateTime)
|
|
||||||
const date = new Date(createTime * 1000)
|
|
||||||
const isMine = msg.mesDes !== 1
|
|
||||||
const localId = parseInt(msg.mesLocalID) || 0
|
|
||||||
|
|
||||||
let content = msg.msgContent
|
|
||||||
let img = ''
|
|
||||||
let name = ''
|
|
||||||
if (isMine) {
|
|
||||||
if (myAvatar) img = myAvatar
|
|
||||||
name = myGroupNickname || (typeof msg.senderNickname === 'string' ? msg.senderNickname : '')
|
|
||||||
} else {
|
|
||||||
if (typeof msg.senderAvatar === 'string') img = msg.senderAvatar
|
|
||||||
if (typeof msg.senderNickname === 'string') name = msg.senderNickname
|
|
||||||
}
|
|
||||||
// 检查内容是否以 wxid 开头并包含冒号
|
|
||||||
// 示例: wxid_xxxx:\nContent 或 wxid_xxxx:Content
|
|
||||||
if (content && typeof content === 'string') {
|
|
||||||
const colonIndex = content.indexOf(':')
|
|
||||||
if (colonIndex > 0) {
|
|
||||||
const potentialWxid = content.substring(0, colonIndex)
|
|
||||||
if (potentialWxid.startsWith('wxid_')) {
|
|
||||||
// 尝试获取头像
|
|
||||||
if (wechatDb) {
|
|
||||||
const member = wechatDb.getGroupMember(potentialWxid)
|
|
||||||
if (member) {
|
|
||||||
img = member.m_nsHeadImgUrl
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (groupMembers[potentialWxid]) {
|
|
||||||
const nickname = groupMembers[potentialWxid]
|
|
||||||
name = nickname
|
|
||||||
content = content.substring(colonIndex + 1) // +1 to skip the colon
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 解析富媒体消息内容
|
|
||||||
let contentData: ReturnType<typeof parseMessageContent> | undefined = undefined
|
|
||||||
let displayType = MSG_TYPE_DICT[msgType] || msg.messageType
|
|
||||||
const inferredMsgType =
|
|
||||||
typeof content === 'string' &&
|
|
||||||
/<appmsg\b|<refermsg\b|<appmsg\b|<refermsg\b/i.test(content)
|
|
||||||
? 49
|
|
||||||
: msgType
|
|
||||||
if ([3, 42, 47, 48, 49, 50].includes(inferredMsgType)) {
|
|
||||||
try {
|
|
||||||
const parsed =
|
|
||||||
inferredMsgType === 47
|
|
||||||
? parseStickerMessageFromRow(msg, content)
|
|
||||||
: parseMessageContent(content, inferredMsgType)
|
|
||||||
if (parsed.type !== 'unknown') {
|
|
||||||
content = ''
|
|
||||||
}
|
|
||||||
if (parsed.type === 'image') {
|
|
||||||
const imageDatName = parseImageDatNameFromRow(msg)
|
|
||||||
contentData = { ...parsed, datName: parsed.datName || imageDatName }
|
|
||||||
} else {
|
|
||||||
if (parsed.type === 'sticker' && !parsed.url && parsed.md5 && wcdb4Client) {
|
|
||||||
parsed.url = wcdb4Client.resolveEmoticonCdnUrl(parsed.md5)
|
|
||||||
}
|
|
||||||
contentData = parsed
|
|
||||||
}
|
|
||||||
if (inferredMsgType !== msgType || rawMsgType !== msgType) {
|
|
||||||
displayType = MSG_TYPE_DICT[inferredMsgType] || displayType
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
// ignore parse errors
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
!contentData &&
|
|
||||||
typeof content === 'string' &&
|
|
||||||
/^[0-9a-fA-F]{64,}$/.test(content.trim())
|
|
||||||
) {
|
|
||||||
const parsed = parseStickerMessageFromRow(msg, content)
|
|
||||||
if (parsed.type === 'sticker') {
|
|
||||||
if (!parsed.url && parsed.md5 && wcdb4Client) {
|
|
||||||
parsed.url = wcdb4Client.resolveEmoticonCdnUrl(parsed.md5)
|
|
||||||
}
|
|
||||||
content = ''
|
|
||||||
contentData = parsed
|
|
||||||
displayType = '表情包'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msgType === 34) {
|
|
||||||
content = '[语音消息]'
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
id: msg.mesLocalID || Math.random().toString(),
|
|
||||||
from: isMine ? 'assistant' : 'user',
|
|
||||||
type: displayType,
|
|
||||||
datetime: date.toLocaleString('zh-CN', { hour12: false }),
|
|
||||||
content: content,
|
|
||||||
img: img,
|
|
||||||
name: name,
|
|
||||||
sessionId: username,
|
|
||||||
localId: localId,
|
|
||||||
createTime: createTime,
|
|
||||||
contentData: contentData
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
ipcMain.handle('db:search', (_, keyword: string) => {
|
|
||||||
if (!wechatDb) return null
|
|
||||||
return wechatDb.searchAllMessages(keyword)
|
|
||||||
})
|
|
||||||
|
|
||||||
ipcMain.handle(
|
ipcMain.handle(
|
||||||
'ai:chat',
|
'ai:chat',
|
||||||
@@ -419,7 +235,7 @@ app.whenReady().then(() => {
|
|||||||
if (!aesKey) {
|
if (!aesKey) {
|
||||||
return { success: false, error: '未配置图片解密密钥' }
|
return { success: false, error: '未配置图片解密密钥' }
|
||||||
}
|
}
|
||||||
imageDecryptService = new ImageDecryptService(xorKey, aesKey, wechatDb?.getWcdb4Client())
|
imageDecryptService = new ImageDecryptService(xorKey, aesKey, chat.getChatDb()?.getWcdb4Client())
|
||||||
}
|
}
|
||||||
|
|
||||||
const imageDatName = typeof imageDatNameOrThumb === 'string' ? imageDatNameOrThumb : undefined
|
const imageDatName = typeof imageDatNameOrThumb === 'string' ? imageDatNameOrThumb : undefined
|
||||||
@@ -439,13 +255,75 @@ app.whenReady().then(() => {
|
|||||||
|
|
||||||
ipcMain.handle('db:getSticker', async (_, cdnUrl?: string, md5?: string) => {
|
ipcMain.handle('db:getSticker', async (_, cdnUrl?: string, md5?: string) => {
|
||||||
if (!stickerService) {
|
if (!stickerService) {
|
||||||
stickerService = new StickerService(wechatDb?.getWcdb4Client())
|
stickerService = new StickerService(chat.getChatDb()?.getWcdb4Client())
|
||||||
}
|
}
|
||||||
return stickerService.resolveSticker(cdnUrl, md5)
|
return stickerService.resolveSticker(cdnUrl, md5)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// -------- Settings & API service --------
|
||||||
|
|
||||||
|
ipcMain.handle('settings:get', () => ({
|
||||||
|
settings: loadSettings(),
|
||||||
|
settingsPath: getSettingsPath()
|
||||||
|
}))
|
||||||
|
|
||||||
|
ipcMain.handle('settings:set', (_, patch: Partial<AppSettings>) => {
|
||||||
|
const merged = saveSettings({ ...loadSettings(), ...patch })
|
||||||
|
return { settings: merged, settingsPath: getSettingsPath() }
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('settings:getSelf', () => {
|
||||||
|
const info = chat.getSelfAccountInfo()
|
||||||
|
if (!info) return { ready: false }
|
||||||
|
return { ready: true, info }
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('db:testConnection', (_, key: string, accountRoot?: string) => {
|
||||||
|
return chat.testConnection(key, accountRoot)
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('db:reopenWithRoot', (_, accountRoot: string) => {
|
||||||
|
const ok = chat.reopenWithRoot(accountRoot)
|
||||||
|
if (!ok) return { success: false, error: '数据库未初始化或重新打开失败' }
|
||||||
|
const info = chat.getSelfAccountInfo()
|
||||||
|
return { success: true, info }
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('api:getStatus', () => apiServer.getState())
|
||||||
|
|
||||||
|
ipcMain.handle('api:start', async (_, host?: string, port?: number) => {
|
||||||
|
const settings = loadSettings()
|
||||||
|
const target = {
|
||||||
|
host: host || settings.apiHost,
|
||||||
|
port: port || settings.apiPort
|
||||||
|
}
|
||||||
|
if (host || port) saveSettings({ ...settings, ...target })
|
||||||
|
return apiServer.start(target.host, target.port)
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('api:stop', async () => apiServer.stop())
|
||||||
|
|
||||||
|
ipcMain.handle('api:toggle', async (_, enabled: boolean) => {
|
||||||
|
const settings = saveSettings({ ...loadSettings(), apiEnabled: enabled })
|
||||||
|
if (enabled) {
|
||||||
|
return apiServer.start(settings.apiHost, settings.apiPort)
|
||||||
|
}
|
||||||
|
return apiServer.stop()
|
||||||
|
})
|
||||||
|
|
||||||
createWindow()
|
createWindow()
|
||||||
|
|
||||||
|
// 启动本地 HTTP API(根据 settings.apiEnabled 控制)
|
||||||
|
const settings = loadSettings()
|
||||||
|
if (settings.apiEnabled) {
|
||||||
|
await apiServer.start(settings.apiHost, settings.apiPort)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TRAY_MODE) {
|
||||||
|
app.dock?.hide()
|
||||||
|
setupTray()
|
||||||
|
}
|
||||||
|
|
||||||
app.on('activate', function () {
|
app.on('activate', function () {
|
||||||
// 在 macOS 上,当点击 dock 图标且没有其他窗口打开时,
|
// 在 macOS 上,当点击 dock 图标且没有其他窗口打开时,
|
||||||
// 通常会在应用程序中重新创建一个窗口。
|
// 通常会在应用程序中重新创建一个窗口。
|
||||||
@@ -457,12 +335,65 @@ app.whenReady().then(() => {
|
|||||||
// 应用程序及其菜单栏通常会保持活动状态,直到用户
|
// 应用程序及其菜单栏通常会保持活动状态,直到用户
|
||||||
// 显式使用 Cmd + Q 退出。
|
// 显式使用 Cmd + Q 退出。
|
||||||
app.on('window-all-closed', () => {
|
app.on('window-all-closed', () => {
|
||||||
|
if (TRAY_MODE) return
|
||||||
if (process.platform !== 'darwin') {
|
if (process.platform !== 'darwin') {
|
||||||
app.quit()
|
app.quit()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
app.on('before-quit', () => {
|
app.on('before-quit', async () => {
|
||||||
wechatDb?.close()
|
chat.setChatDb(null)
|
||||||
wechatDb = null
|
await apiServer.stop().catch(() => undefined)
|
||||||
|
if (tray) {
|
||||||
|
tray.destroy()
|
||||||
|
tray = null
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function showMainWindow(): void {
|
||||||
|
if (TRAY_MODE) app.dock?.show().catch(() => undefined)
|
||||||
|
const wins = BrowserWindow.getAllWindows()
|
||||||
|
if (wins.length === 0) {
|
||||||
|
createWindow()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const win = wins[0]
|
||||||
|
if (win.isMinimized()) win.restore()
|
||||||
|
win.show()
|
||||||
|
win.focus()
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildTrayMenu(): Menu {
|
||||||
|
return Menu.buildFromTemplate([
|
||||||
|
{
|
||||||
|
label: '打开主窗口',
|
||||||
|
click: () => showMainWindow()
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'API 状态',
|
||||||
|
click: () => showMainWindow()
|
||||||
|
},
|
||||||
|
{ type: 'separator' },
|
||||||
|
{
|
||||||
|
label: '退出 WechatExplorer',
|
||||||
|
click: () => {
|
||||||
|
tray?.destroy()
|
||||||
|
tray = null
|
||||||
|
app.quit()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupTray(): void {
|
||||||
|
if (tray) return
|
||||||
|
try {
|
||||||
|
const image = nativeImage.createFromPath(join(__dirname, '../../resources/icon.png'))
|
||||||
|
tray = new Tray(image.isEmpty() ? nativeImage.createEmpty() : image)
|
||||||
|
tray.setToolTip('WechatExplorer')
|
||||||
|
tray.setContextMenu(buildTrayMenu())
|
||||||
|
tray.on('click', () => showMainWindow())
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('[Tray] Failed to create tray:', error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+28
-10
@@ -16,17 +16,35 @@ export interface DatabaseKeyResult {
|
|||||||
|
|
||||||
export class KeyServiceMac {
|
export class KeyServiceMac {
|
||||||
private getHelperPath(): string {
|
private getHelperPath(): string {
|
||||||
const candidates = app.isPackaged
|
// 多 candidate fallback:覆盖 extraResources、asarUnpack、dev 三种场景
|
||||||
? [
|
// (extraResources → Contents/Resources/resources/;asarUnpack 同路径;dev → cwd 或 app.getAppPath)
|
||||||
path.join(process.resourcesPath, 'resources', 'xkey_helper'),
|
const candidates = [
|
||||||
path.join(process.resourcesPath, 'xkey_helper')
|
// 1) extraResources 标准位置(electron-builder.yml 配的就是这个)
|
||||||
]
|
path.join(process.resourcesPath, 'resources', 'xkey_helper'),
|
||||||
: [
|
// 2) process.resourcesPath 直接(防止 extraResources 没复制成功)
|
||||||
path.join(process.cwd(), 'resources', 'xkey_helper'),
|
path.join(process.resourcesPath, 'xkey_helper'),
|
||||||
path.join(app.getAppPath(), 'resources', 'xkey_helper')
|
// 3) asarUnpack 路径(如果在 asar 内的 resources/ 被解包到 app.asar.unpacked)
|
||||||
]
|
path.join(app.getAppPath(), 'app.asar.unpacked', 'resources', 'xkey_helper'),
|
||||||
|
// 4) dev 模式 + 打包后某些版本 app.getAppPath() 也指向 .app 根目录
|
||||||
|
path.join(app.getAppPath(), 'resources', 'xkey_helper'),
|
||||||
|
// 5) dev 模式:cwd
|
||||||
|
path.join(process.cwd(), 'resources', 'xkey_helper')
|
||||||
|
].filter((p, idx, arr) => arr.indexOf(p) === idx) // 去重
|
||||||
|
|
||||||
|
// 诊断:即使命中也打 log,方便排查"装了但找不到"的问题(translocation / quarantine)
|
||||||
|
const statusList = candidates.map((candidate) => ({
|
||||||
|
path: candidate,
|
||||||
|
exists: fs.existsSync(candidate)
|
||||||
|
}))
|
||||||
|
console.log('[KeyServiceMac] xkey_helper candidates:', JSON.stringify(statusList))
|
||||||
const helperPath = candidates.find((candidate) => fs.existsSync(candidate))
|
const helperPath = candidates.find((candidate) => fs.existsSync(candidate))
|
||||||
if (!helperPath) throw new Error('找不到 xkey_helper')
|
if (!helperPath) {
|
||||||
|
throw new Error(
|
||||||
|
`找不到 xkey_helper(尝试 ${candidates.length} 个路径;` +
|
||||||
|
` app.isPackaged=${app.isPackaged} resourcesPath=${process.resourcesPath} ` +
|
||||||
|
` appPath=${app.getAppPath()} cwd=${process.cwd()})`
|
||||||
|
)
|
||||||
|
}
|
||||||
return helperPath
|
return helperPath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ type QuoteContent = {
|
|||||||
quotedSender?: string
|
quotedSender?: string
|
||||||
quotedType?: string
|
quotedType?: string
|
||||||
}
|
}
|
||||||
type SystemContent = { type: 'system'; content: string }
|
type SystemContent = { type: 'system'; content: string; raw?: string }
|
||||||
type UnknownContent = { type: 'unknown'; raw: string }
|
type UnknownContent = { type: 'unknown'; raw: string }
|
||||||
|
|
||||||
export type ParsedContent =
|
export type ParsedContent =
|
||||||
@@ -79,12 +79,40 @@ export function parseMessageContent(content: string, messageType: number): Parse
|
|||||||
return parseVoipMessage(normalized)
|
return parseVoipMessage(normalized)
|
||||||
case 10000:
|
case 10000:
|
||||||
case 10002:
|
case 10002:
|
||||||
return { type: 'system', content: normalized }
|
return parseSystemMessage(normalized)
|
||||||
default:
|
default:
|
||||||
return { type: 'text', content: normalized }
|
return { type: 'text', content: normalized }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseSystemMessage(content: string): ParsedContent {
|
||||||
|
const stripped = stripChatroomPrefix(content)
|
||||||
|
const decoded = decodeXmlEntities(stripped)
|
||||||
|
const delChatroomMemberText = extractDelChatroomMemberText(decoded)
|
||||||
|
if (delChatroomMemberText) {
|
||||||
|
return {
|
||||||
|
type: 'system',
|
||||||
|
content: normalizeSystemText(delChatroomMemberText),
|
||||||
|
raw: content
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const plainText =
|
||||||
|
extractXmlNodeText(decoded, 'plain') ||
|
||||||
|
extractXmlNodeText(decoded, 'text') ||
|
||||||
|
extractXmlNodeText(decoded, 'title') ||
|
||||||
|
extractXmlValue(decoded, 'plain') ||
|
||||||
|
extractXmlValue(decoded, 'text') ||
|
||||||
|
extractXmlValue(decoded, 'title') ||
|
||||||
|
''
|
||||||
|
|
||||||
|
const normalized = normalizeSystemText(plainText || fallbackSystemText(decoded))
|
||||||
|
return {
|
||||||
|
type: 'system',
|
||||||
|
content: normalized || '[系统消息]',
|
||||||
|
raw: content
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function parseImageMessage(content: string): ParsedContent {
|
function parseImageMessage(content: string): ParsedContent {
|
||||||
// 尝试 XML 格式: <img md5="..." aeskey="..."/>
|
// 尝试 XML 格式: <img md5="..." aeskey="..."/>
|
||||||
let md5 = extractXmlAttribute(content, 'img', 'md5') || extractXmlValue(content, 'md5') || ''
|
let md5 = extractXmlAttribute(content, 'img', 'md5') || extractXmlValue(content, 'md5') || ''
|
||||||
@@ -356,6 +384,20 @@ function sanitizeQuotedContent(content: string): string {
|
|||||||
return decoded
|
return decoded
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function stripChatroomPrefix(content: string): string {
|
||||||
|
return String(content || '')
|
||||||
|
.replace(/^[0-9a-z_-]+@chatroom:\s*/i, '')
|
||||||
|
.replace(/^wxid_[^:\n]+:\s*/i, '')
|
||||||
|
.trim()
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeSystemText(content: string): string {
|
||||||
|
return String(content || '')
|
||||||
|
.replace(/\s+/g, ' ')
|
||||||
|
.replace(/\s+([,.;!?])/g, '$1')
|
||||||
|
.trim()
|
||||||
|
}
|
||||||
|
|
||||||
function parseVoipMessage(content: string): ParsedContent {
|
function parseVoipMessage(content: string): ParsedContent {
|
||||||
const roomTypeStr = extractXmlValue(content, 'room_type')
|
const roomTypeStr = extractXmlValue(content, 'room_type')
|
||||||
const msg = extractXmlValue(content, 'msg') || ''
|
const msg = extractXmlValue(content, 'msg') || ''
|
||||||
@@ -416,6 +458,44 @@ function decodeXmlUrl(value: string): string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function decodeXmlEntities(value: string): string {
|
||||||
|
return String(value || '')
|
||||||
|
.replace(/</g, '<')
|
||||||
|
.replace(/>/g, '>')
|
||||||
|
.replace(/"/g, '"')
|
||||||
|
.replace(/'/g, "'")
|
||||||
|
.replace(/&/g, '&')
|
||||||
|
}
|
||||||
|
|
||||||
|
function extractXmlNodeText(xml: string, tagName: string): string {
|
||||||
|
const match = new RegExp(`<${tagName}[^>]*>([\\s\\S]*?)<\\/${tagName}>`, 'i').exec(xml)
|
||||||
|
if (!match?.[1]) return ''
|
||||||
|
return normalizeSystemText(
|
||||||
|
decodeXmlEntities(
|
||||||
|
match[1].replace(/<!\[CDATA\[([\s\S]*?)\]\]>/g, '$1').replace(/<[^>]+>/g, ' ')
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function fallbackSystemText(xml: string): string {
|
||||||
|
return normalizeSystemText(
|
||||||
|
decodeXmlEntities(
|
||||||
|
String(xml || '')
|
||||||
|
.replace(/<!\[CDATA\[([\s\S]*?)\]\]>/g, '$1')
|
||||||
|
.replace(/<[^>]+>/g, ' ')
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function extractDelChatroomMemberText(xml: string): string {
|
||||||
|
if (!/<sysmsg[^>]+delchatroommember/i.test(xml)) return ''
|
||||||
|
const plainMatch = /<plain[^>]*><!\[CDATA\[([\s\S]*?)\]\]><\/plain>/i.exec(xml)
|
||||||
|
if (plainMatch?.[1]) return plainMatch[1].trim()
|
||||||
|
const textMatch = /<text[^>]*><!\[CDATA\[([\s\S]*?)\]\]><\/text>/i.exec(xml)
|
||||||
|
if (textMatch?.[1]) return textMatch[1].trim()
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
function normalizeMd5(value: unknown): string | undefined {
|
function normalizeMd5(value: unknown): string | undefined {
|
||||||
const md5 = String(value || '')
|
const md5 = String(value || '')
|
||||||
.trim()
|
.trim()
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
// Safe logging for Electron child processes whose stdout/stderr pipes can be
|
||||||
|
// closed by the parent (electron-vite). Plain console.error throws EPIPE
|
||||||
|
// against a closed pipe, which crashes the IPC handler. Wrap writes so any
|
||||||
|
// pipe error is swallowed.
|
||||||
|
type SafeConsoleMethod = (...args: unknown[]) => void
|
||||||
|
|
||||||
|
function makeSafe(method: SafeConsoleMethod): SafeConsoleMethod {
|
||||||
|
return (...args: unknown[]) => {
|
||||||
|
try {
|
||||||
|
method(...args)
|
||||||
|
} catch {
|
||||||
|
// Swallow EPIPE / ERR_STREAM_DESTROYED; logging must never crash the app.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const safeLog = makeSafe(console.log.bind(console))
|
||||||
|
export const safeWarn = makeSafe(console.warn.bind(console))
|
||||||
|
export const safeError = makeSafe(console.error.bind(console))
|
||||||
|
|
||||||
|
export function installSafeConsole(): void {
|
||||||
|
console.log = safeLog
|
||||||
|
console.warn = safeWarn
|
||||||
|
console.error = safeError
|
||||||
|
}
|
||||||
@@ -0,0 +1,393 @@
|
|||||||
|
import { WechatDb, WechatMessage } from '../wechat-db'
|
||||||
|
import {
|
||||||
|
parseImageDatNameFromRow,
|
||||||
|
parseMessageContent,
|
||||||
|
parseStickerMessageFromRow
|
||||||
|
} from '../message-parser'
|
||||||
|
|
||||||
|
export function getCurrentKey(): string {
|
||||||
|
if (!dbRef) return ''
|
||||||
|
try {
|
||||||
|
return dbRef.getWcdb4Client().getKey()
|
||||||
|
} catch {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FormattedContact {
|
||||||
|
m_nsUsrName: string
|
||||||
|
m_nsNickName: string
|
||||||
|
md5: string
|
||||||
|
type: 'user' | 'group'
|
||||||
|
avatar?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FormattedMessage {
|
||||||
|
id: string
|
||||||
|
from: string
|
||||||
|
type: string
|
||||||
|
datetime: string
|
||||||
|
content: string
|
||||||
|
isSender: boolean
|
||||||
|
img?: string
|
||||||
|
name?: string
|
||||||
|
contentData?: ReturnType<typeof parseMessageContent>
|
||||||
|
voiceDataUrl?: string
|
||||||
|
voiceDuration?: number
|
||||||
|
localId?: number
|
||||||
|
createTime?: number
|
||||||
|
sessionId?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GroupSnapshot {
|
||||||
|
roomId: string
|
||||||
|
memberCount: number
|
||||||
|
members: { wxid: string; nickname: string; avatar: string }[]
|
||||||
|
}
|
||||||
|
|
||||||
|
const MSG_TYPE_DICT: Record<number, string> = {
|
||||||
|
1: '普通文本',
|
||||||
|
3: '图片',
|
||||||
|
34: '语音',
|
||||||
|
42: '名片',
|
||||||
|
43: '视频',
|
||||||
|
47: '表情包',
|
||||||
|
48: '位置',
|
||||||
|
49: '分享消息',
|
||||||
|
50: '通话',
|
||||||
|
10000: '系统消息'
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeMsgType(value: string | number | undefined): number {
|
||||||
|
const raw = String(value ?? '').trim()
|
||||||
|
if (!raw) return 0
|
||||||
|
|
||||||
|
try {
|
||||||
|
const parsed = BigInt(raw)
|
||||||
|
const low32 = Number(parsed & 0xffffffffn)
|
||||||
|
return low32 || Number(parsed)
|
||||||
|
} catch {
|
||||||
|
const parsed = Number(raw)
|
||||||
|
if (!Number.isFinite(parsed)) return 0
|
||||||
|
return parsed > 0xffffffff ? parsed >>> 0 : parsed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let dbRef: WechatDb | null = null
|
||||||
|
|
||||||
|
export function setChatDb(db: WechatDb | null): void {
|
||||||
|
dbRef?.close()
|
||||||
|
dbRef = db
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getChatDb(): WechatDb | null {
|
||||||
|
return dbRef
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isReady(): boolean {
|
||||||
|
return dbRef !== null
|
||||||
|
}
|
||||||
|
|
||||||
|
export function listContacts(filter?: string): FormattedContact[] {
|
||||||
|
if (!dbRef) return []
|
||||||
|
|
||||||
|
const contacts: FormattedContact[] = []
|
||||||
|
const groupContacts = dbRef.getAllGroupContacts()
|
||||||
|
const userList = dbRef.getUserList(filter)
|
||||||
|
const existingMd5s = new Set<string>()
|
||||||
|
|
||||||
|
for (const user of userList) {
|
||||||
|
const md5 = dbRef.md5(user.m_nsUsrName)
|
||||||
|
const isGroup = user.m_nsUsrName.endsWith('@chatroom')
|
||||||
|
existingMd5s.add(md5)
|
||||||
|
contacts.push({
|
||||||
|
m_nsUsrName: user.m_nsUsrName,
|
||||||
|
m_nsNickName: user.nickname || '未知用户',
|
||||||
|
md5,
|
||||||
|
type: isGroup ? 'group' : 'user',
|
||||||
|
avatar: typeof user.avatar === 'string' ? user.avatar : undefined
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const chatTables = dbRef.getAllChatTables()
|
||||||
|
for (const table of chatTables) {
|
||||||
|
if (!table.name.startsWith('Chat_')) continue
|
||||||
|
const md5 = table.name.substring(5)
|
||||||
|
if (existingMd5s.has(md5)) continue
|
||||||
|
if (groupContacts[md5]) {
|
||||||
|
contacts.push({
|
||||||
|
m_nsUsrName: `Group_${md5}`,
|
||||||
|
m_nsNickName: groupContacts[md5],
|
||||||
|
md5,
|
||||||
|
type: 'group'
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
contacts.push({
|
||||||
|
m_nsUsrName: `Unknown_${md5}`,
|
||||||
|
m_nsNickName: `Chat_${md5}`,
|
||||||
|
md5,
|
||||||
|
type: 'user'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return contacts
|
||||||
|
}
|
||||||
|
|
||||||
|
export function listMessages(
|
||||||
|
userMd5: string,
|
||||||
|
startTime?: number,
|
||||||
|
endTime?: number
|
||||||
|
): FormattedMessage[] {
|
||||||
|
if (!dbRef) return []
|
||||||
|
|
||||||
|
const wcdb4Client = dbRef.getWcdb4Client()
|
||||||
|
const username = wcdb4Client.getUsernameByMd5(userMd5)
|
||||||
|
const rawMessages = dbRef.getUserMessages(userMd5, startTime, endTime)
|
||||||
|
const groupMembers = dbRef.getGroupMembersForChat(userMd5)
|
||||||
|
const myAvatar = dbRef.getMyAvatarUrl()
|
||||||
|
const myGroupNickname = username?.endsWith('@chatroom')
|
||||||
|
? wcdb4Client.getMyGroupNickname(username)
|
||||||
|
: undefined
|
||||||
|
|
||||||
|
return rawMessages.map((msg: WechatMessage) => {
|
||||||
|
const rawMsgType = parseInt(msg.messageType)
|
||||||
|
const msgType = normalizeMsgType(msg.messageType)
|
||||||
|
const createTime = parseInt(msg.msgCreateTime)
|
||||||
|
const date = new Date(createTime * 1000)
|
||||||
|
const isMine = msg.mesDes !== 1
|
||||||
|
const localId = parseInt(msg.mesLocalID) || 0
|
||||||
|
|
||||||
|
let content = msg.msgContent
|
||||||
|
let img = ''
|
||||||
|
let name = ''
|
||||||
|
if (isMine) {
|
||||||
|
if (myAvatar) img = myAvatar
|
||||||
|
name = myGroupNickname || (typeof msg.senderNickname === 'string' ? msg.senderNickname : '')
|
||||||
|
} else {
|
||||||
|
if (typeof msg.senderAvatar === 'string') img = msg.senderAvatar
|
||||||
|
if (typeof msg.senderNickname === 'string') name = msg.senderNickname
|
||||||
|
}
|
||||||
|
if (content && typeof content === 'string') {
|
||||||
|
const colonIndex = content.indexOf(':')
|
||||||
|
if (colonIndex > 0) {
|
||||||
|
const potentialWxid = content.substring(0, colonIndex)
|
||||||
|
if (potentialWxid.startsWith('wxid_')) {
|
||||||
|
const member = dbRef!.getGroupMember(potentialWxid)
|
||||||
|
if (member) img = member.m_nsHeadImgUrl
|
||||||
|
if (groupMembers[potentialWxid]) {
|
||||||
|
name = groupMembers[potentialWxid]
|
||||||
|
content = content.substring(colonIndex + 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let contentData: ReturnType<typeof parseMessageContent> | undefined
|
||||||
|
let displayType = MSG_TYPE_DICT[msgType] || msg.messageType
|
||||||
|
const inferredMsgType =
|
||||||
|
typeof content === 'string' &&
|
||||||
|
/<appmsg\b|<refermsg\b|<appmsg\b|<refermsg\b/i.test(content)
|
||||||
|
? 49
|
||||||
|
: msgType
|
||||||
|
if ([3, 42, 47, 48, 49, 50, 10000, 10002].includes(inferredMsgType)) {
|
||||||
|
try {
|
||||||
|
const parsed =
|
||||||
|
inferredMsgType === 47
|
||||||
|
? parseStickerMessageFromRow(msg, content)
|
||||||
|
: parseMessageContent(content, inferredMsgType)
|
||||||
|
if (parsed.type === 'system') {
|
||||||
|
content = parsed.content
|
||||||
|
contentData = parsed
|
||||||
|
} else if (parsed.type !== 'unknown') {
|
||||||
|
content = ''
|
||||||
|
}
|
||||||
|
if (parsed.type === 'image') {
|
||||||
|
const imageDatName = parseImageDatNameFromRow(msg)
|
||||||
|
contentData = { ...parsed, datName: parsed.datName || imageDatName }
|
||||||
|
} else if (parsed.type !== 'system') {
|
||||||
|
if (parsed.type === 'sticker' && !parsed.url && parsed.md5) {
|
||||||
|
parsed.url = wcdb4Client.resolveEmoticonCdnUrl(parsed.md5)
|
||||||
|
}
|
||||||
|
contentData = parsed
|
||||||
|
}
|
||||||
|
if (inferredMsgType !== msgType || rawMsgType !== msgType) {
|
||||||
|
displayType = MSG_TYPE_DICT[inferredMsgType] || displayType
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// ignore parse errors
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
!contentData &&
|
||||||
|
typeof content === 'string' &&
|
||||||
|
/^[0-9a-fA-F]{64,}$/.test(content.trim())
|
||||||
|
) {
|
||||||
|
const parsed = parseStickerMessageFromRow(msg, content)
|
||||||
|
if (parsed.type === 'sticker') {
|
||||||
|
if (!parsed.url && parsed.md5) {
|
||||||
|
parsed.url = wcdb4Client.resolveEmoticonCdnUrl(parsed.md5)
|
||||||
|
}
|
||||||
|
content = ''
|
||||||
|
contentData = parsed
|
||||||
|
displayType = '表情包'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msgType === 34) content = '[语音消息]'
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: msg.mesLocalID || Math.random().toString(),
|
||||||
|
from: contentData?.type === 'system' ? 'system' : isMine ? 'assistant' : 'user',
|
||||||
|
isSender: isMine,
|
||||||
|
type: displayType,
|
||||||
|
datetime: date.toLocaleString('zh-CN', { hour12: false }),
|
||||||
|
content,
|
||||||
|
img,
|
||||||
|
name,
|
||||||
|
sessionId: username,
|
||||||
|
localId,
|
||||||
|
createTime,
|
||||||
|
contentData
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getGroupSnapshot(userMd5: string): GroupSnapshot | null {
|
||||||
|
if (!dbRef) return null
|
||||||
|
const wcdb4Client = dbRef.getWcdb4Client()
|
||||||
|
const roomId = wcdb4Client.getUsernameByMd5(userMd5)
|
||||||
|
if (!roomId || !roomId.endsWith('@chatroom')) return null
|
||||||
|
|
||||||
|
const members = wcdb4Client
|
||||||
|
.getGroupMembers(roomId)
|
||||||
|
.filter((member) => member?.m_nsUsrName)
|
||||||
|
.map((member) => ({
|
||||||
|
wxid: member.m_nsUsrName,
|
||||||
|
nickname: member.nickname || '',
|
||||||
|
avatar: member.m_nsHeadImgUrl || ''
|
||||||
|
}))
|
||||||
|
|
||||||
|
return { roomId, memberCount: members.length, members }
|
||||||
|
}
|
||||||
|
|
||||||
|
export function searchMessages(keyword: string): string | null {
|
||||||
|
if (!dbRef) return null
|
||||||
|
return dbRef.searchAllMessages(keyword)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function listRecentChat(limit = 50): FormattedContact[] {
|
||||||
|
const contacts = listContacts()
|
||||||
|
return contacts.slice(0, limit)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resolveMd5(query: string): FormattedContact | null {
|
||||||
|
const trimmed = query.trim()
|
||||||
|
if (!trimmed) return null
|
||||||
|
const lower = trimmed.toLowerCase()
|
||||||
|
const contacts = listContacts()
|
||||||
|
|
||||||
|
const exact = contacts.find(
|
||||||
|
(c) =>
|
||||||
|
c.md5 === trimmed ||
|
||||||
|
c.m_nsUsrName.toLowerCase() === lower ||
|
||||||
|
c.m_nsNickName.toLowerCase() === lower
|
||||||
|
)
|
||||||
|
if (exact) return exact
|
||||||
|
|
||||||
|
const partial = contacts.find(
|
||||||
|
(c) =>
|
||||||
|
c.m_nsNickName.toLowerCase().includes(lower) ||
|
||||||
|
c.m_nsUsrName.toLowerCase().includes(lower)
|
||||||
|
)
|
||||||
|
return partial || null
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SelfAccountInfo {
|
||||||
|
wxid: string
|
||||||
|
nickname: string
|
||||||
|
avatar?: string
|
||||||
|
accountRoot: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getSelfAccountInfo(): SelfAccountInfo | null {
|
||||||
|
if (!dbRef) return null
|
||||||
|
const wcdb = dbRef.getWcdb4Client()
|
||||||
|
const accountRoot = wcdb.getAccountRoot()
|
||||||
|
const usernameCandidates = wcdb.getMyUsernameCandidates()
|
||||||
|
const primaryUsername = usernameCandidates[0] ?? ''
|
||||||
|
const wxid =
|
||||||
|
primaryUsername && primaryUsername.toLowerCase().startsWith('wxid_')
|
||||||
|
? primaryUsername
|
||||||
|
: wcdb.getUsernameByMd5(wcdb.md5(accountRoot.split('/').pop() || '')) || primaryUsername
|
||||||
|
|
||||||
|
let nickname = ''
|
||||||
|
let avatar: string | undefined
|
||||||
|
try {
|
||||||
|
avatar = wcdb.getMyAvatarUrl()
|
||||||
|
} catch {
|
||||||
|
avatar = undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
if (usernameCandidates.length) {
|
||||||
|
const contacts = listContacts()
|
||||||
|
const self = contacts.find(
|
||||||
|
(c) =>
|
||||||
|
usernameCandidates.includes(c.m_nsUsrName) ||
|
||||||
|
(c.type === 'user' && usernameCandidates.some((u) => c.m_nsUsrName.includes(u)))
|
||||||
|
)
|
||||||
|
if (self) {
|
||||||
|
nickname = self.m_nsNickName
|
||||||
|
avatar = avatar || self.avatar
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
wxid: wxid || primaryUsername || '',
|
||||||
|
nickname: nickname || wxid || '我',
|
||||||
|
avatar,
|
||||||
|
accountRoot
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function testConnection(
|
||||||
|
key: string,
|
||||||
|
accountRoot?: string
|
||||||
|
): { success: boolean; error?: string; accountRoot?: string; wxid?: string } {
|
||||||
|
try {
|
||||||
|
const probeKey = key.replace(/^0x/i, '').trim()
|
||||||
|
if (!probeKey) {
|
||||||
|
return { success: false, error: '密钥不能为空' }
|
||||||
|
}
|
||||||
|
const probe = accountRoot ? new WechatDb(probeKey, accountRoot) : new WechatDb(probeKey)
|
||||||
|
try {
|
||||||
|
probe.close()
|
||||||
|
} catch {
|
||||||
|
// best effort
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
accountRoot: probe.getWcdb4Client().getAccountRoot(),
|
||||||
|
wxid: (probe.getWcdb4Client().getMyUsernameCandidates?.() ?? [])[0] || ''
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: error instanceof Error ? error.message : String(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function reopenWithRoot(accountRoot: string): boolean {
|
||||||
|
if (!dbRef) return false
|
||||||
|
const key = getCurrentKey()
|
||||||
|
if (!key) return false
|
||||||
|
try {
|
||||||
|
const next = new WechatDb(key, accountRoot)
|
||||||
|
setChatDb(next)
|
||||||
|
return true
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[ChatService] reopen with root failed:', error)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
import { app } from 'electron'
|
||||||
|
import fs from 'fs-extra'
|
||||||
|
import path from 'path'
|
||||||
|
import os from 'os'
|
||||||
|
|
||||||
|
export interface AppSettings {
|
||||||
|
dbRoot: string
|
||||||
|
apiEnabled: boolean
|
||||||
|
apiHost: string
|
||||||
|
apiPort: number
|
||||||
|
}
|
||||||
|
|
||||||
|
const DEFAULT_SETTINGS: AppSettings = {
|
||||||
|
dbRoot: path.join(
|
||||||
|
os.homedir(),
|
||||||
|
'Library/Containers/com.tencent.xinWeChat/Data/Documents/xwechat_files'
|
||||||
|
),
|
||||||
|
apiEnabled: true,
|
||||||
|
apiHost: '127.0.0.1',
|
||||||
|
apiPort: 6131
|
||||||
|
}
|
||||||
|
|
||||||
|
const SETTINGS_FILE = path.join(
|
||||||
|
process.env['WE_SETTINGS_DIR'] || app.getPath('userData'),
|
||||||
|
'settings.json'
|
||||||
|
)
|
||||||
|
|
||||||
|
let cache: AppSettings | null = null
|
||||||
|
|
||||||
|
function ensureDir(): void {
|
||||||
|
fs.ensureDirSync(path.dirname(SETTINGS_FILE))
|
||||||
|
}
|
||||||
|
|
||||||
|
export function loadSettings(): AppSettings {
|
||||||
|
if (cache) return cache
|
||||||
|
try {
|
||||||
|
if (fs.existsSync(SETTINGS_FILE)) {
|
||||||
|
const raw = fs.readJsonSync(SETTINGS_FILE) as Partial<AppSettings>
|
||||||
|
cache = { ...DEFAULT_SETTINGS, ...raw }
|
||||||
|
return cache
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('[Settings] failed to load, fallback to defaults:', error)
|
||||||
|
}
|
||||||
|
cache = { ...DEFAULT_SETTINGS }
|
||||||
|
return cache
|
||||||
|
}
|
||||||
|
|
||||||
|
export function saveSettings(next: AppSettings): AppSettings {
|
||||||
|
cache = { ...next }
|
||||||
|
try {
|
||||||
|
ensureDir()
|
||||||
|
fs.writeJsonSync(SETTINGS_FILE, cache, { spaces: 2 })
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[Settings] failed to save:', error)
|
||||||
|
}
|
||||||
|
return cache
|
||||||
|
}
|
||||||
|
|
||||||
|
export function updateSettings(patch: Partial<AppSettings>): AppSettings {
|
||||||
|
return saveSettings({ ...loadSettings(), ...patch })
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resetSettings(): AppSettings {
|
||||||
|
cache = null
|
||||||
|
try {
|
||||||
|
if (fs.existsSync(SETTINGS_FILE)) fs.unlinkSync(SETTINGS_FILE)
|
||||||
|
} catch {
|
||||||
|
// best effort
|
||||||
|
}
|
||||||
|
return loadSettings()
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getSettingsPath(): string {
|
||||||
|
return SETTINGS_FILE
|
||||||
|
}
|
||||||
@@ -145,7 +145,9 @@ export class Wcdb4Client {
|
|||||||
|
|
||||||
constructor(key: string, accountRoot?: string) {
|
constructor(key: string, accountRoot?: string) {
|
||||||
this.key = key.replace(/^0x/i, '').trim()
|
this.key = key.replace(/^0x/i, '').trim()
|
||||||
this.accountRoot = accountRoot || Wcdb4Client.findLatestAccountRoot()
|
this.accountRoot = accountRoot
|
||||||
|
? Wcdb4Client.resolveAccountRoot(accountRoot)
|
||||||
|
: Wcdb4Client.findLatestAccountRoot()
|
||||||
this.wxid = Wcdb4Client.cleanAccountDirName(path.basename(this.accountRoot))
|
this.wxid = Wcdb4Client.cleanAccountDirName(path.basename(this.accountRoot))
|
||||||
this.dbStoragePath = path.join(this.accountRoot, 'db_storage')
|
this.dbStoragePath = path.join(this.accountRoot, 'db_storage')
|
||||||
this.sessionDbPath = this.findSessionDb()
|
this.sessionDbPath = this.findSessionDb()
|
||||||
@@ -155,6 +157,37 @@ export class Wcdb4Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static resolveAccountRoot(accountRoot: string): string {
|
||||||
|
const target = (accountRoot || '').trim().replace(/\/+$/, '')
|
||||||
|
if (!target) {
|
||||||
|
throw new Error('微信 4.0 账号目录不能为空')
|
||||||
|
}
|
||||||
|
if (fs.existsSync(path.join(target, 'db_storage'))) {
|
||||||
|
return target
|
||||||
|
}
|
||||||
|
if (!fs.existsSync(target)) {
|
||||||
|
throw new Error(`未找到微信 4.0 数据目录: ${target}`)
|
||||||
|
}
|
||||||
|
const candidates = fs
|
||||||
|
.readdirSync(target)
|
||||||
|
.map((name) => path.join(target, name))
|
||||||
|
.filter((candidate) => {
|
||||||
|
try {
|
||||||
|
return (
|
||||||
|
fs.statSync(candidate).isDirectory() &&
|
||||||
|
fs.existsSync(path.join(candidate, 'db_storage'))
|
||||||
|
)
|
||||||
|
} catch {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.sort((a, b) => fs.statSync(b).mtimeMs - fs.statSync(a).mtimeMs)
|
||||||
|
if (!candidates[0]) {
|
||||||
|
throw new Error(`未找到包含 db_storage 的微信 4.0 账号目录: ${target}`)
|
||||||
|
}
|
||||||
|
return candidates[0]
|
||||||
|
}
|
||||||
|
|
||||||
static findLatestAccountRoot(): string {
|
static findLatestAccountRoot(): string {
|
||||||
const root = Wcdb4Client.defaultRoot
|
const root = Wcdb4Client.defaultRoot
|
||||||
if (!fs.existsSync(root)) {
|
if (!fs.existsSync(root)) {
|
||||||
@@ -714,6 +747,10 @@ export class Wcdb4Client {
|
|||||||
return this.accountRoot
|
return this.accountRoot
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getKey(): string {
|
||||||
|
return this.key
|
||||||
|
}
|
||||||
|
|
||||||
resolveImageHardlink(md5: string): Wcdb4ImageHardlink | null {
|
resolveImageHardlink(md5: string): Wcdb4ImageHardlink | null {
|
||||||
if (!this.wcdbResolveImageHardlink) return null
|
if (!this.wcdbResolveImageHardlink) return null
|
||||||
const normalizedMd5 = String(md5 || '')
|
const normalizedMd5 = String(md5 || '')
|
||||||
@@ -1390,7 +1427,7 @@ export class Wcdb4Client {
|
|||||||
return Array.from(new Set(values.map((value) => value.trim()).filter(Boolean)))
|
return Array.from(new Set(values.map((value) => value.trim()).filter(Boolean)))
|
||||||
}
|
}
|
||||||
|
|
||||||
private getMyUsernameCandidates(): string[] {
|
getMyUsernameCandidates(): string[] {
|
||||||
const rawAccountName = path.basename(this.accountRoot)
|
const rawAccountName = path.basename(this.accountRoot)
|
||||||
return this.uniq([this.wxid, rawAccountName, Wcdb4Client.cleanAccountDirName(rawAccountName)])
|
return this.uniq([this.wxid, rawAccountName, Wcdb4Client.cleanAccountDirName(rawAccountName)])
|
||||||
}
|
}
|
||||||
|
|||||||
+67
-396
@@ -1,12 +1,5 @@
|
|||||||
import DatabaseConstructor from 'better-sqlite3-multiple-ciphers'
|
|
||||||
import fs from 'fs-extra'
|
|
||||||
import path from 'path'
|
|
||||||
import crypto from 'crypto'
|
|
||||||
import os from 'os'
|
|
||||||
import { Wcdb4Client } from './wcdb4-client'
|
import { Wcdb4Client } from './wcdb4-client'
|
||||||
|
|
||||||
type Database = import('better-sqlite3-multiple-ciphers').Database
|
|
||||||
|
|
||||||
export interface UserContact {
|
export interface UserContact {
|
||||||
m_nsUsrName: string
|
m_nsUsrName: string
|
||||||
nickname: string
|
nickname: string
|
||||||
@@ -38,444 +31,122 @@ export interface GroupMemberInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class WechatDb {
|
export class WechatDb {
|
||||||
private static WECHAT_DIR = path.join(
|
private wcdb4Client: Wcdb4Client
|
||||||
os.homedir(),
|
|
||||||
'Library/Containers/com.tencent.xinWeChat/Data/Library/Application Support/com.tencent.xinWeChat/2.0b4.0.9'
|
|
||||||
)
|
|
||||||
|
|
||||||
private rawKey: string
|
|
||||||
private correctUserId: string | null = null
|
|
||||||
private chatDb: { name: string; db_number: string }[] | null = null
|
|
||||||
private groupMemberCache = new Map<string, GroupMemberInfo | null>()
|
|
||||||
private wcdb4Client: Wcdb4Client | null = null
|
|
||||||
private chatMd5ToUsername = new Map<string, string>()
|
private chatMd5ToUsername = new Map<string, string>()
|
||||||
private wechat4OpenError: string | null = null
|
|
||||||
|
|
||||||
constructor(rawKey: string) {
|
constructor(rawKey: string, accountRoot?: string) {
|
||||||
this.rawKey = rawKey
|
|
||||||
console.log(`Initializing WechatDb with key length: ${rawKey.trim().length}`)
|
console.log(`Initializing WechatDb with key length: ${rawKey.trim().length}`)
|
||||||
|
const client = new Wcdb4Client(rawKey, accountRoot)
|
||||||
if (this.tryOpenWechat4()) {
|
client.open()
|
||||||
this.chatDb = this.getChatDbNumber()
|
this.wcdb4Client = client
|
||||||
return
|
for (const table of client.getChatTables()) {
|
||||||
}
|
if (table.name.startsWith('Chat_')) {
|
||||||
|
this.chatMd5ToUsername.set(table.name.substring(5), table.db_number)
|
||||||
if (!fs.existsSync(WechatDb.WECHAT_DIR)) {
|
|
||||||
throw new Error(`WeChat directory not found at ${WechatDb.WECHAT_DIR}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.getUser()) {
|
|
||||||
console.log('User found, getting chat DB number')
|
|
||||||
this.chatDb = this.getChatDbNumber()
|
|
||||||
} else {
|
|
||||||
throw new Error(
|
|
||||||
`No valid user found or invalid key${this.wechat4OpenError ? `; WeChat 4.0 error: ${this.wechat4OpenError}` : ''}`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private tryOpenWechat4(): boolean {
|
|
||||||
try {
|
|
||||||
const client = new Wcdb4Client(this.rawKey)
|
|
||||||
client.open()
|
|
||||||
this.wcdb4Client = client
|
|
||||||
console.log('Opened WeChat 4.0 database with WechatExplorer WCDB native adapter')
|
|
||||||
return true
|
|
||||||
} catch (error) {
|
|
||||||
this.wechat4OpenError = error instanceof Error ? error.message : String(error)
|
|
||||||
console.warn('WeChat 4.0 open failed, fallback to 3.0 SQLCipher mode:', error)
|
|
||||||
this.wcdb4Client = null
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private connectDb(dbPath: string): Database | null {
|
|
||||||
const targetPath = path.resolve(dbPath)
|
|
||||||
if (!fs.existsSync(targetPath)) {
|
|
||||||
console.error(`❌ 错误:数据库文件不存在于路径:${targetPath}`)
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const db = new DatabaseConstructor(targetPath, {
|
|
||||||
// verbose: console.log
|
|
||||||
})
|
|
||||||
|
|
||||||
// 配置加密方案 (Cipher Scheme)
|
|
||||||
db.pragma("cipher='sqlcipher'")
|
|
||||||
db.pragma('cipher_page_size = 1024')
|
|
||||||
db.pragma('legacy=3')
|
|
||||||
db.pragma('kdf_iter = 64000')
|
|
||||||
db.pragma('cipher_hmac_algorithm = HMAC_SHA1')
|
|
||||||
db.pragma('cipher_kdf_algorithm = PBKDF2_HMAC_SHA1')
|
|
||||||
|
|
||||||
const processedKey = this.processRawKey(this.rawKey)
|
|
||||||
// console.log(`🔑 应用密钥 (前6位): ${processedKey.substring(0, 6)}...`)
|
|
||||||
|
|
||||||
db.pragma(`key = "x'${processedKey}'"`)
|
|
||||||
|
|
||||||
// 验证连接
|
|
||||||
db.prepare('SELECT count(*) as count FROM sqlite_master').get()
|
|
||||||
|
|
||||||
return db
|
|
||||||
} catch (error) {
|
|
||||||
console.error(`❌ 连接失败:`, error)
|
|
||||||
|
|
||||||
const errString = String(error)
|
|
||||||
if (errString.includes('file is not a database')) {
|
|
||||||
console.error(
|
|
||||||
"💡 诊断建议:\n1. 请确认是否已安装 'better-sqlite3-multiple-ciphers'。\n2. 检查密钥是否正确(WeChat密钥与设备强绑定)。\n3. 尝试将页大小改为 4096 (db.pragma('cipher_page_size = 4096'))。"
|
|
||||||
)
|
|
||||||
} else if (errString.includes('HMAC')) {
|
|
||||||
console.error(
|
|
||||||
'💡 诊断建议:密钥可能正确,但HMAC算法或页大小不匹配。尝试调整 cipher_hmac_algorithm。'
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private processRawKey(key: string): string {
|
|
||||||
// 移除可能的 '0x' 前缀并修剪空格
|
|
||||||
return key.replace(/^0x/i, '').trim()
|
|
||||||
}
|
|
||||||
|
|
||||||
private getUser(): boolean {
|
|
||||||
const keyValuePath = path.join(WechatDb.WECHAT_DIR, 'KeyValue')
|
|
||||||
if (!fs.existsSync(keyValuePath)) return false
|
|
||||||
|
|
||||||
const contents = fs.readdirSync(keyValuePath)
|
|
||||||
const potentialUsers = contents.filter((name) => !name.startsWith('.'))
|
|
||||||
|
|
||||||
for (const user of potentialUsers) {
|
|
||||||
const dbPath = path.join(keyValuePath, user, 'KeyValue.db')
|
|
||||||
if (fs.existsSync(dbPath)) {
|
|
||||||
const db = this.connectDb(dbPath)
|
|
||||||
if (db) {
|
|
||||||
this.correctUserId = user
|
|
||||||
console.log(`Valid user found: ${user}`)
|
|
||||||
db.close()
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
private getChatDbNumber(): { name: string; db_number: string }[] {
|
|
||||||
if (this.wcdb4Client) {
|
|
||||||
const chatDb = this.wcdb4Client.getChatTables()
|
|
||||||
this.chatMd5ToUsername.clear()
|
|
||||||
for (const table of chatDb) {
|
|
||||||
if (table.name.startsWith('Chat_')) {
|
|
||||||
this.chatMd5ToUsername.set(table.name.substring(5), table.db_number)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return chatDb
|
|
||||||
}
|
|
||||||
|
|
||||||
const chatDb: { name: string; db_number: string }[] = []
|
|
||||||
if (!this.correctUserId) return []
|
|
||||||
|
|
||||||
for (let i = 0; i < 10; i++) {
|
|
||||||
const dbPath = path.join(WechatDb.WECHAT_DIR, this.correctUserId, 'Message', `msg_${i}.db`)
|
|
||||||
if (!fs.existsSync(dbPath)) continue
|
|
||||||
|
|
||||||
const db = this.connectDb(dbPath)
|
|
||||||
if (db) {
|
|
||||||
const tables = db
|
|
||||||
.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name LIKE 'Chat_%'")
|
|
||||||
.all() as { name: string }[]
|
|
||||||
for (const table of tables) {
|
|
||||||
chatDb.push({ name: table.name, db_number: `msg_${i}.db` })
|
|
||||||
}
|
|
||||||
db.close()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return chatDb
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public getUserList(nicknameFilter?: string): UserContact[] {
|
public getUserList(nicknameFilter?: string): UserContact[] {
|
||||||
if (this.wcdb4Client) {
|
const keyword = (nicknameFilter || '').trim().toLowerCase()
|
||||||
const keyword = (nicknameFilter || '').trim().toLowerCase()
|
return this.wcdb4Client
|
||||||
return this.wcdb4Client
|
.getSessions()
|
||||||
.getSessions()
|
.map((session) => ({
|
||||||
.map((session) => ({
|
m_nsUsrName: session.username,
|
||||||
m_nsUsrName: session.username,
|
nickname: session.nickname || session.username,
|
||||||
nickname: session.nickname || session.username,
|
avatar: session.avatar
|
||||||
avatar: session.avatar
|
}))
|
||||||
}))
|
.filter((contact) => {
|
||||||
.filter((contact) => {
|
if (!keyword) return true
|
||||||
if (!keyword) return true
|
return (
|
||||||
return (
|
contact.m_nsUsrName.toLowerCase().includes(keyword) ||
|
||||||
contact.m_nsUsrName.toLowerCase().includes(keyword) ||
|
contact.nickname.toLowerCase().includes(keyword)
|
||||||
contact.nickname.toLowerCase().includes(keyword)
|
)
|
||||||
)
|
})
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.correctUserId) return []
|
|
||||||
const dbPath = path.join(WechatDb.WECHAT_DIR, this.correctUserId, 'Contact/wccontact_new2.db')
|
|
||||||
const db = this.connectDb(dbPath)
|
|
||||||
if (!db) return []
|
|
||||||
|
|
||||||
let query = "SELECT m_nsUsrName, nickname FROM WCContact WHERE m_nsUsrName NOT LIKE 'gh_%'"
|
|
||||||
if (nicknameFilter) {
|
|
||||||
query += ` AND nickname LIKE '%${nicknameFilter}%'`
|
|
||||||
}
|
|
||||||
|
|
||||||
const results = db.prepare(query).all() as unknown as UserContact[]
|
|
||||||
db.close()
|
|
||||||
return results
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public getAllGroupContacts(): Record<string, string> {
|
public getAllGroupContacts(): Record<string, string> {
|
||||||
if (this.wcdb4Client) {
|
|
||||||
const groupContacts: Record<string, string> = {}
|
|
||||||
for (const session of this.wcdb4Client.getSessions()) {
|
|
||||||
if (session.username.endsWith('@chatroom')) {
|
|
||||||
groupContacts[this.md5(session.username)] = session.nickname || session.username
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return groupContacts
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.correctUserId) return {}
|
|
||||||
const dbPath = path.join(WechatDb.WECHAT_DIR, this.correctUserId, 'Group/group_new.db')
|
|
||||||
const db = this.connectDb(dbPath)
|
|
||||||
if (!db) return {}
|
|
||||||
|
|
||||||
const results = db.prepare('SELECT m_nsUsrName, nickname FROM GroupContact').all() as {
|
|
||||||
m_nsUsrName: string
|
|
||||||
nickname: string
|
|
||||||
}[]
|
|
||||||
db.close()
|
|
||||||
|
|
||||||
const groupContacts: Record<string, string> = {}
|
const groupContacts: Record<string, string> = {}
|
||||||
for (const row of results) {
|
for (const session of this.wcdb4Client.getSessions()) {
|
||||||
if (row.m_nsUsrName && row.nickname) {
|
if (session.username.endsWith('@chatroom')) {
|
||||||
const md5 = this.md5(row.m_nsUsrName)
|
groupContacts[this.md5(session.username)] = session.nickname || session.username
|
||||||
groupContacts[md5] = row.nickname
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return groupContacts
|
return groupContacts
|
||||||
}
|
}
|
||||||
|
|
||||||
public getAllGroupMembers(): Record<string, string> {
|
public getAllGroupMembers(): Record<string, string> {
|
||||||
if (this.wcdb4Client) {
|
const members: Record<string, string> = {}
|
||||||
const members: Record<string, string> = {}
|
for (const session of this.wcdb4Client.getSessions()) {
|
||||||
for (const session of this.wcdb4Client.getSessions()) {
|
if (!session.username.endsWith('@chatroom')) continue
|
||||||
if (!session.username.endsWith('@chatroom')) continue
|
for (const member of this.wcdb4Client.getGroupMembers(session.username)) {
|
||||||
for (const member of this.wcdb4Client.getGroupMembers(session.username)) {
|
|
||||||
if (member.m_nsUsrName) {
|
|
||||||
members[member.m_nsUsrName] = member.nickname || member.m_nsUsrName
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return members
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.correctUserId) return {}
|
|
||||||
const dbPath = path.join(WechatDb.WECHAT_DIR, this.correctUserId, 'Group/group_new.db')
|
|
||||||
const db = this.connectDb(dbPath)
|
|
||||||
if (!db) return {}
|
|
||||||
|
|
||||||
// 查询 GroupMember 表
|
|
||||||
const results = db.prepare('SELECT m_nsUsrName, nickname FROM GroupMember').all() as {
|
|
||||||
m_nsUsrName: string
|
|
||||||
nickname: string
|
|
||||||
}[]
|
|
||||||
db.close()
|
|
||||||
|
|
||||||
const groupMembers: Record<string, string> = {}
|
|
||||||
for (const row of results) {
|
|
||||||
if (row.m_nsUsrName && row.nickname) {
|
|
||||||
// 将 wxid (m_nsUsrName) 映射到昵称
|
|
||||||
groupMembers[row.m_nsUsrName] = row.nickname
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return groupMembers
|
|
||||||
}
|
|
||||||
|
|
||||||
public getGroupMembersForChat(userMd5: string): Record<string, string> {
|
|
||||||
if (this.wcdb4Client) {
|
|
||||||
const username = this.chatMd5ToUsername.get(userMd5)
|
|
||||||
if (!username || !username.endsWith('@chatroom')) return {}
|
|
||||||
|
|
||||||
const members: Record<string, string> = {}
|
|
||||||
for (const member of this.wcdb4Client.getGroupMembers(username)) {
|
|
||||||
if (member.m_nsUsrName) {
|
if (member.m_nsUsrName) {
|
||||||
members[member.m_nsUsrName] = member.nickname || member.m_nsUsrName
|
members[member.m_nsUsrName] = member.nickname || member.m_nsUsrName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return members
|
|
||||||
}
|
}
|
||||||
|
return members
|
||||||
|
}
|
||||||
|
|
||||||
return this.getAllGroupMembers()
|
public getGroupMembersForChat(userMd5: string): Record<string, string> {
|
||||||
|
const username = this.chatMd5ToUsername.get(userMd5)
|
||||||
|
if (!username || !username.endsWith('@chatroom')) return {}
|
||||||
|
|
||||||
|
const members: Record<string, string> = {}
|
||||||
|
for (const member of this.wcdb4Client.getGroupMembers(username)) {
|
||||||
|
if (member.m_nsUsrName) {
|
||||||
|
members[member.m_nsUsrName] = member.nickname || member.m_nsUsrName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return members
|
||||||
}
|
}
|
||||||
|
|
||||||
public getGroupMember(wxid: string, chatroomId?: string): GroupMemberInfo | null {
|
public getGroupMember(wxid: string, chatroomId?: string): GroupMemberInfo | null {
|
||||||
if (this.wcdb4Client && chatroomId) {
|
if (!chatroomId) return null
|
||||||
return (
|
return (
|
||||||
this.wcdb4Client
|
this.wcdb4Client
|
||||||
.getGroupMembers(chatroomId)
|
.getGroupMembers(chatroomId)
|
||||||
.find((member) => member.m_nsUsrName === wxid) || null
|
.find((member) => member.m_nsUsrName === wxid) || null
|
||||||
)
|
)
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.correctUserId) return null
|
|
||||||
|
|
||||||
// 检查缓存
|
|
||||||
if (this.groupMemberCache.has(wxid)) {
|
|
||||||
return this.groupMemberCache.get(wxid) || null
|
|
||||||
}
|
|
||||||
|
|
||||||
const dbPath = path.join(WechatDb.WECHAT_DIR, this.correctUserId, 'Group/group_new.db')
|
|
||||||
const db = this.connectDb(dbPath)
|
|
||||||
if (!db) {
|
|
||||||
this.groupMemberCache.set(wxid, null)
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = db
|
|
||||||
.prepare(
|
|
||||||
'SELECT m_nsUsrName, nickname, m_nsHeadImgUrl FROM GroupMember WHERE m_nsUsrName = ?'
|
|
||||||
)
|
|
||||||
.get(wxid) as GroupMemberInfo
|
|
||||||
|
|
||||||
db.close()
|
|
||||||
|
|
||||||
// 写入缓存
|
|
||||||
this.groupMemberCache.set(wxid, result || null)
|
|
||||||
|
|
||||||
return result || null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public getAllChatTables(): { name: string; db_number: string }[] {
|
public getAllChatTables(): { name: string; db_number: string }[] {
|
||||||
return this.chatDb || []
|
return this.wcdb4Client.getChatTables()
|
||||||
}
|
}
|
||||||
|
|
||||||
public getMyAvatarUrl(): string | undefined {
|
public getMyAvatarUrl(): string | undefined {
|
||||||
return this.wcdb4Client?.getMyAvatarUrl()
|
return this.wcdb4Client.getMyAvatarUrl()
|
||||||
}
|
}
|
||||||
|
|
||||||
public getWcdb4Client(): Wcdb4Client | null {
|
public getWcdb4Client(): Wcdb4Client {
|
||||||
return this.wcdb4Client
|
return this.wcdb4Client
|
||||||
}
|
}
|
||||||
|
|
||||||
public close(): void {
|
public close(): void {
|
||||||
this.wcdb4Client?.close()
|
this.wcdb4Client.close()
|
||||||
this.wcdb4Client = null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public getUserMessages(userMd5: string, startTime?: number, endTime?: number): WechatMessage[] {
|
public getUserMessages(userMd5: string, startTime?: number, endTime?: number): WechatMessage[] {
|
||||||
if (this.wcdb4Client) {
|
const username = this.chatMd5ToUsername.get(userMd5)
|
||||||
const username = this.chatMd5ToUsername.get(userMd5)
|
if (!username) return []
|
||||||
if (!username) return []
|
return this.wcdb4Client.getMessages(username, startTime, endTime).map((message) => ({
|
||||||
return this.wcdb4Client.getMessages(username, startTime, endTime).map((message) => ({
|
...message,
|
||||||
...message,
|
...message.raw
|
||||||
...message.raw
|
}))
|
||||||
}))
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.chatDb || !this.correctUserId) return []
|
|
||||||
|
|
||||||
const tableName = `Chat_${userMd5}`
|
|
||||||
const tableInfo = this.chatDb.find((t) => t.name === tableName)
|
|
||||||
|
|
||||||
if (!tableInfo) {
|
|
||||||
console.error(`No table found for ${tableName}`)
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
|
|
||||||
const dbPath = path.join(
|
|
||||||
WechatDb.WECHAT_DIR,
|
|
||||||
this.correctUserId,
|
|
||||||
'Message',
|
|
||||||
tableInfo.db_number
|
|
||||||
)
|
|
||||||
const db = this.connectDb(dbPath)
|
|
||||||
if (!db) return []
|
|
||||||
|
|
||||||
try {
|
|
||||||
let query = `SELECT * FROM ${tableName}`
|
|
||||||
const conditions: string[] = []
|
|
||||||
|
|
||||||
// console.log(startTime, endTime, 'time range')
|
|
||||||
|
|
||||||
if (startTime) {
|
|
||||||
conditions.push(`msgCreateTime >= ${startTime}`)
|
|
||||||
}
|
|
||||||
if (endTime) {
|
|
||||||
conditions.push(`msgCreateTime <= ${endTime}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (conditions.length > 0) {
|
|
||||||
query += ` WHERE ${conditions.join(' AND ')}`
|
|
||||||
}
|
|
||||||
|
|
||||||
// 添加排序以确保存储正确的顺序
|
|
||||||
query += ` ORDER BY msgCreateTime ASC`
|
|
||||||
|
|
||||||
const results = db.prepare(query).all() as unknown as WechatMessage[]
|
|
||||||
db.close()
|
|
||||||
return results
|
|
||||||
} catch (e) {
|
|
||||||
console.error(`Error querying messages for ${tableName}:`, e)
|
|
||||||
db.close()
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public searchAllMessages(keyword: string): string | null {
|
public searchAllMessages(keyword: string): string | null {
|
||||||
if (this.wcdb4Client) {
|
const lowerKeyword = keyword.trim().toLowerCase()
|
||||||
const lowerKeyword = keyword.trim().toLowerCase()
|
if (!lowerKeyword) return null
|
||||||
if (!lowerKeyword) return null
|
for (const session of this.wcdb4Client.getSessions()) {
|
||||||
for (const session of this.wcdb4Client.getSessions()) {
|
const found = this.wcdb4Client
|
||||||
const found = this.wcdb4Client
|
.getMessages(session.username)
|
||||||
.getMessages(session.username)
|
.some((message) => message.msgContent.toLowerCase().includes(lowerKeyword))
|
||||||
.some((message) => message.msgContent.toLowerCase().includes(lowerKeyword))
|
if (found) return `Chat_${this.md5(session.username)}`
|
||||||
if (found) return `Chat_${this.md5(session.username)}`
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.correctUserId) return null
|
|
||||||
|
|
||||||
for (let i = 0; i < 10; i++) {
|
|
||||||
const dbName = `msg_${i}.db`
|
|
||||||
const dbPath = path.join(WechatDb.WECHAT_DIR, this.correctUserId, 'Message', dbName)
|
|
||||||
if (!fs.existsSync(dbPath)) continue
|
|
||||||
|
|
||||||
const db = this.connectDb(dbPath)
|
|
||||||
if (!db) continue
|
|
||||||
|
|
||||||
const tables = db
|
|
||||||
.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name LIKE 'Chat_%'")
|
|
||||||
.all() as { name: string }[]
|
|
||||||
for (const table of tables) {
|
|
||||||
try {
|
|
||||||
// 首先检查 msgContent 列是否存在以避免错误?
|
|
||||||
// 或者像 Swift 代码中那样使用 try/catch "抑制错误"
|
|
||||||
const results = db
|
|
||||||
.prepare(`SELECT 1 FROM ${table.name} WHERE msgContent LIKE '%${keyword}%' LIMIT 1`)
|
|
||||||
.get()
|
|
||||||
if (results) {
|
|
||||||
console.log(`Found keyword in ${table.name} (${dbName})`)
|
|
||||||
db.close()
|
|
||||||
return table.name
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
// 忽略没有 msgContent 的表
|
|
||||||
}
|
|
||||||
}
|
|
||||||
db.close()
|
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
public md5(str: string): string {
|
public md5(str: string): string {
|
||||||
return crypto.createHash('md5').update(str).digest('hex')
|
return this.wcdb4Client.md5(str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+67
@@ -39,6 +39,11 @@ declare global {
|
|||||||
) => Promise<boolean | { success: boolean; error?: string; monitoring?: boolean }>
|
) => Promise<boolean | { success: boolean; error?: string; monitoring?: boolean }>
|
||||||
getContacts: (filter?: string) => Promise<Contact[]>
|
getContacts: (filter?: string) => Promise<Contact[]>
|
||||||
getMessages: (userMd5: string, startTime?: number, endTime?: number) => Promise<Message[]>
|
getMessages: (userMd5: string, startTime?: number, endTime?: number) => Promise<Message[]>
|
||||||
|
getGroupSnapshot: (userMd5: string) => Promise<{
|
||||||
|
roomId: string
|
||||||
|
memberCount: number
|
||||||
|
members: { wxid: string; nickname: string; avatar: string }[]
|
||||||
|
} | null>
|
||||||
search: (keyword: string) => Promise<string | null>
|
search: (keyword: string) => Promise<string | null>
|
||||||
aiChat: (
|
aiChat: (
|
||||||
messages: { role: string; content: string }[],
|
messages: { role: string; content: string }[],
|
||||||
@@ -73,9 +78,71 @@ declare global {
|
|||||||
warning?: string
|
warning?: string
|
||||||
}>
|
}>
|
||||||
pasteAndSaveDbKey: () => Promise<{ success: boolean; key?: string; error?: string }>
|
pasteAndSaveDbKey: () => Promise<{ success: boolean; key?: string; error?: string }>
|
||||||
|
saveDbKey: (key: string) => Promise<{ success: boolean; key?: string; error?: string }>
|
||||||
clearSavedDbKey: () => Promise<{ success: boolean; error?: string }>
|
clearSavedDbKey: () => Promise<{ success: boolean; error?: string }>
|
||||||
onWcdbChange: (callback: (payload: { type: string; json: string }) => void) => () => void
|
onWcdbChange: (callback: (payload: { type: string; json: string }) => void) => () => void
|
||||||
onDbKeyStatus: (callback: (payload: { message: string }) => void) => () => void
|
onDbKeyStatus: (callback: (payload: { message: string }) => void) => () => void
|
||||||
|
getSettings: () => Promise<{
|
||||||
|
settings: {
|
||||||
|
dbRoot: string
|
||||||
|
apiEnabled: boolean
|
||||||
|
apiHost: string
|
||||||
|
apiPort: number
|
||||||
|
}
|
||||||
|
settingsPath: string
|
||||||
|
}>
|
||||||
|
setSettings: (patch: Partial<{
|
||||||
|
dbRoot: string
|
||||||
|
apiEnabled: boolean
|
||||||
|
apiHost: string
|
||||||
|
apiPort: number
|
||||||
|
}>) => Promise<{
|
||||||
|
settings: {
|
||||||
|
dbRoot: string
|
||||||
|
apiEnabled: boolean
|
||||||
|
apiHost: string
|
||||||
|
apiPort: number
|
||||||
|
}
|
||||||
|
settingsPath: string
|
||||||
|
}>
|
||||||
|
getSelf: () => Promise<
|
||||||
|
| {
|
||||||
|
ready: true
|
||||||
|
info: { wxid: string; nickname: string; avatar?: string; accountRoot: string }
|
||||||
|
}
|
||||||
|
| { ready: false }
|
||||||
|
>
|
||||||
|
testConnection: (
|
||||||
|
key: string,
|
||||||
|
accountRoot?: string
|
||||||
|
) => Promise<{
|
||||||
|
success: boolean
|
||||||
|
error?: string
|
||||||
|
accountRoot?: string
|
||||||
|
wxid?: string
|
||||||
|
}>
|
||||||
|
reopenWithRoot: (accountRoot: string) => Promise<{
|
||||||
|
success: boolean
|
||||||
|
error?: string
|
||||||
|
info?: { wxid: string; nickname: string; avatar?: string; accountRoot: string }
|
||||||
|
}>
|
||||||
|
apiStatus: () => Promise<{
|
||||||
|
running: boolean
|
||||||
|
host: string
|
||||||
|
port: number
|
||||||
|
error?: string
|
||||||
|
}>
|
||||||
|
apiStart: (
|
||||||
|
host?: string,
|
||||||
|
port?: number
|
||||||
|
) => Promise<{ running: boolean; host: string; port: number; error?: string }>
|
||||||
|
apiStop: () => Promise<{ running: boolean; host: string; port: number; error?: string }>
|
||||||
|
apiToggle: (enabled: boolean) => Promise<{
|
||||||
|
running: boolean
|
||||||
|
host: string
|
||||||
|
port: number
|
||||||
|
error?: string
|
||||||
|
}>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-1
@@ -8,6 +8,7 @@ const api = {
|
|||||||
getContacts: (filter?: string) => ipcRenderer.invoke('db:getContacts', filter),
|
getContacts: (filter?: string) => ipcRenderer.invoke('db:getContacts', filter),
|
||||||
getMessages: (userMd5: string, startTime?: number, endTime?: number) =>
|
getMessages: (userMd5: string, startTime?: number, endTime?: number) =>
|
||||||
ipcRenderer.invoke('db:getMessages', userMd5, startTime, endTime),
|
ipcRenderer.invoke('db:getMessages', userMd5, startTime, endTime),
|
||||||
|
getGroupSnapshot: (userMd5: string) => ipcRenderer.invoke('db:getGroupSnapshot', userMd5),
|
||||||
search: (keyword: string) => ipcRenderer.invoke('db:search', keyword),
|
search: (keyword: string) => ipcRenderer.invoke('db:search', keyword),
|
||||||
aiChat: (
|
aiChat: (
|
||||||
messages: { role: string; content: string }[],
|
messages: { role: string; content: string }[],
|
||||||
@@ -27,6 +28,7 @@ const api = {
|
|||||||
getSavedDbKey: () => ipcRenderer.invoke('key:getSavedDbKey'),
|
getSavedDbKey: () => ipcRenderer.invoke('key:getSavedDbKey'),
|
||||||
autoGetDbKey: () => ipcRenderer.invoke('key:autoGetDbKey'),
|
autoGetDbKey: () => ipcRenderer.invoke('key:autoGetDbKey'),
|
||||||
pasteAndSaveDbKey: () => ipcRenderer.invoke('key:pasteAndSaveDbKey'),
|
pasteAndSaveDbKey: () => ipcRenderer.invoke('key:pasteAndSaveDbKey'),
|
||||||
|
saveDbKey: (key: string) => ipcRenderer.invoke('key:saveDbKey', key),
|
||||||
clearSavedDbKey: () => ipcRenderer.invoke('key:clearSavedDbKey'),
|
clearSavedDbKey: () => ipcRenderer.invoke('key:clearSavedDbKey'),
|
||||||
onWcdbChange: (callback: (payload: { type: string; json: string }) => void) => {
|
onWcdbChange: (callback: (payload: { type: string; json: string }) => void) => {
|
||||||
const listener = (
|
const listener = (
|
||||||
@@ -41,7 +43,17 @@ const api = {
|
|||||||
callback(payload)
|
callback(payload)
|
||||||
ipcRenderer.on('key:dbKeyStatus', listener)
|
ipcRenderer.on('key:dbKeyStatus', listener)
|
||||||
return () => ipcRenderer.removeListener('key:dbKeyStatus', listener)
|
return () => ipcRenderer.removeListener('key:dbKeyStatus', listener)
|
||||||
}
|
},
|
||||||
|
getSettings: () => ipcRenderer.invoke('settings:get'),
|
||||||
|
setSettings: (patch) => ipcRenderer.invoke('settings:set', patch),
|
||||||
|
getSelf: () => ipcRenderer.invoke('settings:getSelf'),
|
||||||
|
testConnection: (key: string, accountRoot?: string) =>
|
||||||
|
ipcRenderer.invoke('db:testConnection', key, accountRoot),
|
||||||
|
reopenWithRoot: (accountRoot: string) => ipcRenderer.invoke('db:reopenWithRoot', accountRoot),
|
||||||
|
apiStatus: () => ipcRenderer.invoke('api:getStatus'),
|
||||||
|
apiStart: (host?: string, port?: number) => ipcRenderer.invoke('api:start', host, port),
|
||||||
|
apiStop: () => ipcRenderer.invoke('api:stop'),
|
||||||
|
apiToggle: (enabled: boolean) => ipcRenderer.invoke('api:toggle', enabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.contextIsolated) {
|
if (process.contextIsolated) {
|
||||||
|
|||||||
+262
-17
@@ -1,8 +1,16 @@
|
|||||||
import React, { useState } from 'react'
|
import React, { useState } from 'react'
|
||||||
import { Sidebar } from './components/Sidebar'
|
import { Sidebar } from './components/Sidebar'
|
||||||
import ChatWindow from './components/ChatWindow'
|
import ChatWindow from './components/ChatWindow'
|
||||||
|
import { SettingsPanel } from './components/SettingsPanel'
|
||||||
import { Contact, Message } from '../../shared/types'
|
import { Contact, Message } from '../../shared/types'
|
||||||
|
|
||||||
|
interface SelfInfo {
|
||||||
|
wxid: string
|
||||||
|
nickname: string
|
||||||
|
avatar?: string
|
||||||
|
accountRoot: string
|
||||||
|
}
|
||||||
|
|
||||||
const MAC_KEY_FAQ_URL = 'https://github.com/hicccc77/WeFlow/blob/main/docs/MAC-KEY-FAQ.md'
|
const MAC_KEY_FAQ_URL = 'https://github.com/hicccc77/WeFlow/blob/main/docs/MAC-KEY-FAQ.md'
|
||||||
const MESSAGE_MONITOR_DEBOUNCE_MS = 250
|
const MESSAGE_MONITOR_DEBOUNCE_MS = 250
|
||||||
|
|
||||||
@@ -21,6 +29,67 @@ const areMessagesEquivalent = (left: Message[], right: Message[]): boolean => {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GroupSnapshot = {
|
||||||
|
roomId: string
|
||||||
|
memberCount: number
|
||||||
|
members: { wxid: string; nickname: string; avatar: string }[]
|
||||||
|
}
|
||||||
|
|
||||||
|
const formatGroupMemberName = (member: GroupSnapshot['members'][number]): string =>
|
||||||
|
member.nickname || member.wxid
|
||||||
|
|
||||||
|
const buildSyntheticGroupMessages = (
|
||||||
|
previous: GroupSnapshot | null,
|
||||||
|
next: GroupSnapshot | null,
|
||||||
|
referenceMessages: Message[]
|
||||||
|
): Message[] => {
|
||||||
|
if (!previous || !next || previous.roomId !== next.roomId) return []
|
||||||
|
|
||||||
|
const previousMap = new Map(previous.members.map((member) => [member.wxid, member]))
|
||||||
|
const nextMap = new Map(next.members.map((member) => [member.wxid, member]))
|
||||||
|
const latestMessageTime = referenceMessages.reduce(
|
||||||
|
(max, message) => Math.max(max, message.createTime || 0),
|
||||||
|
0
|
||||||
|
)
|
||||||
|
const fallbackNow = Math.floor(Date.now() / 1000)
|
||||||
|
const events: Message[] = []
|
||||||
|
|
||||||
|
let offset = 1
|
||||||
|
for (const [wxid, member] of previousMap.entries()) {
|
||||||
|
if (nextMap.has(wxid)) continue
|
||||||
|
const name = formatGroupMemberName(member)
|
||||||
|
const eventTime = Math.max(latestMessageTime + offset, fallbackNow)
|
||||||
|
const eventDate = new Date(eventTime * 1000)
|
||||||
|
offset += 1
|
||||||
|
events.push({
|
||||||
|
id: `synthetic-leave:${next.roomId}:${wxid}:${eventTime}`,
|
||||||
|
from: 'system',
|
||||||
|
type: '系统消息',
|
||||||
|
datetime: eventDate.toLocaleString('zh-CN', { hour12: false }),
|
||||||
|
content: `${name} 退出了群聊`,
|
||||||
|
isSender: false,
|
||||||
|
createTime: eventTime
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (events.length) {
|
||||||
|
console.log(
|
||||||
|
`[GroupMonitor] synthetic leave detected roomId=${next.roomId} events=${events
|
||||||
|
.map((event) => event.content)
|
||||||
|
.join(' | ')}`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return events
|
||||||
|
}
|
||||||
|
|
||||||
|
const sortMessagesChronologically = (items: Message[]): Message[] =>
|
||||||
|
[...items].sort((left, right) => {
|
||||||
|
const timeDelta = (left.createTime || 0) - (right.createTime || 0)
|
||||||
|
if (timeDelta !== 0) return timeDelta
|
||||||
|
return getMessageIdentity(left).localeCompare(getMessageIdentity(right))
|
||||||
|
})
|
||||||
|
|
||||||
function App(): React.ReactElement {
|
function App(): React.ReactElement {
|
||||||
const [isAuthenticated, setIsAuthenticated] = useState(false)
|
const [isAuthenticated, setIsAuthenticated] = useState(false)
|
||||||
const [dbKey, setDbKey] = useState(import.meta.env.VITE_DB_KEY || '')
|
const [dbKey, setDbKey] = useState(import.meta.env.VITE_DB_KEY || '')
|
||||||
@@ -35,18 +104,87 @@ function App(): React.ReactElement {
|
|||||||
const [dbKeyStatusKind, setDbKeyStatusKind] = useState<'normal' | 'success' | 'error'>('normal')
|
const [dbKeyStatusKind, setDbKeyStatusKind] = useState<'normal' | 'success' | 'error'>('normal')
|
||||||
const [showDbKey, setShowDbKey] = useState(false)
|
const [showDbKey, setShowDbKey] = useState(false)
|
||||||
const [showMacKeyFaq, setShowMacKeyFaq] = useState(false)
|
const [showMacKeyFaq, setShowMacKeyFaq] = useState(false)
|
||||||
|
const [showSettings, setShowSettings] = useState(false)
|
||||||
|
const [selfInfo, setSelfInfo] = useState<SelfInfo | null>(null)
|
||||||
const [isNativeMonitorActive, setIsNativeMonitorActive] = useState(false)
|
const [isNativeMonitorActive, setIsNativeMonitorActive] = useState(false)
|
||||||
|
const [bootState, setBootState] = useState<'loading' | 'connecting' | 'login'>('loading')
|
||||||
|
const [autoConnectSource, setAutoConnectSource] = useState<'env' | 'saved' | null>(null)
|
||||||
|
const currentGroupSnapshotRef = React.useRef<GroupSnapshot | null>(null)
|
||||||
|
const syntheticGroupMessagesRef = React.useRef<Record<string, Message[]>>({})
|
||||||
|
|
||||||
|
const refreshSelfInfo = async (): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const result = await window.api.getSelf()
|
||||||
|
if (result.ready) {
|
||||||
|
setSelfInfo(result.info)
|
||||||
|
} else {
|
||||||
|
setSelfInfo(null)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('[SelfInfo] 加载失败:', error)
|
||||||
|
setSelfInfo(null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const loadContacts = async (): Promise<void> => {
|
||||||
|
const list = await window.api.getContacts()
|
||||||
|
setContacts(list)
|
||||||
|
setFilteredContacts(list)
|
||||||
|
}
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
let active = true
|
let active = true
|
||||||
void window.api.getSavedDbKey().then((result) => {
|
const attemptAutoConnect = async (): Promise<void> => {
|
||||||
if (!active) return
|
// 优先级 1:构建期环境变量 VITE_DB_KEY(本地开发/打包时硬编码的密钥)
|
||||||
if (result.success && result.key) {
|
const envKey = String(import.meta.env.VITE_DB_KEY || '').trim()
|
||||||
setDbKey(result.key)
|
// 优先级 2:上一次保存到 safeStorage 的密钥
|
||||||
setDbKeyStatus('已加载安全保存的密钥')
|
let savedKey = ''
|
||||||
setDbKeyStatusKind('success')
|
if (!envKey) {
|
||||||
|
const result = await window.api.getSavedDbKey()
|
||||||
|
if (result.success && result.key) savedKey = result.key
|
||||||
}
|
}
|
||||||
})
|
const key = envKey || savedKey
|
||||||
|
if (!key) {
|
||||||
|
if (active) setBootState('login')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (active) {
|
||||||
|
setBootState('connecting')
|
||||||
|
setDbKey(key)
|
||||||
|
setAutoConnectSource(envKey ? 'env' : 'saved')
|
||||||
|
setDbKeyStatus(
|
||||||
|
envKey ? '检测到环境变量中的密钥,正在自动连接...' : '已加载安全保存的密钥,正在自动连接...'
|
||||||
|
)
|
||||||
|
setDbKeyStatusKind('normal')
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const result = await window.api.initDb(key)
|
||||||
|
if (!active) return
|
||||||
|
const success = typeof result === 'boolean' ? result : result.success
|
||||||
|
if (success) {
|
||||||
|
setIsNativeMonitorActive(typeof result !== 'boolean' && result.monitoring === true)
|
||||||
|
setIsAuthenticated(true)
|
||||||
|
setDbKeyStatus('已自动连接')
|
||||||
|
setDbKeyStatusKind('success')
|
||||||
|
await loadContacts()
|
||||||
|
void refreshSelfInfo()
|
||||||
|
} else {
|
||||||
|
const error = typeof result === 'boolean' ? '' : result.error
|
||||||
|
setDbKeyStatus(
|
||||||
|
`自动连接失败,请重新输入${error ? `: ${error}` : ''}`
|
||||||
|
)
|
||||||
|
setDbKeyStatusKind('error')
|
||||||
|
setBootState('login')
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
if (!active) return
|
||||||
|
const message = error instanceof Error ? error.message : String(error)
|
||||||
|
setDbKeyStatus(`自动连接失败: ${message}`)
|
||||||
|
setDbKeyStatusKind('error')
|
||||||
|
setBootState('login')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void attemptAutoConnect()
|
||||||
const unsubscribe = window.api.onDbKeyStatus(({ message }) => {
|
const unsubscribe = window.api.onDbKeyStatus(({ message }) => {
|
||||||
if (!active) return
|
if (!active) return
|
||||||
setDbKeyStatus(message)
|
setDbKeyStatus(message)
|
||||||
@@ -73,7 +211,10 @@ function App(): React.ReactElement {
|
|||||||
if (success) {
|
if (success) {
|
||||||
setIsNativeMonitorActive(typeof result !== 'boolean' && result.monitoring === true)
|
setIsNativeMonitorActive(typeof result !== 'boolean' && result.monitoring === true)
|
||||||
setIsAuthenticated(true)
|
setIsAuthenticated(true)
|
||||||
|
// 手动输入也持久化,下次启动可自动连接(参考 WeFlow)
|
||||||
|
void window.api.saveDbKey(keyToUse).catch(() => undefined)
|
||||||
loadContacts()
|
loadContacts()
|
||||||
|
void refreshSelfInfo()
|
||||||
} else {
|
} else {
|
||||||
const error = typeof result === 'boolean' ? '' : result.error
|
const error = typeof result === 'boolean' ? '' : result.error
|
||||||
alert(`Failed to open database.${error ? `\n\n${error}` : '\nCheck your key.'}`)
|
alert(`Failed to open database.${error ? `\n\n${error}` : '\nCheck your key.'}`)
|
||||||
@@ -84,6 +225,36 @@ function App(): React.ReactElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const logGroupSnapshot = React.useCallback(
|
||||||
|
async (contact: Contact | null, reason: string): Promise<GroupSnapshot | null> => {
|
||||||
|
if (!contact || contact.type !== 'group') return null
|
||||||
|
try {
|
||||||
|
const snapshot = (await window.api.getGroupSnapshot(contact.md5)) as GroupSnapshot | null
|
||||||
|
if (!snapshot) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return snapshot
|
||||||
|
} catch (error) {
|
||||||
|
console.warn(`[GroupSnapshot] reason=${reason} name=${contact.m_nsNickName} failed:`, error)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
)
|
||||||
|
|
||||||
|
const mergeSyntheticMessages = React.useCallback(
|
||||||
|
(contact: Contact | null, baseMessages: Message[], roomId?: string): Message[] => {
|
||||||
|
if (!contact || contact.type !== 'group') return baseMessages
|
||||||
|
const resolvedRoomId = roomId || currentGroupSnapshotRef.current?.roomId
|
||||||
|
if (!resolvedRoomId) return baseMessages
|
||||||
|
const synthetic = syntheticGroupMessagesRef.current[resolvedRoomId] || []
|
||||||
|
return synthetic.length
|
||||||
|
? sortMessagesChronologically([...baseMessages, ...synthetic])
|
||||||
|
: baseMessages
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
)
|
||||||
|
|
||||||
const handleAutoGetDbKey = async (): Promise<void> => {
|
const handleAutoGetDbKey = async (): Promise<void> => {
|
||||||
if (isFetchingDbKey) return
|
if (isFetchingDbKey) return
|
||||||
setIsFetchingDbKey(true)
|
setIsFetchingDbKey(true)
|
||||||
@@ -133,12 +304,6 @@ function App(): React.ReactElement {
|
|||||||
setDbKeyStatusKind('normal')
|
setDbKeyStatusKind('normal')
|
||||||
}
|
}
|
||||||
|
|
||||||
const loadContacts = async (): Promise<void> => {
|
|
||||||
const list = await window.api.getContacts()
|
|
||||||
setContacts(list)
|
|
||||||
setFilteredContacts(list)
|
|
||||||
}
|
|
||||||
|
|
||||||
const getDateRangeParams = (
|
const getDateRangeParams = (
|
||||||
range: string
|
range: string
|
||||||
): { startTime: number | undefined; endTime: number | undefined } => {
|
): { startTime: number | undefined; endTime: number | undefined } => {
|
||||||
@@ -175,14 +340,18 @@ function App(): React.ReactElement {
|
|||||||
setSelectedContact(contact)
|
setSelectedContact(contact)
|
||||||
const { startTime, endTime } = getDateRangeParams(dateRange)
|
const { startTime, endTime } = getDateRangeParams(dateRange)
|
||||||
const msgs = await window.api.getMessages(contact.md5, startTime, endTime)
|
const msgs = await window.api.getMessages(contact.md5, startTime, endTime)
|
||||||
setMessages(msgs)
|
const snapshot = await logGroupSnapshot(contact, 'select-contact')
|
||||||
|
currentGroupSnapshotRef.current = snapshot
|
||||||
|
setMessages(mergeSyntheticMessages(contact, msgs, snapshot?.roomId))
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleDateRangeChange = (range: string): void => {
|
const handleDateRangeChange = (range: string): void => {
|
||||||
setDateRange(range)
|
setDateRange(range)
|
||||||
if (selectedContact) {
|
if (selectedContact) {
|
||||||
const { startTime, endTime } = getDateRangeParams(range)
|
const { startTime, endTime } = getDateRangeParams(range)
|
||||||
window.api.getMessages(selectedContact.md5, startTime, endTime).then(setMessages)
|
window.api.getMessages(selectedContact.md5, startTime, endTime).then((nextMessages) => {
|
||||||
|
setMessages(mergeSyntheticMessages(selectedContact, nextMessages))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,9 +370,45 @@ function App(): React.ReactElement {
|
|||||||
range.startTime,
|
range.startTime,
|
||||||
range.endTime
|
range.endTime
|
||||||
)
|
)
|
||||||
|
const latestSnapshot = await logGroupSnapshot(selectedContact, 'wcdb-change')
|
||||||
|
const syntheticEvents = buildSyntheticGroupMessages(
|
||||||
|
currentGroupSnapshotRef.current,
|
||||||
|
latestSnapshot,
|
||||||
|
latestMessages
|
||||||
|
)
|
||||||
|
if (latestSnapshot) {
|
||||||
|
currentGroupSnapshotRef.current = latestSnapshot
|
||||||
|
if (syntheticEvents.length) {
|
||||||
|
const existing = syntheticGroupMessagesRef.current[latestSnapshot.roomId] || []
|
||||||
|
const existingIds = new Set(existing.map((message) => message.id))
|
||||||
|
const appended = syntheticEvents.filter((message) => !existingIds.has(message.id))
|
||||||
|
if (appended.length) {
|
||||||
|
syntheticGroupMessagesRef.current[latestSnapshot.roomId] = [...existing, ...appended]
|
||||||
|
console.log(
|
||||||
|
`[GroupMonitor] merged synthetic messages roomId=${latestSnapshot.roomId} total=${syntheticGroupMessagesRef.current[latestSnapshot.roomId].length}`
|
||||||
|
)
|
||||||
|
if (!disposed) {
|
||||||
|
setMessages((current) =>
|
||||||
|
sortMessagesChronologically([
|
||||||
|
...current,
|
||||||
|
...appended.filter(
|
||||||
|
(message) =>
|
||||||
|
!current.some((existingMessage) => existingMessage.id === message.id)
|
||||||
|
)
|
||||||
|
])
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const nextMessages = mergeSyntheticMessages(
|
||||||
|
selectedContact,
|
||||||
|
latestMessages,
|
||||||
|
latestSnapshot?.roomId
|
||||||
|
)
|
||||||
if (!disposed) {
|
if (!disposed) {
|
||||||
setMessages((current) =>
|
setMessages((current) =>
|
||||||
areMessagesEquivalent(current, latestMessages) ? current : latestMessages
|
areMessagesEquivalent(current, nextMessages) ? current : nextMessages
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -224,7 +429,14 @@ function App(): React.ReactElement {
|
|||||||
if (refreshTimer) window.clearTimeout(refreshTimer)
|
if (refreshTimer) window.clearTimeout(refreshTimer)
|
||||||
unsubscribe()
|
unsubscribe()
|
||||||
}
|
}
|
||||||
}, [dateRange, isAuthenticated, isNativeMonitorActive, selectedContact])
|
}, [
|
||||||
|
dateRange,
|
||||||
|
isAuthenticated,
|
||||||
|
isNativeMonitorActive,
|
||||||
|
selectedContact,
|
||||||
|
logGroupSnapshot,
|
||||||
|
mergeSyntheticMessages
|
||||||
|
])
|
||||||
|
|
||||||
const handleSearchContacts = (keyword: string): void => {
|
const handleSearchContacts = (keyword: string): void => {
|
||||||
if (!keyword) {
|
if (!keyword) {
|
||||||
@@ -269,6 +481,24 @@ function App(): React.ReactElement {
|
|||||||
}
|
}
|
||||||
}, [resize, stopResizing])
|
}, [resize, stopResizing])
|
||||||
|
|
||||||
|
if (!isAuthenticated && bootState !== 'login') {
|
||||||
|
return (
|
||||||
|
<div className="boot-splash">
|
||||||
|
<div className="boot-splash-spinner" aria-hidden />
|
||||||
|
<div className="boot-splash-title">
|
||||||
|
{bootState === 'connecting' ? '正在自动连接数据库...' : '正在准备...'}
|
||||||
|
</div>
|
||||||
|
<div className="boot-splash-subtitle">
|
||||||
|
{bootState === 'connecting'
|
||||||
|
? autoConnectSource === 'env'
|
||||||
|
? '检测到环境变量中的密钥'
|
||||||
|
: '使用上次安全保存的密钥'
|
||||||
|
: 'WechatExplorer'}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if (!isAuthenticated) {
|
if (!isAuthenticated) {
|
||||||
return (
|
return (
|
||||||
<div className="login-modal">
|
<div className="login-modal">
|
||||||
@@ -336,6 +566,9 @@ function App(): React.ReactElement {
|
|||||||
width={sidebarWidth}
|
width={sidebarWidth}
|
||||||
dateRange={dateRange}
|
dateRange={dateRange}
|
||||||
onDateRangeChange={handleDateRangeChange}
|
onDateRangeChange={handleDateRangeChange}
|
||||||
|
selfInfo={selfInfo}
|
||||||
|
dbReady={isAuthenticated}
|
||||||
|
onOpenSettings={() => setShowSettings(true)}
|
||||||
/>
|
/>
|
||||||
<div className="resizer" onMouseDown={startResizing} />
|
<div className="resizer" onMouseDown={startResizing} />
|
||||||
<ChatWindow
|
<ChatWindow
|
||||||
@@ -346,6 +579,18 @@ function App(): React.ReactElement {
|
|||||||
onRefresh={() => selectedContact && handleSelectContact(selectedContact)}
|
onRefresh={() => selectedContact && handleSelectContact(selectedContact)}
|
||||||
onRefreshData={loadContacts}
|
onRefreshData={loadContacts}
|
||||||
/>
|
/>
|
||||||
|
<SettingsPanel
|
||||||
|
open={showSettings}
|
||||||
|
selfInfo={selfInfo}
|
||||||
|
dbReady={isAuthenticated}
|
||||||
|
dbKey={dbKey}
|
||||||
|
onClose={() => setShowSettings(false)}
|
||||||
|
onDbKeyChange={setDbKey}
|
||||||
|
onDbRootChanged={() => {
|
||||||
|
void refreshSelfInfo()
|
||||||
|
void loadContacts()
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -233,7 +233,6 @@ body {
|
|||||||
|
|
||||||
.wechat-message-list {
|
.wechat-message-list {
|
||||||
padding: 18px 28px;
|
padding: 18px 28px;
|
||||||
gap: 14px;
|
|
||||||
background-color: #edf1f2;
|
background-color: #edf1f2;
|
||||||
background-image:
|
background-image:
|
||||||
radial-gradient(circle at 20px 20px, rgba(0, 0, 0, 0.025) 1px, transparent 1px),
|
radial-gradient(circle at 20px 20px, rgba(0, 0, 0, 0.025) 1px, transparent 1px),
|
||||||
@@ -241,6 +240,10 @@ body {
|
|||||||
background-size: 120px 120px;
|
background-size: 120px 120px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.wechat-message-row {
|
||||||
|
margin-bottom: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
.wechat-message-row {
|
.wechat-message-row {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: flex-start;
|
align-items: flex-start;
|
||||||
@@ -252,6 +255,31 @@ body {
|
|||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.wechat-system-message-row {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
margin: 2px 0 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wechat-system-message {
|
||||||
|
max-width: min(78%, 760px);
|
||||||
|
padding: 6px 12px;
|
||||||
|
border-radius: 999px;
|
||||||
|
background: rgba(227, 86, 86, 0.1);
|
||||||
|
color: #c84a4a;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 1.5;
|
||||||
|
text-align: center;
|
||||||
|
word-break: break-word;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wechat-system-message-meta {
|
||||||
|
color: #a0a7ab;
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
|
||||||
.message-avatar {
|
.message-avatar {
|
||||||
width: 38px;
|
width: 38px;
|
||||||
height: 38px;
|
height: 38px;
|
||||||
@@ -297,7 +325,6 @@ body {
|
|||||||
line-height: 1.55;
|
line-height: 1.55;
|
||||||
box-shadow: 0 1px 0 rgba(0, 0, 0, 0.03);
|
box-shadow: 0 1px 0 rgba(0, 0, 0, 0.03);
|
||||||
word-break: break-word;
|
word-break: break-word;
|
||||||
white-space: pre-wrap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.wechat-message-row.mine .message-bubble {
|
.wechat-message-row.mine .message-bubble {
|
||||||
@@ -865,9 +892,43 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.image-preview-modal {
|
.image-preview-modal {
|
||||||
background: transparent;
|
width: min(520px, 92vw);
|
||||||
box-shadow: none;
|
max-height: 88vh;
|
||||||
padding: 0;
|
background: #f7f8fa;
|
||||||
|
box-shadow: 0 18px 48px rgba(0, 0, 0, 0.18);
|
||||||
|
padding: 16px;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.report-preview-frame {
|
||||||
|
border: 1px solid #d8dde3;
|
||||||
|
border-radius: 10px;
|
||||||
|
background: #eef1f4;
|
||||||
|
padding: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.report-preview-scroller {
|
||||||
|
max-height: calc(88vh - 120px);
|
||||||
|
overflow-y: auto;
|
||||||
|
overflow-x: hidden;
|
||||||
|
padding-right: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.report-preview-image {
|
||||||
|
display: block;
|
||||||
|
width: min(430px, 100%);
|
||||||
|
height: auto;
|
||||||
|
margin: 0 auto;
|
||||||
|
border-radius: 8px;
|
||||||
|
border: 1px solid #ccd3d9;
|
||||||
|
background: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.report-preview-actions {
|
||||||
|
margin-top: 12px;
|
||||||
|
display: flex;
|
||||||
|
gap: 10px;
|
||||||
|
flex-wrap: wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.image-viewer-overlay {
|
.image-viewer-overlay {
|
||||||
@@ -1143,3 +1204,408 @@ body {
|
|||||||
.voip-status {
|
.voip-status {
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Sidebar 自助卡片 + 入口 */
|
||||||
|
.sidebar-footer {
|
||||||
|
padding: 10px 12px;
|
||||||
|
border-top: 1px solid var(--border-color);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
cursor: pointer;
|
||||||
|
background-color: #f3f4f5;
|
||||||
|
transition: background-color 0.15s ease;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-footer:hover {
|
||||||
|
background-color: #e6e9eb;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-self-avatar {
|
||||||
|
width: 36px;
|
||||||
|
height: 36px;
|
||||||
|
border-radius: 6px;
|
||||||
|
background-color: #07c160;
|
||||||
|
color: #fff;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 500;
|
||||||
|
overflow: hidden;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-self-avatar img {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-self-info {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-self-nickname {
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 500;
|
||||||
|
color: #1f2429;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-self-wxid {
|
||||||
|
font-size: 11px;
|
||||||
|
color: #8a9298;
|
||||||
|
margin-top: 2px;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-self-arrow {
|
||||||
|
color: #8a9298;
|
||||||
|
font-size: 18px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 启动自动连接 Splash */
|
||||||
|
.boot-splash {
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 14px;
|
||||||
|
background: linear-gradient(180deg, #f5f7f8 0%, #eceff1 100%);
|
||||||
|
z-index: 2000;
|
||||||
|
animation: boot-splash-fade-in 0.2s ease-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes boot-splash-fade-in {
|
||||||
|
from {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.boot-splash-spinner {
|
||||||
|
width: 36px;
|
||||||
|
height: 36px;
|
||||||
|
border-radius: 50%;
|
||||||
|
border: 3px solid rgba(7, 193, 96, 0.18);
|
||||||
|
border-top-color: #07c160;
|
||||||
|
animation: boot-splash-spin 0.9s linear infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes boot-splash-spin {
|
||||||
|
to {
|
||||||
|
transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.boot-splash-title {
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: 500;
|
||||||
|
color: #1f2429;
|
||||||
|
}
|
||||||
|
|
||||||
|
.boot-splash-subtitle {
|
||||||
|
font-size: 12px;
|
||||||
|
color: #6f767c;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 设置面板 */
|
||||||
|
.settings-overlay {
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
background: rgba(15, 21, 26, 0.45);
|
||||||
|
backdrop-filter: blur(2px);
|
||||||
|
z-index: 1100;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
animation: settings-fade-in 0.16s ease-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes settings-fade-in {
|
||||||
|
from {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-modal {
|
||||||
|
width: min(560px, 92vw);
|
||||||
|
max-height: 84vh;
|
||||||
|
background: #fff;
|
||||||
|
border-radius: 12px;
|
||||||
|
box-shadow: 0 24px 60px rgba(15, 21, 26, 0.28);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
overflow: hidden;
|
||||||
|
animation: settings-pop-in 0.18s ease-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes settings-pop-in {
|
||||||
|
from {
|
||||||
|
transform: translateY(8px) scale(0.98);
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
transform: translateY(0) scale(1);
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: 16px 22px;
|
||||||
|
border-bottom: 1px solid #ececec;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-header h2 {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 17px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #1f2429;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-close {
|
||||||
|
background: transparent;
|
||||||
|
border: 0;
|
||||||
|
color: #7d858a;
|
||||||
|
font-size: 26px;
|
||||||
|
line-height: 1;
|
||||||
|
width: 32px;
|
||||||
|
height: 32px;
|
||||||
|
border-radius: 50%;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background-color 0.15s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-close:hover {
|
||||||
|
background: #f0f2f4;
|
||||||
|
color: #1f2429;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-body {
|
||||||
|
padding: 12px 22px 22px;
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-section {
|
||||||
|
margin-top: 14px;
|
||||||
|
padding: 14px 16px;
|
||||||
|
border-radius: 10px;
|
||||||
|
background: #fafbfc;
|
||||||
|
border: 1px solid #ececec;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-section:first-child {
|
||||||
|
margin-top: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-section-title {
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #6f767c;
|
||||||
|
letter-spacing: 0.5px;
|
||||||
|
text-transform: uppercase;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
margin-top: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-row:first-child {
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-input {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
padding: 8px 11px;
|
||||||
|
border: 1px solid #d4d9dc;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: #fff;
|
||||||
|
font-size: 13px;
|
||||||
|
color: #1f2429;
|
||||||
|
font-family: 'SF Mono', Menlo, Consolas, monospace;
|
||||||
|
outline: none;
|
||||||
|
transition: border-color 0.15s ease, box-shadow 0.15s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-input:focus {
|
||||||
|
border-color: #07c160;
|
||||||
|
box-shadow: 0 0 0 3px rgba(7, 193, 96, 0.12);
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-input-half {
|
||||||
|
flex: 0 1 140px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-input-quarter {
|
||||||
|
flex: 0 1 90px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-btn {
|
||||||
|
padding: 7px 14px;
|
||||||
|
border: 1px solid #d4d9dc;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: #fff;
|
||||||
|
color: #30383d;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 13px;
|
||||||
|
transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-btn:hover:not(:disabled) {
|
||||||
|
border-color: #07c160;
|
||||||
|
color: #078f49;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-btn:disabled {
|
||||||
|
opacity: 0.55;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-btn-primary {
|
||||||
|
background: #07c160;
|
||||||
|
color: #fff;
|
||||||
|
border-color: #07c160;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-btn-primary:hover:not(:disabled) {
|
||||||
|
background: #06ad56;
|
||||||
|
color: #fff;
|
||||||
|
border-color: #06ad56;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-hint {
|
||||||
|
margin-top: 10px;
|
||||||
|
font-size: 11px;
|
||||||
|
color: #8a9298;
|
||||||
|
line-height: 1.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-hint code {
|
||||||
|
background: #eef0f2;
|
||||||
|
padding: 1px 5px;
|
||||||
|
border-radius: 3px;
|
||||||
|
font-size: 10.5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-status {
|
||||||
|
font-size: 12px;
|
||||||
|
color: #59636a;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-status.ok {
|
||||||
|
color: #078f49;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-status.fail {
|
||||||
|
color: #c73737;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-toggle {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 13px;
|
||||||
|
color: #30383d;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-toggle input {
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
accent-color: #07c160;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-self {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-self-avatar {
|
||||||
|
width: 56px;
|
||||||
|
height: 56px;
|
||||||
|
border-radius: 10px;
|
||||||
|
background: #07c160;
|
||||||
|
color: #fff;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font-size: 22px;
|
||||||
|
font-weight: 500;
|
||||||
|
overflow: hidden;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-self-avatar img {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-self-info {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-self-nickname {
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #1f2429;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-self-wxid {
|
||||||
|
font-size: 12px;
|
||||||
|
color: #6f767c;
|
||||||
|
margin-top: 2px;
|
||||||
|
font-family: 'SF Mono', Menlo, Consolas, monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-self-account {
|
||||||
|
font-size: 11px;
|
||||||
|
color: #8a9298;
|
||||||
|
margin-top: 2px;
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-self-empty {
|
||||||
|
font-size: 13px;
|
||||||
|
color: #8a9298;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-path {
|
||||||
|
display: inline-block;
|
||||||
|
font-family: 'SF Mono', Menlo, Consolas, monospace;
|
||||||
|
font-size: 11px;
|
||||||
|
background: #eef0f2;
|
||||||
|
padding: 3px 7px;
|
||||||
|
border-radius: 4px;
|
||||||
|
color: #30383d;
|
||||||
|
word-break: break-all;
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
|||||||
@@ -304,6 +304,7 @@ const ChatWindow: React.FC<ChatWindowProps> = ({
|
|||||||
<div className="message-list wechat-message-list">
|
<div className="message-list wechat-message-list">
|
||||||
{filteredMessages.map((msg) => {
|
{filteredMessages.map((msg) => {
|
||||||
const isMine = msg.from === 'assistant'
|
const isMine = msg.from === 'assistant'
|
||||||
|
const isSystem = msg.from === 'system' || msg.type === '系统消息'
|
||||||
const displayName = isMine
|
const displayName = isMine
|
||||||
? '我'
|
? '我'
|
||||||
: isGroupChat
|
: isGroupChat
|
||||||
@@ -312,7 +313,18 @@ const ChatWindow: React.FC<ChatWindowProps> = ({
|
|||||||
const avatarSrc = isMine ? msg.img : msg.img || contact.avatar
|
const avatarSrc = isMine ? msg.img : msg.img || contact.avatar
|
||||||
const isVoice = msg.type === '语音'
|
const isVoice = msg.type === '语音'
|
||||||
const isImage = msg.type === '图片'
|
const isImage = msg.type === '图片'
|
||||||
const isRichMedia = ['名片', '位置', '分享消息', '通话', '表情包'].includes(msg.type)
|
const isRichMedia = ['名片', '位置', '分享消息', '通话', '表情包', '系统消息'].includes(
|
||||||
|
msg.type
|
||||||
|
)
|
||||||
|
|
||||||
|
if (isSystem) {
|
||||||
|
return (
|
||||||
|
<div key={msg.id} className="wechat-system-message-row">
|
||||||
|
<div className="wechat-system-message">{msg.content}</div>
|
||||||
|
<div className="wechat-system-message-meta">{msg.datetime}</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div key={msg.id} className={`wechat-message-row ${isMine ? 'mine' : 'other'}`}>
|
<div key={msg.id} className={`wechat-message-row ${isMine ? 'mine' : 'other'}`}>
|
||||||
@@ -420,19 +432,16 @@ const ChatWindow: React.FC<ChatWindowProps> = ({
|
|||||||
{generatedImage && (
|
{generatedImage && (
|
||||||
<div className="modal-overlay" onClick={() => setGeneratedImage(null)}>
|
<div className="modal-overlay" onClick={() => setGeneratedImage(null)}>
|
||||||
<div className="modal-content image-preview-modal" onClick={(e) => e.stopPropagation()}>
|
<div className="modal-content image-preview-modal" onClick={(e) => e.stopPropagation()}>
|
||||||
<img
|
<div className="report-preview-frame">
|
||||||
src={generatedImage}
|
<div className="report-preview-scroller">
|
||||||
alt="Generated Summary"
|
<img
|
||||||
style={{ maxWidth: '100%', maxHeight: '80vh', border: '1px solid #ccc' }}
|
src={generatedImage}
|
||||||
/>
|
alt="Generated Summary"
|
||||||
<div
|
className="report-preview-image"
|
||||||
style={{
|
/>
|
||||||
marginTop: '10px',
|
</div>
|
||||||
display: 'flex',
|
</div>
|
||||||
// justifyContent: 'flex-end',
|
<div className="report-preview-actions">
|
||||||
gap: '10px'
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<button
|
<button
|
||||||
onClick={handleCopyImage}
|
onClick={handleCopyImage}
|
||||||
style={{
|
style={{
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ export function RichMessageBubble({ contentData }: RichMessageBubbleProps): JSX.
|
|||||||
return <StickerBubble data={contentData} />
|
return <StickerBubble data={contentData} />
|
||||||
case 'quote':
|
case 'quote':
|
||||||
return <QuoteBubble data={contentData} />
|
return <QuoteBubble data={contentData} />
|
||||||
|
case 'system':
|
||||||
|
return <SystemBubble data={contentData} />
|
||||||
case 'unknown':
|
case 'unknown':
|
||||||
return (
|
return (
|
||||||
<div className="message-text">{(contentData as { raw?: string }).raw || '[未知消息]'}</div>
|
<div className="message-text">{(contentData as { raw?: string }).raw || '[未知消息]'}</div>
|
||||||
@@ -212,6 +214,10 @@ function QuoteBubble({ data }: { data: Extract<ParsedContent, { type: 'quote' }>
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function SystemBubble({ data }: { data: Extract<ParsedContent, { type: 'system' }> }): JSX.Element {
|
||||||
|
return <div className="message-text">{data.content || '[系统消息]'}</div>
|
||||||
|
}
|
||||||
|
|
||||||
function getUrlHost(url?: string): string {
|
function getUrlHost(url?: string): string {
|
||||||
if (!url) return ''
|
if (!url) return ''
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -0,0 +1,306 @@
|
|||||||
|
import React, { useEffect, useState } from 'react'
|
||||||
|
|
||||||
|
interface SelfInfo {
|
||||||
|
wxid: string
|
||||||
|
nickname: string
|
||||||
|
avatar?: string
|
||||||
|
accountRoot: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AppSettings {
|
||||||
|
dbRoot: string
|
||||||
|
apiEnabled: boolean
|
||||||
|
apiHost: string
|
||||||
|
apiPort: number
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ApiState {
|
||||||
|
running: boolean
|
||||||
|
host: string
|
||||||
|
port: number
|
||||||
|
error?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface SettingsPanelProps {
|
||||||
|
open: boolean
|
||||||
|
selfInfo: SelfInfo | null
|
||||||
|
dbReady: boolean
|
||||||
|
dbKey: string
|
||||||
|
onClose: () => void
|
||||||
|
onDbKeyChange: (key: string) => void
|
||||||
|
onDbRootChanged: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
export const SettingsPanel: React.FC<SettingsPanelProps> = ({
|
||||||
|
open,
|
||||||
|
selfInfo,
|
||||||
|
dbReady,
|
||||||
|
dbKey,
|
||||||
|
onClose,
|
||||||
|
onDbKeyChange,
|
||||||
|
onDbRootChanged
|
||||||
|
}) => {
|
||||||
|
const [settings, setSettings] = useState<AppSettings | null>(null)
|
||||||
|
const [settingsPath, setSettingsPath] = useState('')
|
||||||
|
const [apiState, setApiState] = useState<ApiState | null>(null)
|
||||||
|
const [testStatus, setTestStatus] = useState<
|
||||||
|
{ kind: 'idle' | 'ok' | 'fail'; message: string; wxid?: string; accountRoot?: string }
|
||||||
|
>({ kind: 'idle', message: '' })
|
||||||
|
const [reopenStatus, setReopenStatus] = useState<string>('')
|
||||||
|
const [busy, setBusy] = useState(false)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!open) return
|
||||||
|
void refresh()
|
||||||
|
}, [open])
|
||||||
|
|
||||||
|
async function refresh(): Promise<void> {
|
||||||
|
const [{ settings, settingsPath }, api] = await Promise.all([
|
||||||
|
window.api.getSettings(),
|
||||||
|
window.api.apiStatus()
|
||||||
|
])
|
||||||
|
setSettings(settings)
|
||||||
|
setSettingsPath(settingsPath)
|
||||||
|
setApiState(api)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!open) return null
|
||||||
|
|
||||||
|
async function handleSave(patch: Partial<AppSettings>): Promise<void> {
|
||||||
|
if (!settings) return
|
||||||
|
setBusy(true)
|
||||||
|
const next = await window.api.setSettings(patch)
|
||||||
|
setSettings(next.settings)
|
||||||
|
setBusy(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleTest(): Promise<void> {
|
||||||
|
setTestStatus({ kind: 'idle', message: '测试中...' })
|
||||||
|
setBusy(true)
|
||||||
|
try {
|
||||||
|
const result = await window.api.testConnection(dbKey, settings?.dbRoot)
|
||||||
|
if (result.success) {
|
||||||
|
setTestStatus({
|
||||||
|
kind: 'ok',
|
||||||
|
message: '连接成功',
|
||||||
|
wxid: result.wxid,
|
||||||
|
accountRoot: result.accountRoot
|
||||||
|
})
|
||||||
|
if (result.accountRoot && settings && result.accountRoot !== settings.dbRoot) {
|
||||||
|
const next = await window.api.setSettings({ dbRoot: result.accountRoot })
|
||||||
|
setSettings(next.settings)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setTestStatus({ kind: 'fail', message: result.error || '连接失败' })
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
setTestStatus({ kind: 'fail', message: error instanceof Error ? error.message : String(error) })
|
||||||
|
} finally {
|
||||||
|
setBusy(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleReopen(): Promise<void> {
|
||||||
|
if (!settings) return
|
||||||
|
setBusy(true)
|
||||||
|
setReopenStatus('重新初始化中...')
|
||||||
|
try {
|
||||||
|
const result = await window.api.reopenWithRoot(settings.dbRoot)
|
||||||
|
if (result.success) {
|
||||||
|
setReopenStatus(`已重新打开:${result.info?.wxid || '未知'}`)
|
||||||
|
onDbRootChanged()
|
||||||
|
} else {
|
||||||
|
setReopenStatus(result.error || '重新打开失败')
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
setReopenStatus(error instanceof Error ? error.message : String(error))
|
||||||
|
} finally {
|
||||||
|
setBusy(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleApiToggle(enabled: boolean): Promise<void> {
|
||||||
|
setBusy(true)
|
||||||
|
await handleSave({ apiEnabled: enabled })
|
||||||
|
const state = await window.api.apiToggle(enabled)
|
||||||
|
setApiState(state)
|
||||||
|
setBusy(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleApiRestart(): Promise<void> {
|
||||||
|
if (!settings) return
|
||||||
|
setBusy(true)
|
||||||
|
await window.api.apiStop()
|
||||||
|
const state = await window.api.apiStart(settings.apiHost, settings.apiPort)
|
||||||
|
setApiState(state)
|
||||||
|
setBusy(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="settings-overlay" onClick={onClose}>
|
||||||
|
<div className="settings-modal" onClick={(e) => e.stopPropagation()}>
|
||||||
|
<div className="settings-header">
|
||||||
|
<h2>设置</h2>
|
||||||
|
<button className="settings-close" onClick={onClose} title="关闭">
|
||||||
|
×
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="settings-body">
|
||||||
|
{/* 自我信息卡片 */}
|
||||||
|
<section className="settings-section">
|
||||||
|
<div className="settings-section-title">账号信息</div>
|
||||||
|
{dbReady && selfInfo ? (
|
||||||
|
<div className="settings-self">
|
||||||
|
<div className="settings-self-avatar">
|
||||||
|
{selfInfo.avatar ? (
|
||||||
|
<img src={selfInfo.avatar} alt={selfInfo.nickname} referrerPolicy="no-referrer" />
|
||||||
|
) : (
|
||||||
|
(selfInfo.nickname || selfInfo.wxid || '?').charAt(0)
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="settings-self-info">
|
||||||
|
<div className="settings-self-nickname">{selfInfo.nickname}</div>
|
||||||
|
<div className="settings-self-wxid">{selfInfo.wxid}</div>
|
||||||
|
<div className="settings-self-account">{selfInfo.accountRoot}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="settings-self-empty">尚未连接数据库</div>
|
||||||
|
)}
|
||||||
|
</section>
|
||||||
|
|
||||||
|
{/* 测试连接 */}
|
||||||
|
<section className="settings-section">
|
||||||
|
<div className="settings-section-title">连接测试</div>
|
||||||
|
<div className="settings-row">
|
||||||
|
<button
|
||||||
|
className="settings-btn settings-btn-primary"
|
||||||
|
onClick={handleTest}
|
||||||
|
disabled={busy || !dbKey}
|
||||||
|
>
|
||||||
|
测试连接
|
||||||
|
</button>
|
||||||
|
{testStatus.kind !== 'idle' && (
|
||||||
|
<span className={`settings-status ${testStatus.kind}`}>
|
||||||
|
{testStatus.kind === 'ok' ? '✓' : '✗'} {testStatus.message}
|
||||||
|
{testStatus.wxid ? ` · ${testStatus.wxid}` : ''}
|
||||||
|
{testStatus.accountRoot ? ` · ${testStatus.accountRoot}` : ''}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="settings-hint">
|
||||||
|
使用当前密钥 + 下方配置的根目录尝试打开数据库,只校验不持久化。
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
{/* 解密密钥 */}
|
||||||
|
<section className="settings-section">
|
||||||
|
<div className="settings-section-title">解密密钥</div>
|
||||||
|
<div className="settings-row">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
className="settings-input"
|
||||||
|
value={dbKey}
|
||||||
|
onChange={(e) => onDbKeyChange(e.target.value)}
|
||||||
|
placeholder="64 位 hex 密钥,如 0x..."
|
||||||
|
spellCheck={false}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="settings-hint">
|
||||||
|
密钥保存在本机 macOS Keychain(safeStorage 加密),不会上传任何服务器。
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
{/* 数据库根目录 */}
|
||||||
|
<section className="settings-section">
|
||||||
|
<div className="settings-section-title">数据库根目录</div>
|
||||||
|
<div className="settings-row">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
className="settings-input"
|
||||||
|
value={settings?.dbRoot ?? ''}
|
||||||
|
onChange={(e) => setSettings(settings ? { ...settings, dbRoot: e.target.value } : null)}
|
||||||
|
onBlur={(e) => handleSave({ dbRoot: e.target.value })}
|
||||||
|
placeholder="~/Library/Containers/com.tencent.xinWeChat/Data/Documents/xwechat_files"
|
||||||
|
spellCheck={false}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="settings-row">
|
||||||
|
<button
|
||||||
|
className="settings-btn"
|
||||||
|
onClick={handleReopen}
|
||||||
|
disabled={busy || !dbReady}
|
||||||
|
>
|
||||||
|
应用并重新初始化
|
||||||
|
</button>
|
||||||
|
{reopenStatus && <span className="settings-status">{reopenStatus}</span>}
|
||||||
|
</div>
|
||||||
|
<div className="settings-hint">
|
||||||
|
指向 xwechat_files 目录,内部包含 db_storage/。修改后需重新初始化才能生效。
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
{/* API 服务 */}
|
||||||
|
<section className="settings-section">
|
||||||
|
<div className="settings-section-title">本地 HTTP API</div>
|
||||||
|
<div className="settings-row">
|
||||||
|
<label className="settings-toggle">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={settings?.apiEnabled ?? false}
|
||||||
|
onChange={(e) => handleApiToggle(e.target.checked)}
|
||||||
|
disabled={busy}
|
||||||
|
/>
|
||||||
|
<span>启用 API 服务(127.0.0.1:6131)</span>
|
||||||
|
</label>
|
||||||
|
{apiState && (
|
||||||
|
<span className={`settings-status ${apiState.running ? 'ok' : 'fail'}`}>
|
||||||
|
{apiState.running ? '运行中' : '已停止'}
|
||||||
|
{apiState.error ? ` · ${apiState.error}` : ''}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="settings-row">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
className="settings-input settings-input-half"
|
||||||
|
value={settings?.apiHost ?? ''}
|
||||||
|
onChange={(e) => setSettings(settings ? { ...settings, apiHost: e.target.value } : null)}
|
||||||
|
onBlur={(e) => handleSave({ apiHost: e.target.value })}
|
||||||
|
placeholder="host"
|
||||||
|
spellCheck={false}
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
className="settings-input settings-input-quarter"
|
||||||
|
value={settings?.apiPort ?? 6131}
|
||||||
|
onChange={(e) =>
|
||||||
|
setSettings(settings ? { ...settings, apiPort: Number(e.target.value) || 6131 } : null)
|
||||||
|
}
|
||||||
|
onBlur={(e) => handleSave({ apiPort: Number(e.target.value) || 6131 })}
|
||||||
|
placeholder="port"
|
||||||
|
/>
|
||||||
|
<button className="settings-btn" onClick={handleApiRestart} disabled={busy}>
|
||||||
|
重启 API
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div className="settings-hint">
|
||||||
|
API 仅本机访问,无鉴权。关闭后 Claude / Codex 等客户端无法读取聊天数据。
|
||||||
|
<br />
|
||||||
|
配置文档:<code>docs/skill/wechatexplorer-reader/SKILL.md</code>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
{/* 配置文件位置 */}
|
||||||
|
<section className="settings-section">
|
||||||
|
<div className="settings-section-title">配置文件</div>
|
||||||
|
<div className="settings-row">
|
||||||
|
<code className="settings-path">{settingsPath}</code>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,6 +1,13 @@
|
|||||||
import React, { useState } from 'react'
|
import React, { useState } from 'react'
|
||||||
import { Contact } from '../../../shared/types'
|
import { Contact } from '../../../shared/types'
|
||||||
|
|
||||||
|
interface SelfInfo {
|
||||||
|
wxid: string
|
||||||
|
nickname: string
|
||||||
|
avatar?: string
|
||||||
|
accountRoot: string
|
||||||
|
}
|
||||||
|
|
||||||
interface SidebarProps {
|
interface SidebarProps {
|
||||||
contacts: Contact[]
|
contacts: Contact[]
|
||||||
selectedContact: Contact | null
|
selectedContact: Contact | null
|
||||||
@@ -10,6 +17,9 @@ interface SidebarProps {
|
|||||||
width: number
|
width: number
|
||||||
dateRange: string
|
dateRange: string
|
||||||
onDateRangeChange: (range: string) => void
|
onDateRangeChange: (range: string) => void
|
||||||
|
selfInfo: SelfInfo | null
|
||||||
|
dbReady: boolean
|
||||||
|
onOpenSettings: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Sidebar: React.FC<SidebarProps> = ({
|
export const Sidebar: React.FC<SidebarProps> = ({
|
||||||
@@ -20,7 +30,10 @@ export const Sidebar: React.FC<SidebarProps> = ({
|
|||||||
onContentFilter,
|
onContentFilter,
|
||||||
width,
|
width,
|
||||||
dateRange,
|
dateRange,
|
||||||
onDateRangeChange
|
onDateRangeChange,
|
||||||
|
selfInfo,
|
||||||
|
dbReady,
|
||||||
|
onOpenSettings
|
||||||
}) => {
|
}) => {
|
||||||
const [searchTerm, setSearchTerm] = useState('')
|
const [searchTerm, setSearchTerm] = useState('')
|
||||||
const [contentFilter, setContentFilter] = useState('')
|
const [contentFilter, setContentFilter] = useState('')
|
||||||
@@ -115,14 +128,24 @@ export const Sidebar: React.FC<SidebarProps> = ({
|
|||||||
<div className="section-empty">暂无联系人</div>
|
<div className="section-empty">暂无联系人</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{/* <div className="sidebar-footer">
|
<div className="sidebar-footer" onClick={onOpenSettings} title="设置">
|
||||||
<div className="sidebar-btn" onClick={() => window.location.reload()}>
|
<div className="sidebar-self-avatar">
|
||||||
<span className="icon">↪️</span> 退出
|
{selfInfo?.avatar ? (
|
||||||
</div>
|
<img src={selfInfo.avatar} alt={selfInfo.nickname} referrerPolicy="no-referrer" />
|
||||||
<div className="sidebar-status">
|
) : (
|
||||||
✅ 已获得
|
((selfInfo?.nickname || selfInfo?.wxid || '我').charAt(0))
|
||||||
</div>
|
)}
|
||||||
</div> */}
|
</div>
|
||||||
|
<div className="sidebar-self-info">
|
||||||
|
<div className="sidebar-self-nickname">
|
||||||
|
{dbReady && selfInfo ? selfInfo.nickname || selfInfo.wxid || '我' : '未连接'}
|
||||||
|
</div>
|
||||||
|
<div className="sidebar-self-wxid">
|
||||||
|
{dbReady && selfInfo ? selfInfo.wxid : '点击设置 →'}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="sidebar-self-arrow" aria-hidden>⚙</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -169,9 +169,21 @@ export const buildGroupReportInput = (
|
|||||||
const dateRange = sameDay
|
const dateRange = sameDay
|
||||||
? `${startDate} ${localTime(firstTimestamp)}-${localTime(lastTimestamp)}`
|
? `${startDate} ${localTime(firstTimestamp)}-${localTime(lastTimestamp)}`
|
||||||
: `${startDate} ${localTime(firstTimestamp)} 至 ${endDate} ${localTime(lastTimestamp)}`
|
: `${startDate} ${localTime(firstTimestamp)} 至 ${endDate} ${localTime(lastTimestamp)}`
|
||||||
const timeSpan = sameDay
|
// 模板"持续时长"格子:首条到末条消息的时长,紧凑半角格式
|
||||||
? `${Math.max(1, Math.ceil((lastTimestamp - firstTimestamp) / 3600000))}小时`
|
const durationMs = Math.max(0, lastTimestamp - firstTimestamp)
|
||||||
: `${Math.max(1, Math.ceil((lastTimestamp - firstTimestamp) / 86400000))}天`
|
const durationHours = durationMs / 3600000
|
||||||
|
const timeSpan = (() => {
|
||||||
|
if (sameDay) {
|
||||||
|
if (durationHours < 1) {
|
||||||
|
const minutes = Math.max(1, Math.round(durationMs / 60000))
|
||||||
|
return `${minutes} min`
|
||||||
|
}
|
||||||
|
const hours = Math.max(1, Math.ceil(durationHours))
|
||||||
|
return `${hours} h`
|
||||||
|
}
|
||||||
|
const days = Math.max(1, Math.ceil(durationMs / 86400000))
|
||||||
|
return `${days} d`
|
||||||
|
})()
|
||||||
const contactName = contact?.m_nsNickName || ''
|
const contactName = contact?.m_nsNickName || ''
|
||||||
const groupName = contactName && !isInternalIdentifier(contactName) ? contactName : '未命名会话'
|
const groupName = contactName && !isInternalIdentifier(contactName) ? contactName : '未命名会话'
|
||||||
const metadata: GroupReportMetadata = {
|
const metadata: GroupReportMetadata = {
|
||||||
|
|||||||
@@ -76,6 +76,13 @@ export interface GroupReportMetadata {
|
|||||||
footerNote: string
|
footerNote: string
|
||||||
heroParticipants: string[]
|
heroParticipants: string[]
|
||||||
avatars: Record<string, string | undefined>
|
avatars: Record<string, string | undefined>
|
||||||
|
// === 新增(可选,向后兼容) ===
|
||||||
|
/** 群昵称 / wxid / md5,服务端用来反推真头像(从 getGroupSnapshot) */
|
||||||
|
talker?: string
|
||||||
|
/** 预留,与 /api/v1/chatlog 的 time 参数同格式 */
|
||||||
|
timeRange?: string
|
||||||
|
/** 服务端写回,告知 client enrich 失败/部分缺失 */
|
||||||
|
warnings?: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GroupReportExportRequest {
|
export interface GroupReportExportRequest {
|
||||||
@@ -88,5 +95,6 @@ export interface GroupReportExportResult {
|
|||||||
htmlPath?: string
|
htmlPath?: string
|
||||||
pngPath?: string
|
pngPath?: string
|
||||||
imageDataUrl?: string
|
imageDataUrl?: string
|
||||||
|
warnings?: string[]
|
||||||
error?: string
|
error?: string
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -66,7 +66,7 @@ type QuoteContent = {
|
|||||||
quotedSender?: string
|
quotedSender?: string
|
||||||
quotedType?: string
|
quotedType?: string
|
||||||
}
|
}
|
||||||
type SystemContent = { type: 'system'; content: string }
|
type SystemContent = { type: 'system'; content: string; raw?: string }
|
||||||
type UnknownContent = { type: 'unknown'; raw: string }
|
type UnknownContent = { type: 'unknown'; raw: string }
|
||||||
|
|
||||||
export type ParsedContent =
|
export type ParsedContent =
|
||||||
|
|||||||
Reference in New Issue
Block a user