mirror of
https://wget.la/https://github.com/Wxw-Gu/WechatExplorer
synced 2026-12-01 09:15:41 +08:00
feat: 档案和导出页面支持查看多选消息
This commit is contained in:
1 parent
2fb519a373
commit
b86582e606
19 files changed
+1864
-119
No files matched your search
@@ -1,5 +1,10 @@
|
|||||||
# 群聊机器人 (`com.example.group-chat-bot`)
|
# 群聊机器人 (`com.example.group-chat-bot`)
|
||||||
|
|
||||||
|
> **这是模板壳,不是完整运行包。** 本目录的 `lib/bot-engine.js` 只含纯函数,不含
|
||||||
|
> `activateBotRuntime` 运行时。直接把本目录打成 ZIP 安装,后台会走
|
||||||
|
> `background/index.js` 的 fallback,预览与测试发送都会提示「当前功能暂不可用」。
|
||||||
|
> 可安装的完整包必须包含带运行时的 `lib/bot-engine.js`;不要把本目录当成品分发。
|
||||||
|
|
||||||
TraceMemo 官方扩展模板。结合 TraceMemo 已配置的 AI 模型与文字转语音(TTS)音色,在指定微信群聊中按角色设定自然接话,支持单群长期记忆与随机回复文字 / 随机发送语音。
|
TraceMemo 官方扩展模板。结合 TraceMemo 已配置的 AI 模型与文字转语音(TTS)音色,在指定微信群聊中按角色设定自然接话,支持单群长期记忆与随机回复文字 / 随机发送语音。
|
||||||
|
|
||||||
## 核心特性
|
## 核心特性
|
||||||
|
|||||||
@@ -14,8 +14,8 @@
|
|||||||
"bytes": 33471
|
"bytes": 33471
|
||||||
},
|
},
|
||||||
"group-chat-bot@1.0.0": {
|
"group-chat-bot@1.0.0": {
|
||||||
"sha256": "122a4da7710cf882975f09440819e9dc1b619e4bd6f94153085a7d6fe8a33885",
|
"sha256": "eb672f076710619dc363756d854319a8ded9b8f6a4833c258c1493c57bb89629",
|
||||||
"bytes": 24981
|
"bytes": 25231
|
||||||
},
|
},
|
||||||
"keyword-bot@1.0.0": {
|
"keyword-bot@1.0.0": {
|
||||||
"sha256": "3d8e5453e7ae6de7e29c16eb3c9e718a98bae27e9ed2edfd10399fb158e1c87d",
|
"sha256": "3d8e5453e7ae6de7e29c16eb3c9e718a98bae27e9ed2edfd10399fb158e1c87d",
|
||||||
|
|||||||
@@ -646,18 +646,245 @@ body {
|
|||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
object-fit: cover;
|
object-fit: cover;
|
||||||
}
|
}
|
||||||
.forward-content details { margin-top: 2px; }
|
.forward-content.is-clickable {
|
||||||
.forward-content summary {
|
|
||||||
color: var(--accent);
|
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.forward-content.is-clickable:hover .forward-footer-action {
|
||||||
|
color: var(--accent);
|
||||||
|
}
|
||||||
|
.forward-preview-list {
|
||||||
|
display: grid;
|
||||||
|
gap: 5px;
|
||||||
|
margin-top: 6px;
|
||||||
|
}
|
||||||
|
.forward-preview-line {
|
||||||
|
display: flex;
|
||||||
|
gap: 5px;
|
||||||
|
color: var(--muted);
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
|
line-height: 1.45;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.forward-preview-line strong {
|
||||||
|
color: var(--ink);
|
||||||
|
font-weight: 600;
|
||||||
|
flex: 0 0 auto;
|
||||||
|
}
|
||||||
|
.forward-footer {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-top: 8px;
|
||||||
|
padding-top: 7px;
|
||||||
|
border-top: 1px solid var(--line);
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
.forward-footer-action {
|
||||||
|
transition: color .15s ease;
|
||||||
|
}
|
||||||
|
.forward-modal-backdrop {
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 24px;
|
||||||
|
background: rgba(15, 23, 42, 0.36);
|
||||||
|
}
|
||||||
|
.forward-modal-window {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
width: min(560px, calc(100vw - 48px));
|
||||||
|
max-height: min(78vh, 720px);
|
||||||
|
overflow: hidden;
|
||||||
|
border: 1px solid var(--line);
|
||||||
|
border-radius: 14px;
|
||||||
|
background: #ffffff;
|
||||||
|
color: var(--ink);
|
||||||
|
box-shadow: 0 20px 48px rgba(15, 23, 42, 0.22);
|
||||||
|
}
|
||||||
|
.forward-modal-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 12px;
|
||||||
|
padding: 14px 18px;
|
||||||
|
border-bottom: 1px solid var(--line);
|
||||||
|
background: #f8fafc;
|
||||||
|
}
|
||||||
|
.forward-modal-header-text {
|
||||||
|
min-width: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 2px;
|
||||||
|
}
|
||||||
|
.forward-modal-title {
|
||||||
|
margin: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: 650;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.forward-modal-subtitle {
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
.forward-modal-close {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
width: 28px;
|
||||||
|
height: 28px;
|
||||||
|
border: 0;
|
||||||
|
border-radius: 8px;
|
||||||
|
background: transparent;
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: 20px;
|
||||||
|
line-height: 1;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.forward-modal-close:hover {
|
||||||
|
background: rgba(15, 23, 42, 0.08);
|
||||||
|
color: var(--ink);
|
||||||
|
}
|
||||||
|
.forward-modal-body {
|
||||||
|
flex: 1;
|
||||||
|
overflow-y: auto;
|
||||||
|
padding: 16px 18px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 16px;
|
||||||
|
}
|
||||||
|
.forward-modal-row {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 36px minmax(0, 1fr);
|
||||||
|
gap: 10px;
|
||||||
|
align-items: start;
|
||||||
|
}
|
||||||
|
.forward-modal-avatar {
|
||||||
|
width: 36px;
|
||||||
|
height: 36px;
|
||||||
|
border-radius: 8px;
|
||||||
|
overflow: hidden;
|
||||||
|
background: rgba(7, 193, 96, 0.14);
|
||||||
|
color: var(--accent);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font-size: 14px;
|
||||||
font-weight: 650;
|
font-weight: 650;
|
||||||
}
|
}
|
||||||
.forward-list, .forward-list ol {
|
.forward-modal-avatar img {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
.forward-modal-row-main {
|
||||||
|
min-width: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 6px;
|
||||||
|
padding-bottom: 12px;
|
||||||
|
border-bottom: 1px solid var(--line);
|
||||||
|
}
|
||||||
|
.forward-modal-row:last-child .forward-modal-row-main {
|
||||||
|
padding-bottom: 0;
|
||||||
|
border-bottom: 0;
|
||||||
|
}
|
||||||
|
.forward-modal-row-meta {
|
||||||
|
display: flex;
|
||||||
|
align-items: baseline;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
.forward-modal-sender {
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 650;
|
||||||
|
color: var(--ink);
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.forward-modal-time {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
font-size: 11px;
|
||||||
|
color: var(--muted);
|
||||||
|
}
|
||||||
|
.forward-modal-text {
|
||||||
|
font-size: 13px;
|
||||||
|
line-height: 1.6;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
word-break: break-word;
|
||||||
|
}
|
||||||
|
.forward-modal-link {
|
||||||
|
margin-left: 8px;
|
||||||
|
color: var(--accent);
|
||||||
|
font-size: 12px;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
.forward-modal-link:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
.forward-modal-image {
|
||||||
|
display: block;
|
||||||
|
max-width: min(240px, 100%);
|
||||||
|
max-height: 320px;
|
||||||
|
border-radius: 8px;
|
||||||
|
border: 1px solid var(--line);
|
||||||
|
object-fit: contain;
|
||||||
|
cursor: zoom-in;
|
||||||
|
}
|
||||||
|
.forward-modal-image-missing {
|
||||||
|
display: inline-block;
|
||||||
|
padding: 6px 10px;
|
||||||
|
border-radius: 8px;
|
||||||
|
background: #f1f5f9;
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
.forward-modal-nested-card {
|
||||||
|
width: min(320px, 100%);
|
||||||
|
padding: 10px 12px;
|
||||||
|
border: 1px solid var(--line);
|
||||||
|
border-radius: 10px;
|
||||||
|
background: #f8fafc;
|
||||||
|
color: inherit;
|
||||||
|
text-align: left;
|
||||||
display: grid;
|
display: grid;
|
||||||
gap: 7px;
|
gap: 6px;
|
||||||
margin: 8px 0 0;
|
cursor: pointer;
|
||||||
padding-left: 18px;
|
}
|
||||||
|
.forward-modal-nested-card:hover {
|
||||||
|
border-color: var(--accent);
|
||||||
|
}
|
||||||
|
.forward-modal-nested-title {
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 650;
|
||||||
|
color: var(--ink);
|
||||||
|
}
|
||||||
|
.forward-modal-nested-line {
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--muted);
|
||||||
|
}
|
||||||
|
.forward-modal-nested-footer {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding-top: 6px;
|
||||||
|
border-top: 1px solid var(--line);
|
||||||
|
font-size: 11px;
|
||||||
|
color: var(--muted);
|
||||||
|
}
|
||||||
|
.forward-modal-empty {
|
||||||
|
padding: 32px 0;
|
||||||
|
text-align: center;
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: 13px;
|
||||||
}
|
}
|
||||||
.forward-item { color: var(--muted); font-size: 12px; line-height: 1.5; }
|
.forward-item { color: var(--muted); font-size: 12px; line-height: 1.5; }
|
||||||
.forward-item strong { color: var(--text); font-weight: 650; }
|
.forward-item strong { color: var(--text); font-weight: 650; }
|
||||||
@@ -687,7 +914,7 @@ body {
|
|||||||
display: none;
|
display: none;
|
||||||
place-items: center;
|
place-items: center;
|
||||||
background: #14231ddd;
|
background: #14231ddd;
|
||||||
z-index: 10;
|
z-index: 80;
|
||||||
padding: 24px;
|
padding: 24px;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
}
|
}
|
||||||
@@ -705,7 +932,7 @@ body {
|
|||||||
position: fixed;
|
position: fixed;
|
||||||
top: 20px;
|
top: 20px;
|
||||||
right: 20px;
|
right: 20px;
|
||||||
z-index: 11;
|
z-index: 81;
|
||||||
width: 42px;
|
width: 42px;
|
||||||
height: 42px;
|
height: 42px;
|
||||||
border: 1px solid #ffffff66;
|
border: 1px solid #ffffff66;
|
||||||
@@ -1121,27 +1348,26 @@ const renderExportScript = (name: string): string => `
|
|||||||
(iconUrl ? '<img class="mini-program-icon" src="' + iconUrl + '" alt="">' : '') +
|
(iconUrl ? '<img class="mini-program-icon" src="' + iconUrl + '" alt="">' : '') +
|
||||||
'<span>' + displayText(data.appName || '小程序') + '</span></div></div>'
|
'<span>' + displayText(data.appName || '小程序') + '</span></div></div>'
|
||||||
}
|
}
|
||||||
const renderForwardItems = (items, depth = 0) => {
|
const renderForwardContent = (data, archiveIndex) => {
|
||||||
if (!Array.isArray(items) || !items.length || depth > 4) return ''
|
|
||||||
return '<ol class="forward-list">' + items.map((item) =>
|
|
||||||
'<li class="forward-item">' +
|
|
||||||
(item.sender ? '<strong>' + displayText(item.sender) + '</strong>' : '') +
|
|
||||||
(item.sentAt ? '<time>' + displayText(item.sentAt) + '</time>' : '') +
|
|
||||||
'<span>' + displayText(item.text || '[消息]') + '</span>' +
|
|
||||||
renderForwardItems(item.nested, depth + 1) + '</li>'
|
|
||||||
).join('') + '</ol>'
|
|
||||||
}
|
|
||||||
const renderForwardContent = (data) => {
|
|
||||||
const items = Array.isArray(data.items) ? data.items : []
|
const items = Array.isArray(data.items) ? data.items : []
|
||||||
return '<div class="structured-content forward-content" data-rich-kind="forwardBundle">' +
|
const previewItems = items.slice(0, 4)
|
||||||
|
const previewHtml = previewItems.length
|
||||||
|
? '<div class="forward-preview-list">' + previewItems.map((item) =>
|
||||||
|
'<div class="forward-preview-line">' +
|
||||||
|
(item.sender ? '<strong>' + displayText(item.sender) + ':</strong>' : '') +
|
||||||
|
'<span>' + displayText(item.text || '[消息]') + '</span></div>'
|
||||||
|
).join('') + '</div>'
|
||||||
|
: (data.description
|
||||||
|
? '<div class="structured-description">' + displayText(data.description) + '</div>'
|
||||||
|
: '')
|
||||||
|
return '<div class="structured-content forward-content is-clickable" data-rich-kind="forwardBundle" data-forward-open="' +
|
||||||
|
archiveIndex + '" role="button" tabindex="0">' +
|
||||||
'<div class="structured-kicker">聊天记录</div>' +
|
'<div class="structured-kicker">聊天记录</div>' +
|
||||||
'<div class="structured-title">' + displayText(data.title || '聊天记录') + '</div>' +
|
'<div class="structured-title">' + displayText(data.title || '聊天记录') + '</div>' +
|
||||||
(!items.length && data.description
|
previewHtml +
|
||||||
? '<div class="structured-description">' + displayText(data.description) + '</div>'
|
'<div class="forward-footer"><span>' +
|
||||||
: '') +
|
(items.length ? '共 ' + items.length + ' 条消息' : '聊天记录') +
|
||||||
(items.length
|
'</span><span class="forward-footer-action">查看详情</span></div></div>'
|
||||||
? '<details><summary>展开 ' + items.length + ' 条消息</summary>' + renderForwardItems(items) + '</details>'
|
|
||||||
: '') + '</div>'
|
|
||||||
}
|
}
|
||||||
const renderLocationContent = (data) => {
|
const renderLocationContent = (data) => {
|
||||||
const latitude = Number(data.lat)
|
const latitude = Number(data.lat)
|
||||||
@@ -1195,7 +1421,7 @@ const renderExportScript = (name: string): string => `
|
|||||||
displayText([data.status, durationText].filter(Boolean).join(' · ') || '通话消息') +
|
displayText([data.status, durationText].filter(Boolean).join(' · ') || '通话消息') +
|
||||||
'</div></div>'
|
'</div></div>'
|
||||||
}
|
}
|
||||||
const renderStructuredContent = (data) => {
|
const renderStructuredContent = (data, archiveIndex) => {
|
||||||
if (data.type === 'share') {
|
if (data.type === 'share') {
|
||||||
const typeVal = String(data.typeVal || '')
|
const typeVal = String(data.typeVal || '')
|
||||||
if (typeVal === '6' || typeVal === '74') return ''
|
if (typeVal === '6' || typeVal === '74') return ''
|
||||||
@@ -1203,7 +1429,7 @@ const renderExportScript = (name: string): string => `
|
|||||||
return renderShareContent(data)
|
return renderShareContent(data)
|
||||||
}
|
}
|
||||||
if (data.type === 'miniProgram') return renderMiniProgramContent(data)
|
if (data.type === 'miniProgram') return renderMiniProgramContent(data)
|
||||||
if (data.type === 'forwardBundle') return renderForwardContent(data)
|
if (data.type === 'forwardBundle') return renderForwardContent(data, archiveIndex)
|
||||||
if (data.type === 'location') return renderLocationContent(data)
|
if (data.type === 'location') return renderLocationContent(data)
|
||||||
if (data.type === 'redPacket') return renderPaymentContent(data, 'redPacket')
|
if (data.type === 'redPacket') return renderPaymentContent(data, 'redPacket')
|
||||||
if (data.type === 'voip') return renderVoipContent(data)
|
if (data.type === 'voip') return renderVoipContent(data)
|
||||||
@@ -1248,7 +1474,7 @@ const renderExportScript = (name: string): string => `
|
|||||||
const quote = data.type === 'quote'
|
const quote = data.type === 'quote'
|
||||||
? '<div class="quote-reference"><strong>' + esc(data.quotedSender || '引用消息') + '</strong><span>' + esc(data.quotedContent || '[引用消息]') + '</span></div>'
|
? '<div class="quote-reference"><strong>' + esc(data.quotedSender || '引用消息') + '</strong><span>' + esc(data.quotedContent || '[引用消息]') + '</span></div>'
|
||||||
: ''
|
: ''
|
||||||
const structured = renderStructuredContent(data)
|
const structured = renderStructuredContent(data, archiveIndex)
|
||||||
const isSystem = data.type === 'system'
|
const isSystem = data.type === 'system'
|
||||||
const sender = message.name || (message.isSender ? '我' : '联系人')
|
const sender = message.name || (message.isSender ? '我' : '联系人')
|
||||||
const avatarFallback = esc(String(sender || '友').slice(0, 1))
|
const avatarFallback = esc(String(sender || '友').slice(0, 1))
|
||||||
@@ -1803,25 +2029,174 @@ const renderExportScript = (name: string): string => `
|
|||||||
if (dayButton) jumpToDate(dayButton.dataset.date)
|
if (dayButton) jumpToDate(dayButton.dataset.date)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const forwardModalRoot = document.getElementById('forward-modal-root')
|
||||||
|
let forwardModalLayers = []
|
||||||
|
|
||||||
|
const formatForwardTime = (raw) => {
|
||||||
|
const value = String(raw || '').trim()
|
||||||
|
if (!value) return ''
|
||||||
|
if (/^\\d{9,13}$/.test(value)) {
|
||||||
|
const ms = value.length > 10 ? Number(value) : Number(value) * 1000
|
||||||
|
const date = new Date(ms)
|
||||||
|
if (!Number.isNaN(date.getTime())) {
|
||||||
|
return date.getFullYear() + '-' + pad(date.getMonth() + 1) + '-' + pad(date.getDate()) +
|
||||||
|
' ' + pad(date.getHours()) + ':' + pad(date.getMinutes())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
const renderForwardModalRow = (item, layerIndex, itemIndex) => {
|
||||||
|
const sender = item.sender || '未知发送者'
|
||||||
|
const initial = esc(Array.from(String(sender).trim())[0] || '?')
|
||||||
|
const headUrl = externalUrl(item.sourceHeadUrl || '')
|
||||||
|
const avatarHtml = headUrl
|
||||||
|
? '<div class="forward-modal-avatar"><img src="' + headUrl + '" alt="" loading="lazy" referrerpolicy="no-referrer" onerror="this.remove()"></div>'
|
||||||
|
: '<div class="forward-modal-avatar">' + initial + '</div>'
|
||||||
|
const timeText = formatForwardTime(item.sentAt)
|
||||||
|
const isNested = item.messageType === 17 || (Array.isArray(item.nested) && item.nested.length > 0)
|
||||||
|
const isImage = !isNested && (item.messageType === 2 || Boolean(item.exportMediaUrl || item.imageMd5 || item.thumbMd5 || item.imageDatName))
|
||||||
|
let bodyHtml = ''
|
||||||
|
if (isNested) {
|
||||||
|
const nestedTitle = item.nestedTitle || item.title || '聊天记录'
|
||||||
|
const nestedItems = Array.isArray(item.nested) ? item.nested : []
|
||||||
|
const previewLines = nestedItems.slice(0, 3).map((child) =>
|
||||||
|
'<div class="forward-modal-nested-line">' +
|
||||||
|
(child.sender ? esc(child.sender) + ': ' : '') +
|
||||||
|
displayText(child.text || '[消息]') + '</div>'
|
||||||
|
).join('')
|
||||||
|
bodyHtml = '<button type="button" class="forward-modal-nested-card" data-forward-nested-layer="' +
|
||||||
|
layerIndex + '" data-forward-nested-item="' + itemIndex + '"' +
|
||||||
|
(nestedItems.length ? '' : ' disabled') + '>' +
|
||||||
|
'<div class="forward-modal-nested-title">' + displayText(nestedTitle) + '</div>' +
|
||||||
|
(previewLines || '<div class="forward-modal-nested-line">' + displayText(item.text || '[聊天记录]') + '</div>') +
|
||||||
|
'<div class="forward-modal-nested-footer"><span>聊天记录</span><span>' +
|
||||||
|
(nestedItems.length ? '共 ' + nestedItems.length + ' 条 · 打开新窗口' : '') +
|
||||||
|
'</span></div></button>'
|
||||||
|
} else if (isImage) {
|
||||||
|
bodyHtml = item.exportMediaUrl
|
||||||
|
? '<img class="forward-modal-image" data-preview src="' + esc(item.exportMediaUrl) + '" alt="图片">'
|
||||||
|
: '<span class="forward-modal-image-missing">[图片未导出到本地]</span>'
|
||||||
|
} else {
|
||||||
|
const linkHref = externalUrl(item.linkUrl || '')
|
||||||
|
bodyHtml = '<div class="forward-modal-text">' + displayText(item.text || item.title || '[消息]') +
|
||||||
|
(linkHref ? '<a class="forward-modal-link" href="' + linkHref + '" target="_blank" rel="noreferrer noopener">打开链接 ↗</a>' : '') +
|
||||||
|
'</div>'
|
||||||
|
}
|
||||||
|
return '<article class="forward-modal-row">' + avatarHtml +
|
||||||
|
'<div class="forward-modal-row-main"><header class="forward-modal-row-meta">' +
|
||||||
|
'<span class="forward-modal-sender">' + displayText(sender) + '</span>' +
|
||||||
|
(timeText ? '<time class="forward-modal-time">' + esc(timeText) + '</time>' : '') +
|
||||||
|
'</header><div>' + bodyHtml + '</div></div></article>'
|
||||||
|
}
|
||||||
|
|
||||||
|
const renderForwardModals = () => {
|
||||||
|
if (!forwardModalRoot) return
|
||||||
|
if (!forwardModalLayers.length) {
|
||||||
|
forwardModalRoot.innerHTML = ''
|
||||||
|
return
|
||||||
|
}
|
||||||
|
forwardModalRoot.innerHTML = forwardModalLayers.map((layer, index) => {
|
||||||
|
const zIndex = Math.min(75, 30 + index)
|
||||||
|
const offsetX = Math.min(index, 5) * 28
|
||||||
|
const offsetY = Math.min(index, 5) * 24
|
||||||
|
const items = Array.isArray(layer.items) ? layer.items : []
|
||||||
|
const rowsHtml = items.length
|
||||||
|
? items.map((item, itemIdx) => renderForwardModalRow(item, index, itemIdx)).join('')
|
||||||
|
: '<div class="forward-modal-empty">暂未解析到可展示的记录</div>'
|
||||||
|
return '<div class="forward-modal-backdrop" data-forward-backdrop="' + index + '" style="z-index:' + zIndex + '">' +
|
||||||
|
'<section class="forward-modal-window" role="dialog" aria-modal="true" aria-label="' + esc(layer.title || '聊天记录') +
|
||||||
|
'" style="transform:translate(' + offsetX + 'px,' + offsetY + 'px)">' +
|
||||||
|
'<header class="forward-modal-header"><div class="forward-modal-header-text">' +
|
||||||
|
'<h3 class="forward-modal-title">' + displayText(layer.title || '聊天记录') + '</h3>' +
|
||||||
|
'<span class="forward-modal-subtitle">共 ' + items.length + ' 条消息' +
|
||||||
|
(index > 0 ? ' · 嵌套窗口 #' + (index + 1) : '') + '</span></div>' +
|
||||||
|
'<button type="button" class="forward-modal-close" data-forward-close="' + index + '" aria-label="关闭聊天记录窗口">×</button>' +
|
||||||
|
'</header><div class="forward-modal-body">' + rowsHtml + '</div></section></div>'
|
||||||
|
}).join('')
|
||||||
|
}
|
||||||
|
|
||||||
|
const openForwardModal = (titleText, items) => {
|
||||||
|
forwardModalLayers = [{ title: titleText || '聊天记录', items: Array.isArray(items) ? items : [] }]
|
||||||
|
renderForwardModals()
|
||||||
|
}
|
||||||
|
|
||||||
|
const pushNestedForwardModal = (layerIndex, itemIndex) => {
|
||||||
|
const parentLayer = forwardModalLayers[layerIndex]
|
||||||
|
const item = parentLayer && Array.isArray(parentLayer.items) ? parentLayer.items[itemIndex] : null
|
||||||
|
if (!item || !Array.isArray(item.nested) || !item.nested.length) return
|
||||||
|
forwardModalLayers = forwardModalLayers.slice(0, layerIndex + 1).concat([{
|
||||||
|
title: item.nestedTitle || item.title || '聊天记录',
|
||||||
|
items: item.nested
|
||||||
|
}])
|
||||||
|
renderForwardModals()
|
||||||
|
}
|
||||||
|
|
||||||
|
const closeForwardModalFrom = (index) => {
|
||||||
|
forwardModalLayers = forwardModalLayers.slice(0, index)
|
||||||
|
renderForwardModals()
|
||||||
|
}
|
||||||
|
|
||||||
const updateZoom = () => preview.style.setProperty('--zoom', zoom)
|
const updateZoom = () => preview.style.setProperty('--zoom', zoom)
|
||||||
const closeLightbox = () => {
|
const closeLightbox = () => {
|
||||||
box.classList.remove('open')
|
box.classList.remove('open')
|
||||||
zoom = 1
|
zoom = 1
|
||||||
updateZoom()
|
updateZoom()
|
||||||
}
|
}
|
||||||
|
const openLightbox = (src) => {
|
||||||
|
preview.src = src
|
||||||
|
zoom = 1
|
||||||
|
updateZoom()
|
||||||
|
box.classList.add('open')
|
||||||
|
}
|
||||||
list.addEventListener('click', (event) => {
|
list.addEventListener('click', (event) => {
|
||||||
const locateButton = event.target.closest('[data-locate-index]')
|
const locateButton = event.target.closest('[data-locate-index]')
|
||||||
if (locateButton) {
|
if (locateButton) {
|
||||||
locateInAll(Number(locateButton.dataset.locateIndex))
|
locateInAll(Number(locateButton.dataset.locateIndex))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
const forwardCard = event.target.closest('[data-forward-open]')
|
||||||
|
if (forwardCard) {
|
||||||
|
const msgIndex = Number(forwardCard.dataset.forwardOpen)
|
||||||
|
// data-forward-open 写的是 filtered 下标(renderWindow 用 windowStart + index),
|
||||||
|
// 不能用 allMessages[msgIndex]:切会话 / 搜索 / 按类型筛选后 filtered 会比全集短。
|
||||||
|
const targetMessage = filtered[msgIndex]
|
||||||
|
const bundle = targetMessage && targetMessage.contentData
|
||||||
|
if (bundle && bundle.type === 'forwardBundle') {
|
||||||
|
openForwardModal(bundle.title || '聊天记录', bundle.items || [])
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
const image = event.target.closest('img[data-preview]')
|
const image = event.target.closest('img[data-preview]')
|
||||||
if (!image) return
|
if (!image) return
|
||||||
preview.src = image.src
|
openLightbox(image.src)
|
||||||
zoom = 1
|
|
||||||
updateZoom()
|
|
||||||
box.classList.add('open')
|
|
||||||
})
|
})
|
||||||
|
if (forwardModalRoot) {
|
||||||
|
forwardModalRoot.addEventListener('click', (event) => {
|
||||||
|
const closeBtn = event.target.closest('[data-forward-close]')
|
||||||
|
if (closeBtn) {
|
||||||
|
closeForwardModalFrom(Number(closeBtn.dataset.forwardClose))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const nestedBtn = event.target.closest('[data-forward-nested-layer]')
|
||||||
|
if (nestedBtn) {
|
||||||
|
pushNestedForwardModal(
|
||||||
|
Number(nestedBtn.dataset.forwardNestedLayer),
|
||||||
|
Number(nestedBtn.dataset.forwardNestedItem)
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const img = event.target.closest('img[data-preview]')
|
||||||
|
if (img) {
|
||||||
|
openLightbox(img.src)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const backdrop = event.target.closest('[data-forward-backdrop]')
|
||||||
|
if (backdrop && event.target === backdrop) {
|
||||||
|
closeForwardModalFrom(Number(backdrop.dataset.forwardBackdrop))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
preview.addEventListener('wheel', (event) => {
|
preview.addEventListener('wheel', (event) => {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
zoom = Math.min(5, Math.max(.5, zoom + (event.deltaY < 0 ? .2 : -.2)))
|
zoom = Math.min(5, Math.max(.5, zoom + (event.deltaY < 0 ? .2 : -.2)))
|
||||||
@@ -1837,7 +2212,11 @@ const renderExportScript = (name: string): string => `
|
|||||||
closeButton.addEventListener('click', closeLightbox)
|
closeButton.addEventListener('click', closeLightbox)
|
||||||
document.addEventListener('keydown', (event) => {
|
document.addEventListener('keydown', (event) => {
|
||||||
if (event.key === 'Escape') {
|
if (event.key === 'Escape') {
|
||||||
|
if (box.classList.contains('open')) {
|
||||||
closeLightbox()
|
closeLightbox()
|
||||||
|
} else if (forwardModalLayers.length > 0) {
|
||||||
|
closeForwardModalFrom(forwardModalLayers.length - 1)
|
||||||
|
}
|
||||||
setConversationMenuOpen(false)
|
setConversationMenuOpen(false)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -1940,6 +2319,7 @@ export function renderExportPage(name: string): string {
|
|||||||
</section>
|
</section>
|
||||||
</section>
|
</section>
|
||||||
</main>
|
</main>
|
||||||
|
<div id="forward-modal-root"></div>
|
||||||
<div class="lightbox" id="lightbox">
|
<div class="lightbox" id="lightbox">
|
||||||
<button class="lightbox-close" id="lightbox-close" type="button" aria-label="关闭图片预览">×</button>
|
<button class="lightbox-close" id="lightbox-close" type="button" aria-label="关闭图片预览">×</button>
|
||||||
<img id="lightbox-image" alt="预览">
|
<img id="lightbox-image" alt="预览">
|
||||||
|
|||||||
@@ -524,11 +524,28 @@ export async function pruneHtmlArchiveResources(
|
|||||||
referenced[directory].add(fileName)
|
referenced[directory].add(fileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const addForwardBundleReferences = (
|
||||||
|
items?: Array<{ exportMediaUrl?: string; nested?: Array<{ exportMediaUrl?: string; nested?: unknown[] }> }>
|
||||||
|
): void => {
|
||||||
|
if (!Array.isArray(items)) return
|
||||||
|
for (const item of items) {
|
||||||
|
addReference(item.exportMediaUrl)
|
||||||
|
if (Array.isArray(item.nested)) {
|
||||||
|
addForwardBundleReferences(
|
||||||
|
item.nested as Array<{ exportMediaUrl?: string; nested?: Array<{ exportMediaUrl?: string; nested?: unknown[] }> }>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (const conversation of archive.conversations) addReference(conversation.avatarUrl)
|
for (const conversation of archive.conversations) addReference(conversation.avatarUrl)
|
||||||
for (const message of archive.messages) {
|
for (const message of archive.messages) {
|
||||||
addReference(message.voiceDataUrl)
|
addReference(message.voiceDataUrl)
|
||||||
addReference(message.exportMediaUrl)
|
addReference(message.exportMediaUrl)
|
||||||
addReference(message.exportAvatarUrl)
|
addReference(message.exportAvatarUrl)
|
||||||
|
if (message.contentData?.type === 'forwardBundle') {
|
||||||
|
addForwardBundleReferences(message.contentData.items)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const [directory, prefixes] of Object.entries(htmlArchiveResourcePrefixes) as [
|
for (const [directory, prefixes] of Object.entries(htmlArchiveResourcePrefixes) as [
|
||||||
@@ -1513,6 +1530,75 @@ async function runSingleExport(
|
|||||||
} else {
|
} else {
|
||||||
keepMediaError(request, message, result.error || '表情资源缺失或下载失败')
|
keepMediaError(request, message, result.error || '表情资源缺失或下载失败')
|
||||||
}
|
}
|
||||||
|
} else if (message.contentData.type === 'forwardBundle' && imageService) {
|
||||||
|
const exportForwardItems = async (
|
||||||
|
items: Array<{
|
||||||
|
messageType: number
|
||||||
|
imageMd5?: string
|
||||||
|
thumbMd5?: string
|
||||||
|
imageDatName?: string
|
||||||
|
exportMediaUrl?: string
|
||||||
|
nested?: unknown[]
|
||||||
|
}>,
|
||||||
|
depth = 0
|
||||||
|
): Promise<void> => {
|
||||||
|
if (!Array.isArray(items) || depth > 8) return
|
||||||
|
for (const item of items) {
|
||||||
|
if (Array.isArray(item.nested) && item.nested.length > 0) {
|
||||||
|
await exportForwardItems(
|
||||||
|
item.nested as typeof items,
|
||||||
|
depth + 1
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
const isForwardImage =
|
||||||
|
item.messageType === 2 ||
|
||||||
|
Boolean(item.imageMd5 || item.thumbMd5 || item.imageDatName)
|
||||||
|
if (!isForwardImage) continue
|
||||||
|
if (item.exportMediaUrl && (await resourceExists(item.exportMediaUrl))) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
let decryptedImage: { data: string; filePath: string } | null = null
|
||||||
|
for (const attempt of getImageExportAttempts(request)) {
|
||||||
|
const file = await imageService.findImageFileAsync(
|
||||||
|
item.imageMd5 || item.thumbMd5,
|
||||||
|
item.imageDatName,
|
||||||
|
{
|
||||||
|
allowThumbnail: attempt.allowThumbnail,
|
||||||
|
preferThumbnail: attempt.preferThumbnail,
|
||||||
|
sessionId: message.sessionId,
|
||||||
|
sessionMd5: conversationId,
|
||||||
|
createTime: message.createTime
|
||||||
|
}
|
||||||
|
)
|
||||||
|
if (!file) continue
|
||||||
|
let decrypted = await imageService.decryptImageToBase64WithFallbackAsync(
|
||||||
|
file,
|
||||||
|
attempt.allowThumbnail
|
||||||
|
)
|
||||||
|
if (!decrypted) {
|
||||||
|
decrypted = imageService.decryptImageToBase64WithFallback(
|
||||||
|
file,
|
||||||
|
attempt.allowThumbnail
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (!decrypted) continue
|
||||||
|
decryptedImage = decrypted
|
||||||
|
break
|
||||||
|
}
|
||||||
|
const decoded = decryptedImage ? decodeDataUrl(decryptedImage.data) : null
|
||||||
|
if (decoded) {
|
||||||
|
const name = `image_${bufferHashPart(decoded.buffer)}.${decoded.extension}`
|
||||||
|
const mediaUrl = `media/${name}`
|
||||||
|
if (!(await resourceExists(mediaUrl))) {
|
||||||
|
await fs.writeFile(join(outputDir, 'media', name), decoded.buffer)
|
||||||
|
markResourceExists(mediaUrl)
|
||||||
|
}
|
||||||
|
item.exportMediaUrl = mediaUrl
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await exportForwardItems(message.contentData.items)
|
||||||
} else if (message.contentData.type === 'share' && message.contentData.typeVal === '6') {
|
} else if (message.contentData.type === 'share' && message.contentData.typeVal === '6') {
|
||||||
if (!fileService) {
|
if (!fileService) {
|
||||||
keepMediaError(request, message, '数据库未连接,无法定位本地文件附件')
|
keepMediaError(request, message, '数据库未连接,无法定位本地文件附件')
|
||||||
|
|||||||
@@ -210,12 +210,16 @@ function normalizeDatBase(value) {
|
|||||||
|
|
||||||
function isThumbnailName(fileName) {
|
function isThumbnailName(fileName) {
|
||||||
const lower = fileName.toLowerCase()
|
const lower = fileName.toLowerCase()
|
||||||
|
if (!lower.endsWith('.dat')) {
|
||||||
|
return /(?:_t(?:_m)?|_thumb|\.thumb)$/i.test(lower)
|
||||||
|
}
|
||||||
return /(?:_t(?:_m)?|_thumb|\.thumb|_b|_w|_c)\.dat$/i.test(lower)
|
return /(?:_t(?:_m)?|_thumb|\.thumb|_b|_w|_c)\.dat$/i.test(lower)
|
||||||
}
|
}
|
||||||
|
|
||||||
function imageQualityRank(fileName) {
|
function imageQualityRank(fileName) {
|
||||||
const lower = fileName.toLowerCase()
|
const lower = fileName.toLowerCase()
|
||||||
if (/(?:_t(?:_m)?|_thumb|\.thumb|_b|_w|_c)\.dat$/i.test(lower)) return 1
|
if (isThumbnailName(lower)) return 1
|
||||||
|
if (!lower.endsWith('.dat')) return 3
|
||||||
if (/(?:_hd|\.hd|_h_m|_h|\.h)\.dat$/i.test(lower)) return 3
|
if (/(?:_hd|\.hd|_h_m|_h|\.h)\.dat$/i.test(lower)) return 3
|
||||||
return 2
|
return 2
|
||||||
}
|
}
|
||||||
@@ -239,6 +243,20 @@ function buildPreferredDatNames(baseName) {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buildExtensionlessVariantNames(baseName) {
|
||||||
|
const base = normalizeDatBase(baseName)
|
||||||
|
if (!base) return []
|
||||||
|
return [
|
||||||
|
base + '_hd',
|
||||||
|
base + '_h_M',
|
||||||
|
base + '_h',
|
||||||
|
base + '_M',
|
||||||
|
base,
|
||||||
|
base + '_t_M',
|
||||||
|
base + '_t'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
function detectImageExtension(buffer) {
|
function detectImageExtension(buffer) {
|
||||||
if (buffer.length < 4) return null
|
if (buffer.length < 4) return null
|
||||||
if (buffer[0] === 0xff && buffer[1] === 0xd8 && buffer[2] === 0xff) return '.jpg'
|
if (buffer[0] === 0xff && buffer[1] === 0xd8 && buffer[2] === 0xff) return '.jpg'
|
||||||
@@ -386,10 +404,6 @@ function decryptCandidate(filePath, aesKey, xorKey, ffmpegPath) {
|
|||||||
filePath
|
filePath
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!path.extname(filePath).toLowerCase().includes('dat')) {
|
|
||||||
const extension = path.extname(filePath).toLowerCase()
|
|
||||||
return { data: 'data:' + getMimeType(extension) + ';base64,' + bytes.toString('base64'), filePath }
|
|
||||||
}
|
|
||||||
if (
|
if (
|
||||||
bytes.length < 15 ||
|
bytes.length < 15 ||
|
||||||
bytes[0] !== 0x07 ||
|
bytes[0] !== 0x07 ||
|
||||||
@@ -440,10 +454,12 @@ function decryptCandidate(filePath, aesKey, xorKey, ffmpegPath) {
|
|||||||
|
|
||||||
function collectCandidates(datPath, allowThumbnail) {
|
function collectCandidates(datPath, allowThumbnail) {
|
||||||
const candidates = [datPath]
|
const candidates = [datPath]
|
||||||
if (!path.extname(datPath).toLowerCase().includes('dat')) return candidates
|
|
||||||
const directory = path.dirname(datPath)
|
const directory = path.dirname(datPath)
|
||||||
const base = normalizeDatBase(path.basename(datPath))
|
const base = normalizeDatBase(path.basename(datPath))
|
||||||
const siblings = buildPreferredDatNames(base)
|
const names = path.extname(datPath).toLowerCase().includes('dat')
|
||||||
|
? buildPreferredDatNames(base)
|
||||||
|
: buildExtensionlessVariantNames(base).concat(buildPreferredDatNames(base))
|
||||||
|
const siblings = names
|
||||||
.filter((name) => allowThumbnail || !isThumbnailName(name))
|
.filter((name) => allowThumbnail || !isThumbnailName(name))
|
||||||
.map((name) => path.join(directory, name))
|
.map((name) => path.join(directory, name))
|
||||||
.filter((candidate) => fs.existsSync(candidate))
|
.filter((candidate) => fs.existsSync(candidate))
|
||||||
@@ -606,9 +622,23 @@ export class ImageDecryptService {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const attachDir = join(accountDir, 'msg', 'attach')
|
const attachDir = join(accountDir, 'msg', 'attach')
|
||||||
|
const recRef = this.parseForwardRecordImageRef(imageDatName)
|
||||||
|
if (recRef && existsSync(attachDir)) {
|
||||||
|
const recHit = this.findForwardRecordImage(
|
||||||
|
attachDir,
|
||||||
|
recRef.recordDir,
|
||||||
|
recRef.fileIndex,
|
||||||
|
allowThumbnail,
|
||||||
|
options?.preferThumbnail,
|
||||||
|
sessionDirectory,
|
||||||
|
options?.createTime
|
||||||
|
)
|
||||||
|
if (recHit) return rememberPath(recHit)
|
||||||
|
}
|
||||||
|
|
||||||
// The attach directory stores DAT filenames, while the message MD5 often
|
// The attach directory stores DAT filenames, while the message MD5 often
|
||||||
// identifies the original image rather than the local file.
|
// identifies the original image rather than the local file.
|
||||||
const searchKeys = this.uniq([normalizedDatName, normalizedMd5])
|
const searchKeys = this.uniq([recRef ? '' : normalizedDatName, normalizedMd5])
|
||||||
|
|
||||||
if (sessionDirectory && allowThumbnail && options?.preferThumbnail) {
|
if (sessionDirectory && allowThumbnail && options?.preferThumbnail) {
|
||||||
const bubblePreview = this.findBubblePreview(
|
const bubblePreview = this.findBubblePreview(
|
||||||
@@ -939,7 +969,21 @@ export class ImageDecryptService {
|
|||||||
if (!accountDir) return null
|
if (!accountDir) return null
|
||||||
|
|
||||||
const attachDir = join(accountDir, 'msg', 'attach')
|
const attachDir = join(accountDir, 'msg', 'attach')
|
||||||
const searchKeys = this.uniq([normalizedDatName, normalizedMd5])
|
const recRef = this.parseForwardRecordImageRef(imageDatName)
|
||||||
|
if (recRef && existsSync(attachDir)) {
|
||||||
|
const recHit = await this.findForwardRecordImageAsync(
|
||||||
|
attachDir,
|
||||||
|
recRef.recordDir,
|
||||||
|
recRef.fileIndex,
|
||||||
|
allowThumbnail,
|
||||||
|
options?.preferThumbnail,
|
||||||
|
sessionDirectory,
|
||||||
|
options?.createTime
|
||||||
|
)
|
||||||
|
if (recHit) return rememberPath(recHit)
|
||||||
|
}
|
||||||
|
|
||||||
|
const searchKeys = this.uniq([recRef ? '' : normalizedDatName, normalizedMd5])
|
||||||
if (allowThumbnail && options?.preferThumbnail) {
|
if (allowThumbnail && options?.preferThumbnail) {
|
||||||
const bubblePreview = await this.findBubblePreviewAsync(
|
const bubblePreview = await this.findBubblePreviewAsync(
|
||||||
accountDir,
|
accountDir,
|
||||||
@@ -1422,15 +1466,19 @@ export class ImageDecryptService {
|
|||||||
if (!extname(datPath).toLowerCase().includes('dat')) {
|
if (!extname(datPath).toLowerCase().includes('dat')) {
|
||||||
try {
|
try {
|
||||||
const data = readFileSync(datPath)
|
const data = readFileSync(datPath)
|
||||||
const ext = this.detectImageExtension(data) || extname(datPath).toLowerCase()
|
const detectedExt = this.detectImageExtension(data)
|
||||||
const mimeType = this.getMimeType(ext)
|
if (detectedExt) {
|
||||||
|
const mimeType = this.getMimeType(detectedExt)
|
||||||
this.lastDecodeDiagnostic = {
|
this.lastDecodeDiagnostic = {
|
||||||
code: 'DIRECT_IMAGE',
|
code: 'DIRECT_IMAGE',
|
||||||
detail: '文件本身是可直接读取的图片',
|
detail: '文件本身是可直接读取的图片',
|
||||||
fileSize: data.length,
|
fileSize: data.length,
|
||||||
imageFormat: ext.replace(/^\./, '').toUpperCase()
|
imageFormat: detectedExt.replace(/^\./, '').toUpperCase()
|
||||||
}
|
}
|
||||||
return `data:${mimeType};base64,${data.toString('base64')}`
|
return `data:${mimeType};base64,${data.toString('base64')}`
|
||||||
|
}
|
||||||
|
// 合并转发 Rec/{token}/Img/{index} 文件没有 .dat 扩展名,但内部仍是 WeChat 4.0 V2 加密 DAT,
|
||||||
|
// 若不是明文图片头则继续向下走 decryptImage 解密。
|
||||||
} catch {
|
} catch {
|
||||||
this.lastDecodeDiagnostic = {
|
this.lastDecodeDiagnostic = {
|
||||||
code: 'FILE_NOT_FOUND',
|
code: 'FILE_NOT_FOUND',
|
||||||
@@ -1798,6 +1846,108 @@ export class ImageDecryptService {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private parseForwardRecordImageRef(
|
||||||
|
imageDatName?: string
|
||||||
|
): { recordDir: string; fileIndex: string } | null {
|
||||||
|
const raw = String(imageDatName || '').trim()
|
||||||
|
const match = /^rec:([a-zA-Z0-9_-]+):(\d+)$/i.exec(raw)
|
||||||
|
if (!match) return null
|
||||||
|
return { recordDir: match[1], fileIndex: match[2] }
|
||||||
|
}
|
||||||
|
|
||||||
|
private buildForwardRecordImageNames(fileIndex: string): string[] {
|
||||||
|
return [
|
||||||
|
`${fileIndex}_hd`,
|
||||||
|
`${fileIndex}_h_M`,
|
||||||
|
`${fileIndex}_h`,
|
||||||
|
`${fileIndex}_M`,
|
||||||
|
`${fileIndex}`,
|
||||||
|
`${fileIndex}_t_M`,
|
||||||
|
`${fileIndex}_t`,
|
||||||
|
`${fileIndex}.dat`,
|
||||||
|
`${fileIndex}_t.dat`
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
private findForwardRecordImage(
|
||||||
|
attachDir: string,
|
||||||
|
recordDir: string,
|
||||||
|
fileIndex: string,
|
||||||
|
allowThumbnail: boolean,
|
||||||
|
preferThumbnail = false,
|
||||||
|
sessionDirectory = '',
|
||||||
|
createTime?: number
|
||||||
|
): string | null {
|
||||||
|
const candidateNames = this.buildForwardRecordImageNames(fileIndex)
|
||||||
|
const sessionDirs = sessionDirectory
|
||||||
|
? existsSync(join(attachDir, sessionDirectory))
|
||||||
|
? [sessionDirectory]
|
||||||
|
: []
|
||||||
|
: readdirSync(attachDir).filter((name) => name.length === 32 && /^[a-f0-9]+$/i.test(name))
|
||||||
|
|
||||||
|
for (const sessDir of sessionDirs) {
|
||||||
|
const sessionRoot = join(attachDir, sessDir)
|
||||||
|
const months = sessionDirectory
|
||||||
|
? this.getImageMonthDirectories(sessionRoot, createTime)
|
||||||
|
: this.getRecentImageMonths(24)
|
||||||
|
for (const month of months) {
|
||||||
|
const recImgDir = join(sessionRoot, month, 'Rec', recordDir, 'Img')
|
||||||
|
if (!existsSync(recImgDir)) continue
|
||||||
|
const found = this.getLargestExistingPath(
|
||||||
|
candidateNames.map((name) => join(recImgDir, name)),
|
||||||
|
allowThumbnail,
|
||||||
|
preferThumbnail
|
||||||
|
)
|
||||||
|
if (found) return found
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
private async findForwardRecordImageAsync(
|
||||||
|
attachDir: string,
|
||||||
|
recordDir: string,
|
||||||
|
fileIndex: string,
|
||||||
|
allowThumbnail: boolean,
|
||||||
|
preferThumbnail = false,
|
||||||
|
sessionDirectory = '',
|
||||||
|
createTime?: number
|
||||||
|
): Promise<string | null> {
|
||||||
|
if (!sessionDirectory) {
|
||||||
|
return this.findForwardRecordImage(
|
||||||
|
attachDir,
|
||||||
|
recordDir,
|
||||||
|
fileIndex,
|
||||||
|
allowThumbnail,
|
||||||
|
preferThumbnail,
|
||||||
|
'',
|
||||||
|
createTime
|
||||||
|
)
|
||||||
|
}
|
||||||
|
const sessionRoot = join(attachDir, sessionDirectory)
|
||||||
|
let months: string[]
|
||||||
|
try {
|
||||||
|
months = (await fsPromises.readdir(sessionRoot, { withFileTypes: true }))
|
||||||
|
.filter((entry) => entry.isDirectory() && /^\d{4}-\d{2}$/.test(entry.name))
|
||||||
|
.map((entry) => entry.name)
|
||||||
|
.sort((left, right) => right.localeCompare(left))
|
||||||
|
} catch {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
months = this.prioritizeImageMonth(months, createTime)
|
||||||
|
const candidateNames = this.buildForwardRecordImageNames(fileIndex)
|
||||||
|
for (const month of months) {
|
||||||
|
const recImgDir = join(sessionRoot, month, 'Rec', recordDir, 'Img')
|
||||||
|
const found = await this.getLargestExistingPathAsync(
|
||||||
|
candidateNames.map((name) => join(recImgDir, name)),
|
||||||
|
allowThumbnail,
|
||||||
|
preferThumbnail
|
||||||
|
)
|
||||||
|
if (found) return found
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
private getPreferredDatVariantPath(
|
private getPreferredDatVariantPath(
|
||||||
inputPath: string,
|
inputPath: string,
|
||||||
allowThumbnail: boolean,
|
allowThumbnail: boolean,
|
||||||
@@ -1805,7 +1955,10 @@ export class ImageDecryptService {
|
|||||||
): string {
|
): string {
|
||||||
const actualDir = dirname(inputPath)
|
const actualDir = dirname(inputPath)
|
||||||
const base = this.normalizeDatBase(basename(inputPath))
|
const base = this.normalizeDatBase(basename(inputPath))
|
||||||
const variants = this.buildPreferredDatNames(base)
|
const hasDatExtension = basename(inputPath).toLowerCase().endsWith('.dat')
|
||||||
|
const variants = hasDatExtension
|
||||||
|
? this.buildPreferredDatNames(base)
|
||||||
|
: [...this.buildForwardRecordImageNames(base), ...this.buildPreferredDatNames(base)]
|
||||||
const ordered = allowThumbnail
|
const ordered = allowThumbnail
|
||||||
? variants
|
? variants
|
||||||
: variants.filter((name) => !this.isThumbnailName(name))
|
: variants.filter((name) => !this.isThumbnailName(name))
|
||||||
|
|||||||
+201
-36
@@ -26,14 +26,28 @@ type ShareContent = {
|
|||||||
type ForwardedMessageItem = {
|
type ForwardedMessageItem = {
|
||||||
messageType: number
|
messageType: number
|
||||||
sender?: string
|
sender?: string
|
||||||
|
sourceHeadUrl?: string
|
||||||
sentAt?: string
|
sentAt?: string
|
||||||
text: string
|
text: string
|
||||||
|
title?: string
|
||||||
|
dataId?: string
|
||||||
|
dataIndex?: number
|
||||||
|
imageMd5?: string
|
||||||
|
thumbMd5?: string
|
||||||
|
imageDatName?: string
|
||||||
|
exportMediaUrl?: string
|
||||||
|
dataSize?: number
|
||||||
|
thumbSize?: number
|
||||||
|
fileExt?: string
|
||||||
|
linkUrl?: string
|
||||||
|
nestedTitle?: string
|
||||||
nested?: ForwardedMessageItem[]
|
nested?: ForwardedMessageItem[]
|
||||||
}
|
}
|
||||||
type ForwardBundleContent = {
|
type ForwardBundleContent = {
|
||||||
type: 'forwardBundle'
|
type: 'forwardBundle'
|
||||||
title: string
|
title: string
|
||||||
description?: string
|
description?: string
|
||||||
|
recordDir?: string
|
||||||
items: ForwardedMessageItem[]
|
items: ForwardedMessageItem[]
|
||||||
}
|
}
|
||||||
type MiniProgramContent = {
|
type MiniProgramContent = {
|
||||||
@@ -601,58 +615,206 @@ function parseForwardBundle(content: string): ForwardBundleContent {
|
|||||||
const normalized = decodeXmlEntities(stripChatroomPrefix(content))
|
const normalized = decodeXmlEntities(stripChatroomPrefix(content))
|
||||||
const title = decodeXmlEntities(extractXmlValue(normalized, 'title')) || '聊天记录'
|
const title = decodeXmlEntities(extractXmlValue(normalized, 'title')) || '聊天记录'
|
||||||
const description = decodeXmlEntities(extractXmlValue(normalized, 'des')) || undefined
|
const description = decodeXmlEntities(extractXmlValue(normalized, 'des')) || undefined
|
||||||
const containers = Array.from(
|
const containers = splitBalancedXmlTags(normalized, 'recorditem').map((node) => node.inner)
|
||||||
normalized.matchAll(/<recorditem\b[^>]*>([\s\S]*?)<\/recorditem>/gi),
|
|
||||||
(match) => match[1] || ''
|
|
||||||
)
|
|
||||||
const sources = containers.length ? containers : [normalized]
|
const sources = containers.length ? containers : [normalized]
|
||||||
const items = dedupeForwardedItems(sources.flatMap((source) => parseForwardedItems(source)))
|
const items = dedupeForwardedItems(sources.flatMap((source) => parseForwardedItems(source)))
|
||||||
return { type: 'forwardBundle', title, description, items }
|
return { type: 'forwardBundle', title, description, items }
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseForwardedItems(container: string, depth = 0): ForwardedMessageItem[] {
|
/**
|
||||||
if (!container || depth > 4) return []
|
* 按标签嵌套深度提取顶层 XML 元素,避免合并转发套娃(<dataitem> 内嵌套 <recordxml><dataitem>)
|
||||||
const variants = new Set<string>([container, decodeXmlEntities(container)])
|
* 时被非贪婪正则在第一个内层 </dataitem> 处截断。
|
||||||
for (const match of container.matchAll(/<!\[CDATA\[([\s\S]*?)\]\]>/g)) {
|
*/
|
||||||
if (match[1]) variants.add(decodeXmlEntities(match[1]))
|
function splitBalancedXmlTags(
|
||||||
|
source: string,
|
||||||
|
tagName: string
|
||||||
|
): Array<{ attrs: string; inner: string }> {
|
||||||
|
const xml = source || ''
|
||||||
|
if (!xml) return []
|
||||||
|
const pattern = new RegExp(`<(/?)${tagName}\\b([^>]*)>`, 'gi')
|
||||||
|
const result: Array<{ attrs: string; inner: string }> = []
|
||||||
|
let match: RegExpExecArray | null
|
||||||
|
let depth = 0
|
||||||
|
let openStart = -1
|
||||||
|
let openEnd = -1
|
||||||
|
let openAttrs = ''
|
||||||
|
|
||||||
|
while ((match = pattern.exec(xml)) !== null) {
|
||||||
|
const isClosing = match[1] === '/'
|
||||||
|
const attrs = match[2] || ''
|
||||||
|
const rawTag = match[0] || ''
|
||||||
|
const selfClosing = !isClosing && /\/\s*>$/.test(rawTag)
|
||||||
|
|
||||||
|
if (!isClosing) {
|
||||||
|
if (depth === 0) {
|
||||||
|
openStart = match.index
|
||||||
|
openEnd = pattern.lastIndex
|
||||||
|
openAttrs = attrs
|
||||||
|
}
|
||||||
|
if (!selfClosing) {
|
||||||
|
depth += 1
|
||||||
|
} else if (depth === 0 && openEnd >= 0) {
|
||||||
|
result.push({ attrs: openAttrs, inner: '' })
|
||||||
|
openStart = -1
|
||||||
|
openEnd = -1
|
||||||
|
openAttrs = ''
|
||||||
|
}
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
const items: ForwardedMessageItem[] = []
|
if (depth <= 0) continue
|
||||||
|
depth -= 1
|
||||||
|
if (depth === 0 && openEnd >= 0 && openStart >= 0) {
|
||||||
|
result.push({
|
||||||
|
attrs: openAttrs,
|
||||||
|
inner: xml.slice(openEnd, match.index)
|
||||||
|
})
|
||||||
|
openStart = -1
|
||||||
|
openEnd = -1
|
||||||
|
openAttrs = ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseForwardedItems(container: string, depth = 0): ForwardedMessageItem[] {
|
||||||
|
if (!container || depth > 8) return []
|
||||||
|
const variants: string[] = []
|
||||||
|
const pushVariant = (value: string): void => {
|
||||||
|
const trimmed = String(value || '').trim()
|
||||||
|
if (trimmed && !variants.includes(trimmed)) variants.push(trimmed)
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const match of container.matchAll(/<!\[CDATA\[([\s\S]*?)\]\]>/g)) {
|
||||||
|
if (match[1]) {
|
||||||
|
pushVariant(match[1])
|
||||||
|
pushVariant(decodeXmlEntities(match[1]))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pushVariant(container)
|
||||||
|
pushVariant(decodeXmlEntities(container))
|
||||||
|
|
||||||
for (const variant of variants) {
|
for (const variant of variants) {
|
||||||
for (const match of variant.matchAll(/<dataitem\b([^>]*)>([\s\S]*?)<\/dataitem>/gi)) {
|
const dataItemNodes = splitBalancedXmlTags(variant, 'dataitem')
|
||||||
const attributes = match[1] || ''
|
if (dataItemNodes.length === 0) continue
|
||||||
const body = match[2] || ''
|
|
||||||
|
const items: ForwardedMessageItem[] = []
|
||||||
|
dataItemNodes.forEach((node, index) => {
|
||||||
|
const attributes = node.attrs || ''
|
||||||
|
const body = node.inner || ''
|
||||||
|
const nestedXml = splitBalancedXmlTags(body, 'recordxml')[0]?.inner || ''
|
||||||
|
// 剥离嵌套 <recordxml> 后再提取外层字段,防止内层 <dataitem> 的 fullmd5/datadesc/sourcename 泄漏到外层 datatype=17 节点。
|
||||||
|
const ownBody = nestedXml
|
||||||
|
? body.replace(/<recordxml\b[^>]*>[\s\S]*<\/recordxml>/i, '')
|
||||||
|
: body
|
||||||
const attrType = /datatype\s*=\s*["']?(\d+)/i.exec(attributes)?.[1]
|
const attrType = /datatype\s*=\s*["']?(\d+)/i.exec(attributes)?.[1]
|
||||||
const messageType = Number.parseInt(attrType || extractXmlValue(body, 'datatype') || '0', 10)
|
const dataId = /dataid\s*=\s*["']([^"']+)["']/i.exec(attributes)?.[1] || undefined
|
||||||
const sender = decodeXmlEntities(extractXmlValue(body, 'sourcename')) || undefined
|
const messageType = Number.parseInt(
|
||||||
const sentAt = extractXmlValue(body, 'sourcetime') || undefined
|
attrType || extractXmlValue(ownBody, 'datatype') || '0',
|
||||||
const title = decodeXmlEntities(extractXmlValue(body, 'datatitle'))
|
10
|
||||||
|
)
|
||||||
|
const normalizedType = Number.isFinite(messageType) ? messageType : 0
|
||||||
|
const sender = decodeXmlEntities(extractXmlValue(ownBody, 'sourcename')) || undefined
|
||||||
|
const sourceHeadUrl = decodeXmlUrl(extractXmlValue(ownBody, 'sourceheadurl')) || undefined
|
||||||
|
const sentAt = extractXmlValue(ownBody, 'sourcetime') || undefined
|
||||||
|
const title = decodeXmlEntities(extractXmlValue(ownBody, 'datatitle')) || undefined
|
||||||
const description = decodeXmlEntities(
|
const description = decodeXmlEntities(
|
||||||
extractXmlValue(body, 'datadesc') || extractXmlValue(body, 'content')
|
extractXmlValue(ownBody, 'datadesc') || extractXmlValue(ownBody, 'content')
|
||||||
|
)
|
||||||
|
const isNestedRecord = normalizedType === 17
|
||||||
|
const imageMd5 =
|
||||||
|
!isNestedRecord && normalizedType === 2
|
||||||
|
? normalizeMd5(
|
||||||
|
extractXmlValue(ownBody, 'fullmd5') ||
|
||||||
|
extractXmlValue(ownBody, 'md5') ||
|
||||||
|
extractXmlValue(ownBody, 'datamd5')
|
||||||
)
|
)
|
||||||
const nestedXml = extractXmlBody(body, 'recordxml')
|
|
||||||
const nested =
|
|
||||||
messageType === 17 && nestedXml
|
|
||||||
? parseForwardedItems(decodeXmlEntities(nestedXml), depth + 1)
|
|
||||||
: undefined
|
: undefined
|
||||||
const text = description || title || forwardedTypeLabel(messageType)
|
const thumbMd5 =
|
||||||
if (!sender && !text && !nested?.length) continue
|
!isNestedRecord && normalizedType === 2
|
||||||
|
? normalizeMd5(extractXmlValue(ownBody, 'thumbfullmd5'))
|
||||||
|
: undefined
|
||||||
|
const dataSize =
|
||||||
|
Number.parseInt(extractXmlValue(ownBody, 'datasize') || '0', 10) || undefined
|
||||||
|
const thumbSize =
|
||||||
|
Number.parseInt(extractXmlValue(ownBody, 'thumbsize') || '0', 10) || undefined
|
||||||
|
const fileExt = extractXmlValue(ownBody, 'fileext') || undefined
|
||||||
|
const linkUrl =
|
||||||
|
decodeXmlUrl(extractXmlValue(ownBody, 'link') || extractXmlValue(ownBody, 'streamweburl')) ||
|
||||||
|
undefined
|
||||||
|
const nestedTitle = isNestedRecord
|
||||||
|
? decodeXmlEntities((nestedXml && extractXmlValue(nestedXml, 'title')) || title || '') ||
|
||||||
|
'聊天记录'
|
||||||
|
: undefined
|
||||||
|
const nested =
|
||||||
|
isNestedRecord && nestedXml ? parseForwardedItems(nestedXml, depth + 1) : undefined
|
||||||
|
const text =
|
||||||
|
normalizedType === 2
|
||||||
|
? '[图片]'
|
||||||
|
: isNestedRecord
|
||||||
|
? nestedTitle || '[聊天记录]'
|
||||||
|
: description || title || forwardedTypeLabel(normalizedType)
|
||||||
|
if (!sender && !text && !nested?.length && !imageMd5 && !thumbMd5) return
|
||||||
items.push({
|
items.push({
|
||||||
messageType: Number.isFinite(messageType) ? messageType : 0,
|
messageType: normalizedType,
|
||||||
sender,
|
sender,
|
||||||
|
sourceHeadUrl,
|
||||||
sentAt,
|
sentAt,
|
||||||
text: text || '[消息]',
|
text: text || '[消息]',
|
||||||
|
title,
|
||||||
|
dataId,
|
||||||
|
dataIndex: index,
|
||||||
|
imageMd5,
|
||||||
|
thumbMd5,
|
||||||
|
dataSize,
|
||||||
|
thumbSize,
|
||||||
|
fileExt,
|
||||||
|
linkUrl,
|
||||||
|
nestedTitle,
|
||||||
nested: nested?.length ? nested : undefined
|
nested: nested?.length ? nested : undefined
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
if (items.length > 0) return dedupeForwardedItems(items)
|
||||||
|
}
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
export function attachForwardBundleRecordDir(
|
||||||
|
bundle: ForwardBundleContent,
|
||||||
|
recordDir?: string
|
||||||
|
): ForwardBundleContent {
|
||||||
|
const normalizedDir = String(recordDir || '').trim()
|
||||||
|
if (!normalizedDir) return bundle
|
||||||
|
const items = bundle.items.map((item, idx) => {
|
||||||
|
const dataIndex = typeof item.dataIndex === 'number' ? item.dataIndex : idx
|
||||||
|
if (item.messageType === 2 && !item.imageDatName) {
|
||||||
|
return {
|
||||||
|
...item,
|
||||||
|
dataIndex,
|
||||||
|
imageDatName: `rec:${normalizedDir}:${dataIndex}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return dedupeForwardedItems(items)
|
return item
|
||||||
|
})
|
||||||
|
return {
|
||||||
|
...bundle,
|
||||||
|
recordDir: normalizedDir,
|
||||||
|
items
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function dedupeForwardedItems(items: ForwardedMessageItem[]): ForwardedMessageItem[] {
|
function dedupeForwardedItems(items: ForwardedMessageItem[]): ForwardedMessageItem[] {
|
||||||
const seen = new Set<string>()
|
const seen = new Set<string>()
|
||||||
return items.filter((item) => {
|
return items.filter((item) => {
|
||||||
const key = `${item.messageType}|${item.sender || ''}|${item.sentAt || ''}|${item.text}`
|
const key = [
|
||||||
|
item.messageType,
|
||||||
|
item.dataId || '',
|
||||||
|
item.dataIndex ?? '',
|
||||||
|
item.sender || '',
|
||||||
|
item.sentAt || '',
|
||||||
|
item.imageMd5 || '',
|
||||||
|
item.text
|
||||||
|
].join('|')
|
||||||
if (seen.has(key)) return false
|
if (seen.has(key)) return false
|
||||||
seen.add(key)
|
seen.add(key)
|
||||||
return true
|
return true
|
||||||
@@ -661,30 +823,33 @@ function dedupeForwardedItems(items: ForwardedMessageItem[]): ForwardedMessageIt
|
|||||||
|
|
||||||
function forwardedTypeLabel(messageType: number): string {
|
function forwardedTypeLabel(messageType: number): string {
|
||||||
switch (messageType) {
|
switch (messageType) {
|
||||||
case 3:
|
case 2:
|
||||||
return '[图片]'
|
return '[图片]'
|
||||||
|
case 3:
|
||||||
case 34:
|
case 34:
|
||||||
return '[语音]'
|
return '[语音]'
|
||||||
|
case 4:
|
||||||
case 43:
|
case 43:
|
||||||
return '[视频]'
|
return '[视频]'
|
||||||
case 47:
|
case 5:
|
||||||
return '[表情包]'
|
return '[链接]'
|
||||||
|
case 6:
|
||||||
|
return '[位置]'
|
||||||
case 8:
|
case 8:
|
||||||
case 49:
|
case 49:
|
||||||
return '[文件或分享]'
|
return '[文件或分享]'
|
||||||
case 17:
|
case 17:
|
||||||
return '[聊天记录]'
|
return '[聊天记录]'
|
||||||
|
case 22:
|
||||||
|
return '[视频号]'
|
||||||
|
case 37:
|
||||||
|
case 47:
|
||||||
|
return '[表情包]'
|
||||||
default:
|
default:
|
||||||
return '[消息]'
|
return '[消息]'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function extractXmlBody(xml: string, tagName: string): string {
|
|
||||||
const match = new RegExp(`<${tagName}[^>]*>([\\s\\S]*?)<\\/${tagName}>`, 'i').exec(xml)
|
|
||||||
if (!match?.[1]) return ''
|
|
||||||
return match[1].replace(/^<!\[CDATA\[([\s\S]*?)\]\]>$/, '$1').trim()
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseQuoteMessage(content: string): {
|
function parseQuoteMessage(content: string): {
|
||||||
content?: string
|
content?: string
|
||||||
sender?: string
|
sender?: string
|
||||||
|
|||||||
@@ -761,7 +761,7 @@ export class AutomationActionRunner {
|
|||||||
* 定时日报的统一发送出口。
|
* 定时日报的统一发送出口。
|
||||||
*
|
*
|
||||||
* **必须走 `WechatActionGateway`**:幂等 + 3 秒发送间隔 + 审计落盘都在那里。
|
* **必须走 `WechatActionGateway`**:幂等 + 3 秒发送间隔 + 审计落盘都在那里。
|
||||||
* Automation 层不允许知道 OneBot / WCHook / native host / Windows hook 的存在。
|
* Automation 层不允许知道 native host 的存在。
|
||||||
*/
|
*/
|
||||||
private async sendScheduledReportImage(
|
private async sendScheduledReportImage(
|
||||||
input: ScheduledReportRunInput,
|
input: ScheduledReportRunInput,
|
||||||
@@ -879,7 +879,7 @@ export class AutomationActionRunner {
|
|||||||
*
|
*
|
||||||
* **必须走 `WechatActionGateway`**:幂等 + 3 秒发送间隔 + 审计落盘都在那里,
|
* **必须走 `WechatActionGateway`**:幂等 + 3 秒发送间隔 + 审计落盘都在那里,
|
||||||
* 直接调个人微信发送会绕过全部三样。Automation 层也不允许知道
|
* 直接调个人微信发送会绕过全部三样。Automation 层也不允许知道
|
||||||
* OneBot / WCHook / native host / Windows hook 的存在。
|
* native host 的存在。
|
||||||
*
|
*
|
||||||
* 幂等键由 **eventId** 派生(不是 executionId):审计是落盘的,
|
* 幂等键由 **eventId** 派生(不是 executionId):审计是落盘的,
|
||||||
* 于是"重启后重复投递同一退群事件"会被持久层直接短路。
|
* 于是"重启后重复投递同一退群事件"会被持久层直接短路。
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { createHash, randomUUID } from 'node:crypto'
|
import { createHash, randomUUID } from 'node:crypto'
|
||||||
import { WechatDb, WechatMessage } from '../wechat-db'
|
import { WechatDb, WechatMessage } from '../wechat-db'
|
||||||
import {
|
import {
|
||||||
|
attachForwardBundleRecordDir,
|
||||||
parseImageBufferDataUrlFromRow,
|
parseImageBufferDataUrlFromRow,
|
||||||
parseImageDatNameFromRow,
|
parseImageDatNameFromRow,
|
||||||
parseMessageContent,
|
parseMessageContent,
|
||||||
@@ -613,6 +614,9 @@ function listSourceMessages(
|
|||||||
thumbDatName: parsed.thumbDatName || parseImageDatNameFromRow(msg),
|
thumbDatName: parsed.thumbDatName || parseImageDatNameFromRow(msg),
|
||||||
thumbDataUrl: parsed.thumbDataUrl || parseImageBufferDataUrlFromRow(msg.raw || msg)
|
thumbDataUrl: parsed.thumbDataUrl || parseImageBufferDataUrlFromRow(msg.raw || msg)
|
||||||
}
|
}
|
||||||
|
} else if (parsed.type === 'forwardBundle') {
|
||||||
|
const recordDir = parseImageDatNameFromRow(msg.raw || msg)
|
||||||
|
contentData = attachForwardBundleRecordDir(parsed, recordDir)
|
||||||
} else if (parsed.type !== 'system') {
|
} else if (parsed.type !== 'system') {
|
||||||
if (parsed.type === 'sticker' && !parsed.url && parsed.md5) {
|
if (parsed.type === 'sticker' && !parsed.url && parsed.md5) {
|
||||||
parsed.url = wcdb4Client.resolveEmoticonCdnUrl(parsed.md5)
|
parsed.url = wcdb4Client.resolveEmoticonCdnUrl(parsed.md5)
|
||||||
|
|||||||
@@ -77,12 +77,15 @@ export class VideoAssetService {
|
|||||||
|
|
||||||
const index = this.getIndex()
|
const index = this.getIndex()
|
||||||
for (const key of lookupKeys) {
|
for (const key of lookupKeys) {
|
||||||
const asset = index.get(key) || index.get(`${key}_raw`)
|
const rawAsset = index.get(`${key}_raw`)
|
||||||
|
const compressedAsset = index.get(key)
|
||||||
|
const asset = rawAsset || compressedAsset
|
||||||
if (!asset) continue
|
if (!asset) continue
|
||||||
|
const posterPath = asset.posterPath || compressedAsset?.posterPath
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
url: this.createLocalMediaUrl(asset.filePath),
|
url: this.createLocalMediaUrl(asset.filePath),
|
||||||
poster: asset.posterPath ? this.createLocalMediaUrl(asset.posterPath) : undefined
|
poster: posterPath ? this.createLocalMediaUrl(posterPath) : undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+194
-2
@@ -3334,12 +3334,15 @@ export class Wcdb4Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resolveImageHardlink(md5: string): Wcdb4ImageHardlink | null {
|
resolveImageHardlink(md5: string): Wcdb4ImageHardlink | null {
|
||||||
if (!this.wcdbResolveImageHardlink) return null
|
|
||||||
const normalizedMd5 = String(md5 || '')
|
const normalizedMd5 = String(md5 || '')
|
||||||
.trim()
|
.trim()
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
if (!normalizedMd5) return null
|
if (!normalizedMd5) return null
|
||||||
|
|
||||||
|
const sqlHit = this.resolveImageHardlinkViaSql(normalizedMd5)
|
||||||
|
if (sqlHit) return sqlHit
|
||||||
|
|
||||||
|
if (!this.wcdbResolveImageHardlink) return null
|
||||||
try {
|
try {
|
||||||
return this.callJson<Wcdb4ImageHardlink>((handle, outJson) =>
|
return this.callJson<Wcdb4ImageHardlink>((handle, outJson) =>
|
||||||
this.wcdbResolveImageHardlink!(handle, normalizedMd5, this.nativeAccountRoot, outJson)
|
this.wcdbResolveImageHardlink!(handle, normalizedMd5, this.nativeAccountRoot, outJson)
|
||||||
@@ -3351,12 +3354,15 @@ export class Wcdb4Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async resolveImageHardlinkAsync(md5: string): Promise<Wcdb4ImageHardlink | null> {
|
async resolveImageHardlinkAsync(md5: string): Promise<Wcdb4ImageHardlink | null> {
|
||||||
if (!this.wcdbResolveImageHardlink) return null
|
|
||||||
const normalizedMd5 = String(md5 || '')
|
const normalizedMd5 = String(md5 || '')
|
||||||
.trim()
|
.trim()
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
if (!normalizedMd5) return null
|
if (!normalizedMd5) return null
|
||||||
|
|
||||||
|
const sqlHit = await this.resolveImageHardlinkViaSqlAsync(normalizedMd5)
|
||||||
|
if (sqlHit) return sqlHit
|
||||||
|
|
||||||
|
if (!this.wcdbResolveImageHardlink) return null
|
||||||
try {
|
try {
|
||||||
return await this.callJsonAsync<Wcdb4ImageHardlink>(
|
return await this.callJsonAsync<Wcdb4ImageHardlink>(
|
||||||
this.wcdbResolveImageHardlink as unknown as KoffiAsyncFunction,
|
this.wcdbResolveImageHardlink as unknown as KoffiAsyncFunction,
|
||||||
@@ -3369,6 +3375,192 @@ export class Wcdb4Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private findHardlinkDb(): string {
|
||||||
|
const candidates = [
|
||||||
|
path.join(this.dbStoragePath, 'hardlink', 'hardlink.db'),
|
||||||
|
path.join(this.dbStoragePath, 'hardlink.db')
|
||||||
|
]
|
||||||
|
return candidates.find((candidate) => fs.existsSync(candidate)) || ''
|
||||||
|
}
|
||||||
|
|
||||||
|
private buildImageHardlinkSql(normalizedMd5: string): string {
|
||||||
|
const escaped = normalizedMd5.replace(/'/g, "''")
|
||||||
|
return (
|
||||||
|
`SELECT f.md5, f.type AS link_kind, f.file_name, f.file_size, f.modify_time, ` +
|
||||||
|
`hex(f.extra_buffer) AS extra_hex, IFNULL(d1.username, '') AS dir1, IFNULL(d2.username, '') AS dir2 ` +
|
||||||
|
`FROM image_hardlink_info_v4 f ` +
|
||||||
|
`LEFT JOIN dir2id d1 ON d1.rowid = f.dir1 ` +
|
||||||
|
`LEFT JOIN dir2id d2 ON d2.rowid = f.dir2 ` +
|
||||||
|
`WHERE f.md5 = '${escaped}' OR f.file_name LIKE '${escaped}%'`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析 image_hardlink_info_v4.extra_buffer 中的 Protobuf 字段,提取合并转发 Rec 子目录名(如 16 位 hex 目录名)。
|
||||||
|
*/
|
||||||
|
private decodeRecSubdirTokens(extraHex: string): string[] {
|
||||||
|
const trimmed = String(extraHex || '').trim()
|
||||||
|
if (!trimmed || trimmed.length % 2 !== 0 || !/^[0-9a-fA-F]+$/.test(trimmed)) return []
|
||||||
|
const buf = Buffer.from(trimmed, 'hex')
|
||||||
|
const tokens: string[] = []
|
||||||
|
const collectTokens = (text: string): void => {
|
||||||
|
const matches = text.match(/[a-zA-Z0-9_-]+/g)
|
||||||
|
if (!matches) return
|
||||||
|
for (const token of matches) {
|
||||||
|
if (token.trim()) tokens.push(token.trim())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const isAsciiText = (slice: Buffer): boolean => {
|
||||||
|
if (slice.length === 0) return false
|
||||||
|
for (let i = 0; i < slice.length; i += 1) {
|
||||||
|
if (slice[i] < 0x20 || slice[i] >= 0x7f) return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isAsciiText(buf)) {
|
||||||
|
collectTokens(buf.toString('ascii'))
|
||||||
|
return tokens
|
||||||
|
}
|
||||||
|
|
||||||
|
let offset = 0
|
||||||
|
while (offset < buf.length) {
|
||||||
|
const tag = buf[offset]
|
||||||
|
offset += 1
|
||||||
|
const wireType = tag & 0x07
|
||||||
|
if (wireType === 0) {
|
||||||
|
while (offset < buf.length && (buf[offset] & 0x80) !== 0) offset += 1
|
||||||
|
offset += 1
|
||||||
|
} else if (wireType === 1) {
|
||||||
|
offset += 8
|
||||||
|
} else if (wireType === 2) {
|
||||||
|
let length = 0
|
||||||
|
let shift = 0
|
||||||
|
while (offset < buf.length) {
|
||||||
|
const byte = buf[offset]
|
||||||
|
offset += 1
|
||||||
|
length |= (byte & 0x7f) << shift
|
||||||
|
if ((byte & 0x80) === 0) break
|
||||||
|
shift += 7
|
||||||
|
}
|
||||||
|
if (length < 0 || offset + length > buf.length) break
|
||||||
|
const value = buf.subarray(offset, offset + length)
|
||||||
|
offset += length
|
||||||
|
if (isAsciiText(value)) {
|
||||||
|
collectTokens(value.toString('ascii'))
|
||||||
|
}
|
||||||
|
} else if (wireType === 5) {
|
||||||
|
offset += 4
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tokens
|
||||||
|
}
|
||||||
|
|
||||||
|
private pickImageHardlinkFromRows(
|
||||||
|
normalizedMd5: string,
|
||||||
|
rows: Record<string, unknown>[]
|
||||||
|
): Wcdb4ImageHardlink | null {
|
||||||
|
if (!Array.isArray(rows) || rows.length === 0) return null
|
||||||
|
|
||||||
|
const candidates: Array<{
|
||||||
|
fullPath: string
|
||||||
|
fileName: string
|
||||||
|
dir1: string
|
||||||
|
dir2: string
|
||||||
|
linkKind: number
|
||||||
|
fileSize: number
|
||||||
|
modifyTime: number
|
||||||
|
exists: boolean
|
||||||
|
}> = []
|
||||||
|
|
||||||
|
for (const row of rows) {
|
||||||
|
const fileName = String(row.file_name || '').trim()
|
||||||
|
const dir1 = String(row.dir1 || '').trim()
|
||||||
|
const dir2 = String(row.dir2 || '').trim()
|
||||||
|
if (!fileName || !dir1 || !dir2) continue
|
||||||
|
const linkKind = Number(row.link_kind || row.type || 0)
|
||||||
|
const fileSize = Number(row.file_size || 0)
|
||||||
|
const modifyTime = Number(row.modify_time || 0)
|
||||||
|
const subdirTokens = this.decodeRecSubdirTokens(String(row.extra_hex || ''))
|
||||||
|
|
||||||
|
const fullPath =
|
||||||
|
linkKind === 4 && subdirTokens.length > 0
|
||||||
|
? path.join(this.accountRoot, 'msg', 'attach', dir1, dir2, 'Rec', subdirTokens[0], 'Img', fileName)
|
||||||
|
: path.join(this.accountRoot, 'msg', 'attach', dir1, dir2, 'Img', fileName)
|
||||||
|
|
||||||
|
candidates.push({
|
||||||
|
fullPath,
|
||||||
|
fileName,
|
||||||
|
dir1,
|
||||||
|
dir2,
|
||||||
|
linkKind,
|
||||||
|
fileSize,
|
||||||
|
modifyTime,
|
||||||
|
exists: fs.existsSync(fullPath)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (candidates.length === 0) return null
|
||||||
|
candidates.sort((left, right) => {
|
||||||
|
if (left.exists !== right.exists) return left.exists ? -1 : 1
|
||||||
|
if (left.fileSize !== right.fileSize) return right.fileSize - left.fileSize
|
||||||
|
return right.modifyTime - left.modifyTime
|
||||||
|
})
|
||||||
|
|
||||||
|
const best = candidates[0]
|
||||||
|
if (!best.exists) return null
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
md5: normalizedMd5,
|
||||||
|
dir1: best.dir1,
|
||||||
|
dir2: best.dir2,
|
||||||
|
link_kind: best.linkKind,
|
||||||
|
file_name: best.fileName,
|
||||||
|
full_path: best.fullPath
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private resolveImageHardlinkViaSql(normalizedMd5: string): Wcdb4ImageHardlink | null {
|
||||||
|
if (!this.wcdbExecQuery || this.handle === null) return null
|
||||||
|
const hardlinkDb = this.findHardlinkDb()
|
||||||
|
if (!hardlinkDb) return null
|
||||||
|
try {
|
||||||
|
const rows = this.callJson<Record<string, unknown>[]>((handle, outJson) =>
|
||||||
|
this.wcdbExecQuery!(
|
||||||
|
handle,
|
||||||
|
'media',
|
||||||
|
hardlinkDb,
|
||||||
|
this.buildImageHardlinkSql(normalizedMd5),
|
||||||
|
outJson
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return this.pickImageHardlinkFromRows(normalizedMd5, rows)
|
||||||
|
} catch {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async resolveImageHardlinkViaSqlAsync(
|
||||||
|
normalizedMd5: string
|
||||||
|
): Promise<Wcdb4ImageHardlink | null> {
|
||||||
|
if (!this.wcdbExecQuery || this.handle === null) return null
|
||||||
|
const hardlinkDb = this.findHardlinkDb()
|
||||||
|
if (!hardlinkDb) return null
|
||||||
|
try {
|
||||||
|
const rows = await this.callJsonAsync<Record<string, unknown>[]>(
|
||||||
|
this.wcdbExecQuery as unknown as KoffiAsyncFunction,
|
||||||
|
'media',
|
||||||
|
hardlinkDb,
|
||||||
|
this.buildImageHardlinkSql(normalizedMd5)
|
||||||
|
)
|
||||||
|
return this.pickImageHardlinkFromRows(normalizedMd5, rows)
|
||||||
|
} catch {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
resolveVideoHardlink(md5: string, dbPath: string): Wcdb4VideoHardlink | null {
|
resolveVideoHardlink(md5: string, dbPath: string): Wcdb4VideoHardlink | null {
|
||||||
if (!this.wcdbResolveVideoHardlink) return null
|
if (!this.wcdbResolveVideoHardlink) return null
|
||||||
const normalizedMd5 = String(md5 || '')
|
const normalizedMd5 = String(md5 || '')
|
||||||
|
|||||||
@@ -0,0 +1,241 @@
|
|||||||
|
import { useEffect, useState } from 'react'
|
||||||
|
import { createPortal } from 'react-dom'
|
||||||
|
import type { JSX, MouseEvent } from 'react'
|
||||||
|
import type { ForwardedMessageItem } from '../../../shared/types'
|
||||||
|
import { renderWechatEmojiText } from '../utils/wechatEmojiText'
|
||||||
|
import { ImageBubble } from './ImageBubble'
|
||||||
|
|
||||||
|
export interface ForwardBundleWindowLayer {
|
||||||
|
id: string
|
||||||
|
title: string
|
||||||
|
items: ForwardedMessageItem[]
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ForwardBundleModalStackProps {
|
||||||
|
layers: ForwardBundleWindowLayer[]
|
||||||
|
sessionId?: string
|
||||||
|
onOpenNested: (title: string, items: ForwardedMessageItem[]) => void
|
||||||
|
onCloseFromIndex: (index: number) => void
|
||||||
|
onImageClick?: (imageUrl: string) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatSentAt(value?: string): string {
|
||||||
|
const raw = String(value || '').trim()
|
||||||
|
if (!raw) return ''
|
||||||
|
if (/^\d{9,13}$/.test(raw)) {
|
||||||
|
const ms = raw.length > 10 ? Number(raw) : Number(raw) * 1000
|
||||||
|
const date = new Date(ms)
|
||||||
|
if (!Number.isNaN(date.getTime())) {
|
||||||
|
const yyyy = date.getFullYear()
|
||||||
|
const mm = String(date.getMonth() + 1).padStart(2, '0')
|
||||||
|
const dd = String(date.getDate()).padStart(2, '0')
|
||||||
|
const hh = String(date.getHours()).padStart(2, '0')
|
||||||
|
const min = String(date.getMinutes()).padStart(2, '0')
|
||||||
|
return `${yyyy}-${mm}-${dd} ${hh}:${min}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return raw
|
||||||
|
}
|
||||||
|
|
||||||
|
function ForwardAvatar({ src, name }: { src?: string; name?: string }): JSX.Element {
|
||||||
|
const [failed, setFailed] = useState(false)
|
||||||
|
const initial = Array.from(String(name || '?').trim())[0] || '?'
|
||||||
|
|
||||||
|
if (src && !failed) {
|
||||||
|
return (
|
||||||
|
<div className="forward-modal-avatar">
|
||||||
|
<img
|
||||||
|
src={src}
|
||||||
|
alt=""
|
||||||
|
loading="lazy"
|
||||||
|
referrerPolicy="no-referrer"
|
||||||
|
onError={() => setFailed(true)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return <div className="forward-modal-avatar forward-modal-avatar-fallback">{initial}</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
function ForwardModalItemRow({
|
||||||
|
item,
|
||||||
|
sessionId,
|
||||||
|
onOpenNested,
|
||||||
|
onImageClick
|
||||||
|
}: {
|
||||||
|
item: ForwardedMessageItem
|
||||||
|
sessionId?: string
|
||||||
|
onOpenNested: (title: string, items: ForwardedMessageItem[]) => void
|
||||||
|
onImageClick?: (imageUrl: string) => void
|
||||||
|
}): JSX.Element {
|
||||||
|
const isNested = item.messageType === 17 || Boolean(item.nested?.length)
|
||||||
|
const isImage =
|
||||||
|
!isNested &&
|
||||||
|
(item.messageType === 2 || Boolean(item.imageMd5 || item.thumbMd5 || item.imageDatName))
|
||||||
|
const senderName = item.sender || '未知发送者'
|
||||||
|
const formattedTime = formatSentAt(item.sentAt)
|
||||||
|
|
||||||
|
const handleOpenNested = (event: MouseEvent<HTMLButtonElement>): void => {
|
||||||
|
event.stopPropagation()
|
||||||
|
if (!item.nested?.length) return
|
||||||
|
onOpenNested(item.nestedTitle || item.title || '聊天记录', item.nested)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<article className="forward-modal-row">
|
||||||
|
<ForwardAvatar src={item.sourceHeadUrl} name={senderName} />
|
||||||
|
<div className="forward-modal-row-main">
|
||||||
|
<header className="forward-modal-row-meta">
|
||||||
|
<span className="forward-modal-sender">{senderName}</span>
|
||||||
|
{formattedTime ? <time className="forward-modal-time">{formattedTime}</time> : null}
|
||||||
|
</header>
|
||||||
|
<div className="forward-modal-row-body">
|
||||||
|
{isImage ? (
|
||||||
|
<div className="forward-modal-image-wrap">
|
||||||
|
<ImageBubble
|
||||||
|
imageMd5={item.imageMd5 || item.thumbMd5}
|
||||||
|
imageDatName={item.imageDatName}
|
||||||
|
sessionId={sessionId}
|
||||||
|
onImageClick={onImageClick}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
) : isNested ? (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className={`forward-modal-nested-card${item.nested?.length ? ' is-clickable' : ''}`}
|
||||||
|
disabled={!item.nested?.length}
|
||||||
|
onClick={handleOpenNested}
|
||||||
|
>
|
||||||
|
<div className="forward-modal-nested-title">
|
||||||
|
{item.nestedTitle || item.title || '聊天记录'}
|
||||||
|
</div>
|
||||||
|
{item.nested?.length ? (
|
||||||
|
<div className="forward-modal-nested-preview">
|
||||||
|
{item.nested.slice(0, 3).map((child, idx) => (
|
||||||
|
<div
|
||||||
|
key={`${child.dataId || ''}-${child.sender || ''}-${idx}`}
|
||||||
|
className="forward-modal-nested-line"
|
||||||
|
>
|
||||||
|
{child.sender ? `${child.sender}: ` : ''}
|
||||||
|
{child.text}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="forward-modal-nested-empty">{item.text || '[聊天记录]'}</div>
|
||||||
|
)}
|
||||||
|
<div className="forward-modal-nested-footer">
|
||||||
|
<span>聊天记录</span>
|
||||||
|
{item.nested?.length ? <span>共 {item.nested.length} 条 · 打开新窗口</span> : null}
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
) : (
|
||||||
|
<div className="forward-modal-text">
|
||||||
|
{renderWechatEmojiText(item.text || item.title || '[消息]', 22)}
|
||||||
|
{item.linkUrl && /^https?:\/\//i.test(item.linkUrl) ? (
|
||||||
|
<a
|
||||||
|
className="forward-modal-link"
|
||||||
|
href={item.linkUrl}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
onClick={(e) => e.stopPropagation()}
|
||||||
|
>
|
||||||
|
打开链接 ↗
|
||||||
|
</a>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ForwardBundleModalStack({
|
||||||
|
layers,
|
||||||
|
sessionId,
|
||||||
|
onOpenNested,
|
||||||
|
onCloseFromIndex,
|
||||||
|
onImageClick
|
||||||
|
}: ForwardBundleModalStackProps): JSX.Element | null {
|
||||||
|
useEffect(() => {
|
||||||
|
if (layers.length === 0) return
|
||||||
|
const handleKeyDown = (event: KeyboardEvent): void => {
|
||||||
|
if (event.key !== 'Escape') return
|
||||||
|
// 若此时已打开更上层的 Radix Dialog(例如 ChatImageViewer),优先交由其处理 Escape。
|
||||||
|
if (document.querySelector('[role="dialog"][data-state="open"]')) return
|
||||||
|
event.preventDefault()
|
||||||
|
event.stopPropagation()
|
||||||
|
onCloseFromIndex(layers.length - 1)
|
||||||
|
}
|
||||||
|
window.addEventListener('keydown', handleKeyDown)
|
||||||
|
return () => window.removeEventListener('keydown', handleKeyDown)
|
||||||
|
}, [layers.length, onCloseFromIndex])
|
||||||
|
|
||||||
|
if (layers.length === 0 || typeof document === 'undefined') return null
|
||||||
|
|
||||||
|
return createPortal(
|
||||||
|
<>
|
||||||
|
{layers.map((layer, index) => {
|
||||||
|
const zIndex = Math.min(58, 45 + index)
|
||||||
|
const offsetX = Math.min(index, 5) * 28
|
||||||
|
const offsetY = Math.min(index, 5) * 24
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={layer.id}
|
||||||
|
className="forward-modal-backdrop"
|
||||||
|
style={{ zIndex }}
|
||||||
|
onClick={() => onCloseFromIndex(index)}
|
||||||
|
>
|
||||||
|
<section
|
||||||
|
className="forward-modal-window"
|
||||||
|
role="dialog"
|
||||||
|
aria-modal="true"
|
||||||
|
aria-label={layer.title || '聊天记录'}
|
||||||
|
style={{
|
||||||
|
transform: `translate(${offsetX}px, ${offsetY}px)`
|
||||||
|
}}
|
||||||
|
onClick={(event) => event.stopPropagation()}
|
||||||
|
>
|
||||||
|
<header className="forward-modal-header">
|
||||||
|
<div className="forward-modal-header-text">
|
||||||
|
<h3 className="forward-modal-title">{layer.title || '聊天记录'}</h3>
|
||||||
|
<span className="forward-modal-subtitle">
|
||||||
|
共 {layer.items.length} 条消息
|
||||||
|
{index > 0 ? ` · 嵌套窗口 #${index + 1}` : ''}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="forward-modal-close"
|
||||||
|
aria-label="关闭聊天记录窗口"
|
||||||
|
onClick={() => onCloseFromIndex(index)}
|
||||||
|
>
|
||||||
|
×
|
||||||
|
</button>
|
||||||
|
</header>
|
||||||
|
<div className="forward-modal-body">
|
||||||
|
{layer.items.length > 0 ? (
|
||||||
|
layer.items.map((item, itemIdx) => (
|
||||||
|
<ForwardModalItemRow
|
||||||
|
key={`${layer.id}-${item.dataId || ''}-${item.dataIndex ?? itemIdx}-${itemIdx}`}
|
||||||
|
item={item}
|
||||||
|
sessionId={sessionId}
|
||||||
|
onOpenNested={onOpenNested}
|
||||||
|
onImageClick={onImageClick}
|
||||||
|
/>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<div className="forward-modal-empty">暂未解析到可展示的记录</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</>,
|
||||||
|
document.body
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
import { ParsedContent } from '../../../shared/types'
|
import { ParsedContent, type ForwardedMessageItem } from '../../../shared/types'
|
||||||
import { useEffect, useState } from 'react'
|
import { useCallback, useEffect, useState } from 'react'
|
||||||
import type { JSX, MouseEvent } from 'react'
|
import type { JSX, MouseEvent } from 'react'
|
||||||
import { renderWechatEmojiText } from '../utils/wechatEmojiText'
|
import { renderWechatEmojiText } from '../utils/wechatEmojiText'
|
||||||
import { ImageBubble } from './ImageBubble'
|
import { ImageBubble } from './ImageBubble'
|
||||||
|
import { ForwardBundleModalStack, type ForwardBundleWindowLayer } from './ForwardBundleModal'
|
||||||
|
|
||||||
const stickerDataUrlCache = new Map<string, string>()
|
const stickerDataUrlCache = new Map<string, string>()
|
||||||
|
|
||||||
@@ -25,7 +26,13 @@ export function RichMessageBubble({
|
|||||||
case 'share':
|
case 'share':
|
||||||
return <ShareBubble data={contentData} />
|
return <ShareBubble data={contentData} />
|
||||||
case 'forwardBundle':
|
case 'forwardBundle':
|
||||||
return <ForwardBundleBubble data={contentData} />
|
return (
|
||||||
|
<ForwardBundleBubble
|
||||||
|
data={contentData}
|
||||||
|
sessionId={sessionId}
|
||||||
|
onImageClick={onImageClick}
|
||||||
|
/>
|
||||||
|
)
|
||||||
case 'miniProgram':
|
case 'miniProgram':
|
||||||
return (
|
return (
|
||||||
<MiniProgramBubble data={contentData} sessionId={sessionId} onImageClick={onImageClick} />
|
<MiniProgramBubble data={contentData} sessionId={sessionId} onImageClick={onImageClick} />
|
||||||
@@ -55,52 +62,97 @@ export function RichMessageBubble({
|
|||||||
}
|
}
|
||||||
|
|
||||||
function ForwardBundleBubble({
|
function ForwardBundleBubble({
|
||||||
data
|
data,
|
||||||
|
sessionId,
|
||||||
|
onImageClick
|
||||||
}: {
|
}: {
|
||||||
data: Extract<ParsedContent, { type: 'forwardBundle' }>
|
data: Extract<ParsedContent, { type: 'forwardBundle' }>
|
||||||
|
sessionId?: string
|
||||||
|
onImageClick?: (imageUrl: string) => void
|
||||||
}): JSX.Element {
|
}): JSX.Element {
|
||||||
const [expanded, setExpanded] = useState(false)
|
const [modalLayers, setModalLayers] = useState<ForwardBundleWindowLayer[]>([])
|
||||||
const visibleItems = expanded ? data.items : data.items.slice(0, 3)
|
const previewItems = data.items.slice(0, 4)
|
||||||
const hiddenCount = Math.max(0, data.items.length - visibleItems.length)
|
|
||||||
|
const openRootModal = useCallback((): void => {
|
||||||
|
setModalLayers([
|
||||||
|
{
|
||||||
|
id: `forward-root-${Date.now()}`,
|
||||||
|
title: data.title || '聊天记录',
|
||||||
|
items: data.items
|
||||||
|
}
|
||||||
|
])
|
||||||
|
}, [data.items, data.title])
|
||||||
|
|
||||||
|
const openNestedModal = useCallback(
|
||||||
|
(title: string, items: ForwardedMessageItem[]): void => {
|
||||||
|
setModalLayers((current) => [
|
||||||
|
...current,
|
||||||
|
{
|
||||||
|
id: `forward-nested-${current.length}-${Date.now()}`,
|
||||||
|
title: title || '聊天记录',
|
||||||
|
items
|
||||||
|
}
|
||||||
|
])
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
)
|
||||||
|
|
||||||
|
const closeFromIndex = useCallback((index: number): void => {
|
||||||
|
setModalLayers((current) => current.slice(0, index))
|
||||||
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="forward-bundle-message">
|
<>
|
||||||
<button
|
<div
|
||||||
type="button"
|
className="forward-bundle-message is-clickable"
|
||||||
className="forward-bundle-header"
|
role="button"
|
||||||
onClick={() => setExpanded(!expanded)}
|
tabIndex={0}
|
||||||
|
onClick={openRootModal}
|
||||||
|
onKeyDown={(event) => {
|
||||||
|
if (event.key === 'Enter' || event.key === ' ') {
|
||||||
|
event.preventDefault()
|
||||||
|
openRootModal()
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
title="点击弹窗查看完整聊天记录"
|
||||||
>
|
>
|
||||||
|
<div className="forward-bundle-header">
|
||||||
<span>{data.title || '聊天记录'}</span>
|
<span>{data.title || '聊天记录'}</span>
|
||||||
<small>
|
<small>
|
||||||
{data.items.length ? `${data.items.length} 条消息` : data.description || '聊天记录'}
|
{data.items.length ? `${data.items.length} 条消息` : data.description || '聊天记录'}
|
||||||
</small>
|
</small>
|
||||||
</button>
|
</div>
|
||||||
<div className="forward-bundle-list">
|
<div className="forward-bundle-list">
|
||||||
{visibleItems.length ? (
|
{previewItems.length ? (
|
||||||
visibleItems.map((item, index) => (
|
previewItems.map((item, index) => (
|
||||||
<div
|
<div
|
||||||
className="forward-bundle-item"
|
className="forward-bundle-item"
|
||||||
key={`${item.sender || ''}-${item.sentAt || ''}-${index}`}
|
key={`${item.dataId || ''}-${item.sender || ''}-${item.sentAt || ''}-${index}`}
|
||||||
>
|
>
|
||||||
{item.sender && <b>{item.sender}</b>}
|
{item.sender && <b>{item.sender}</b>}
|
||||||
<span>{renderWechatEmojiText(item.text, 24)}</span>
|
<span>{renderWechatEmojiText(item.text, 24)}</span>
|
||||||
{item.nested?.length ? <small>包含 {item.nested.length} 条聊天记录</small> : null}
|
{item.nested?.length ? (
|
||||||
|
<small>包含 {item.nested.length} 条嵌套聊天记录</small>
|
||||||
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
))
|
))
|
||||||
) : (
|
) : (
|
||||||
<div className="forward-bundle-empty">暂未解析到可展示的记录</div>
|
<div className="forward-bundle-empty">暂未解析到可展示的记录</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{(hiddenCount > 0 || expanded) && data.items.length > 3 ? (
|
<div className="forward-bundle-footer">
|
||||||
<button
|
<span>聊天记录</span>
|
||||||
type="button"
|
<span className="forward-bundle-footer-action">查看详情</span>
|
||||||
className="forward-bundle-toggle"
|
|
||||||
onClick={() => setExpanded(!expanded)}
|
|
||||||
>
|
|
||||||
{expanded ? '收起' : `展开其余 ${hiddenCount} 条`}
|
|
||||||
</button>
|
|
||||||
) : null}
|
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
<ForwardBundleModalStack
|
||||||
|
layers={modalLayers}
|
||||||
|
sessionId={sessionId}
|
||||||
|
onOpenNested={openNestedModal}
|
||||||
|
onCloseFromIndex={closeFromIndex}
|
||||||
|
onImageClick={onImageClick}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -451,6 +451,268 @@
|
|||||||
.forward-bundle-message {
|
.forward-bundle-message {
|
||||||
width: min(320px, 56vw);
|
width: min(320px, 56vw);
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
|
||||||
|
&.is-clickable {
|
||||||
|
cursor: pointer;
|
||||||
|
transition: opacity 0.15s ease;
|
||||||
|
|
||||||
|
&:hover .forward-bundle-footer-action {
|
||||||
|
color: var(--wxex-brand);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.forward-bundle-footer {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding-top: 8px;
|
||||||
|
border-top: 1px solid var(--wxex-border);
|
||||||
|
color: var(--wxex-text-muted);
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.forward-bundle-footer-action {
|
||||||
|
color: var(--wxex-text-secondary);
|
||||||
|
transition: color 0.15s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.forward-modal-backdrop {
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 24px;
|
||||||
|
background: rgba(15, 23, 42, 0.36);
|
||||||
|
}
|
||||||
|
|
||||||
|
.forward-modal-window {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
width: min(560px, calc(100vw - 64px));
|
||||||
|
max-height: min(76vh, 720px);
|
||||||
|
overflow: hidden;
|
||||||
|
border: 1px solid var(--wxex-border);
|
||||||
|
border-radius: 14px;
|
||||||
|
background: var(--wxex-bg-elevated, #ffffff);
|
||||||
|
color: var(--wxex-text-primary);
|
||||||
|
box-shadow: 0 20px 48px rgba(15, 23, 42, 0.22);
|
||||||
|
}
|
||||||
|
|
||||||
|
.forward-modal-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 12px;
|
||||||
|
padding: 14px 18px;
|
||||||
|
border-bottom: 1px solid var(--wxex-border);
|
||||||
|
background: var(--wxex-bg-surface, #f8fafc);
|
||||||
|
}
|
||||||
|
|
||||||
|
.forward-modal-header-text {
|
||||||
|
min-width: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.forward-modal-title {
|
||||||
|
margin: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: 600;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.forward-modal-subtitle {
|
||||||
|
color: var(--wxex-text-muted);
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.forward-modal-close {
|
||||||
|
flex-shrink: 0;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 28px;
|
||||||
|
height: 28px;
|
||||||
|
border: 0;
|
||||||
|
border-radius: 8px;
|
||||||
|
background: transparent;
|
||||||
|
color: var(--wxex-text-secondary);
|
||||||
|
font-size: 20px;
|
||||||
|
line-height: 1;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: rgba(15, 23, 42, 0.08);
|
||||||
|
color: var(--wxex-text-primary);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.forward-modal-body {
|
||||||
|
flex: 1;
|
||||||
|
overflow-y: auto;
|
||||||
|
padding: 16px 18px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.forward-modal-row {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 36px minmax(0, 1fr);
|
||||||
|
gap: 10px;
|
||||||
|
align-items: start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.forward-modal-avatar {
|
||||||
|
width: 36px;
|
||||||
|
height: 36px;
|
||||||
|
border-radius: 8px;
|
||||||
|
overflow: hidden;
|
||||||
|
background: rgba(7, 193, 96, 0.14);
|
||||||
|
color: var(--wxex-brand, #07c160);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 600;
|
||||||
|
|
||||||
|
img {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.forward-modal-row-main {
|
||||||
|
min-width: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 6px;
|
||||||
|
padding-bottom: 12px;
|
||||||
|
border-bottom: 1px solid var(--wxex-border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.forward-modal-row:last-child .forward-modal-row-main {
|
||||||
|
padding-bottom: 0;
|
||||||
|
border-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.forward-modal-row-meta {
|
||||||
|
display: flex;
|
||||||
|
align-items: baseline;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.forward-modal-sender {
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--wxex-text-primary);
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.forward-modal-time {
|
||||||
|
flex-shrink: 0;
|
||||||
|
font-size: 11px;
|
||||||
|
color: var(--wxex-text-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.forward-modal-row-body {
|
||||||
|
font-size: 13px;
|
||||||
|
line-height: 1.6;
|
||||||
|
color: var(--wxex-text-primary);
|
||||||
|
word-break: break-word;
|
||||||
|
}
|
||||||
|
|
||||||
|
.forward-modal-text {
|
||||||
|
white-space: pre-wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.forward-modal-link {
|
||||||
|
display: inline-block;
|
||||||
|
margin-left: 8px;
|
||||||
|
color: var(--wxex-brand, #07c160);
|
||||||
|
text-decoration: none;
|
||||||
|
font-size: 12px;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.forward-modal-image-wrap {
|
||||||
|
width: fit-content;
|
||||||
|
max-width: 240px;
|
||||||
|
|
||||||
|
.image-bubble {
|
||||||
|
width: fit-content;
|
||||||
|
max-width: 240px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.forward-modal-nested-card {
|
||||||
|
width: min(320px, 100%);
|
||||||
|
padding: 10px 12px;
|
||||||
|
border: 1px solid var(--wxex-border);
|
||||||
|
border-radius: 10px;
|
||||||
|
background: var(--wxex-bg-surface, #f8fafc);
|
||||||
|
color: inherit;
|
||||||
|
text-align: left;
|
||||||
|
display: grid;
|
||||||
|
gap: 6px;
|
||||||
|
|
||||||
|
&.is-clickable {
|
||||||
|
cursor: pointer;
|
||||||
|
transition: border-color 0.15s ease, background-color 0.15s ease;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
border-color: var(--wxex-brand, #07c160);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.forward-modal-nested-title {
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--wxex-text-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.forward-modal-nested-preview {
|
||||||
|
display: grid;
|
||||||
|
gap: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.forward-modal-nested-line,
|
||||||
|
.forward-modal-nested-empty {
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--wxex-text-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.forward-modal-nested-footer {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding-top: 6px;
|
||||||
|
border-top: 1px solid var(--wxex-border);
|
||||||
|
font-size: 11px;
|
||||||
|
color: var(--wxex-text-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.forward-modal-empty {
|
||||||
|
padding: 32px 0;
|
||||||
|
text-align: center;
|
||||||
|
color: var(--wxex-text-muted);
|
||||||
|
font-size: 13px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.forward-bundle-header,
|
.forward-bundle-header,
|
||||||
|
|||||||
@@ -9,7 +9,12 @@ const fileNameOf = (filePath: string): string =>
|
|||||||
|
|
||||||
export const imageFileQuality = (filePath: string): ExportImageQuality => {
|
export const imageFileQuality = (filePath: string): ExportImageQuality => {
|
||||||
const fileName = fileNameOf(filePath)
|
const fileName = fileNameOf(filePath)
|
||||||
if (!fileName.endsWith('.dat')) return 'original'
|
if (!fileName.endsWith('.dat')) {
|
||||||
|
if (/(?:_t(?:_m)?|_thumb|\.thumb)$/i.test(fileName)) {
|
||||||
|
return 'thumbnail'
|
||||||
|
}
|
||||||
|
return 'original'
|
||||||
|
}
|
||||||
if (/(?:_t(?:_m)?|_thumb|\.thumb|_b|_w|_c)\.dat$/i.test(fileName)) {
|
if (/(?:_t(?:_m)?|_thumb|\.thumb|_b|_w|_c)\.dat$/i.test(fileName)) {
|
||||||
return 'thumbnail'
|
return 'thumbnail'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,14 +101,28 @@ type ShareContent = {
|
|||||||
export type ForwardedMessageItem = {
|
export type ForwardedMessageItem = {
|
||||||
messageType: number
|
messageType: number
|
||||||
sender?: string
|
sender?: string
|
||||||
|
sourceHeadUrl?: string
|
||||||
sentAt?: string
|
sentAt?: string
|
||||||
text: string
|
text: string
|
||||||
|
title?: string
|
||||||
|
dataId?: string
|
||||||
|
dataIndex?: number
|
||||||
|
imageMd5?: string
|
||||||
|
thumbMd5?: string
|
||||||
|
imageDatName?: string
|
||||||
|
exportMediaUrl?: string
|
||||||
|
dataSize?: number
|
||||||
|
thumbSize?: number
|
||||||
|
fileExt?: string
|
||||||
|
linkUrl?: string
|
||||||
|
nestedTitle?: string
|
||||||
nested?: ForwardedMessageItem[]
|
nested?: ForwardedMessageItem[]
|
||||||
}
|
}
|
||||||
type ForwardBundleContent = {
|
type ForwardBundleContent = {
|
||||||
type: 'forwardBundle'
|
type: 'forwardBundle'
|
||||||
title: string
|
title: string
|
||||||
description?: string
|
description?: string
|
||||||
|
recordDir?: string
|
||||||
items: ForwardedMessageItem[]
|
items: ForwardedMessageItem[]
|
||||||
}
|
}
|
||||||
type MiniProgramContent = {
|
type MiniProgramContent = {
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
import { describe, expect, it, vi, beforeEach } from 'vitest'
|
||||||
|
import { fireEvent, render, screen } from '@testing-library/react'
|
||||||
|
import { RichMessageBubble } from '../../src/renderer/src/components/RichMessageBubble'
|
||||||
|
import type { ParsedContent } from '../../src/shared/types'
|
||||||
|
|
||||||
|
describe('ForwardBundleBubble stacked modal windows', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
;(window as unknown as { api?: Record<string, unknown> }).api = {
|
||||||
|
getImage: vi.fn().mockResolvedValue({
|
||||||
|
success: true,
|
||||||
|
data: 'data:image/jpeg;base64,AAAA'
|
||||||
|
}),
|
||||||
|
copyImage: vi.fn().mockResolvedValue({ success: true })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
it('opens a modal on click and stacks a second modal window for nested forwards', async () => {
|
||||||
|
const contentData: ParsedContent = {
|
||||||
|
type: 'forwardBundle',
|
||||||
|
title: '群聊的聊天记录',
|
||||||
|
recordDir: 'fixture-rec-0001',
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
messageType: 2,
|
||||||
|
sender: '张三',
|
||||||
|
sentAt: '2026-01-02 10:00',
|
||||||
|
text: '[图片]',
|
||||||
|
dataIndex: 0,
|
||||||
|
imageMd5: '0123456789abcdef0123456789abcdef',
|
||||||
|
imageDatName: 'rec:fixture-rec-0001:0'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
messageType: 17,
|
||||||
|
sender: '成员A',
|
||||||
|
sentAt: '2026-01-02 10:05',
|
||||||
|
text: '[聊天记录]',
|
||||||
|
nestedTitle: '嵌套的聊天记录',
|
||||||
|
nested: [
|
||||||
|
{
|
||||||
|
messageType: 1,
|
||||||
|
sender: '成员B',
|
||||||
|
sentAt: '2026-01-02 09:30',
|
||||||
|
text: '这是第二层弹窗里的内容'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
render(
|
||||||
|
<RichMessageBubble contentData={contentData} sessionId="filehelper" onImageClick={vi.fn()} />
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(screen.getByText('[图片]')).toBeTruthy()
|
||||||
|
expect(screen.queryAllByRole('dialog')).toHaveLength(0)
|
||||||
|
|
||||||
|
fireEvent.click(screen.getByTitle('点击弹窗查看完整聊天记录'))
|
||||||
|
expect(screen.getAllByRole('dialog')).toHaveLength(1)
|
||||||
|
expect(screen.getByRole('dialog', { name: '群聊的聊天记录' })).toBeTruthy()
|
||||||
|
|
||||||
|
fireEvent.click(screen.getByText('嵌套的聊天记录'))
|
||||||
|
expect(screen.getAllByRole('dialog')).toHaveLength(2)
|
||||||
|
expect(screen.getByRole('dialog', { name: '嵌套的聊天记录' })).toBeTruthy()
|
||||||
|
expect(screen.getByText('这是第二层弹窗里的内容')).toBeTruthy()
|
||||||
|
|
||||||
|
// 关闭顶层不应连带关掉下层。
|
||||||
|
const closeButtons = screen.getAllByLabelText('关闭聊天记录窗口')
|
||||||
|
fireEvent.click(closeButtons[1])
|
||||||
|
expect(screen.getAllByRole('dialog')).toHaveLength(1)
|
||||||
|
expect(screen.getByRole('dialog', { name: '群聊的聊天记录' })).toBeTruthy()
|
||||||
|
|
||||||
|
fireEvent.click(screen.getByLabelText('关闭聊天记录窗口'))
|
||||||
|
expect(screen.queryAllByRole('dialog')).toHaveLength(0)
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -258,6 +258,56 @@ describe('export media', () => {
|
|||||||
dom.window.close()
|
dom.window.close()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('opens the forward bundle of the clicked card after filters shrink the list', () => {
|
||||||
|
const html = renderExportPage('合并转发索引')
|
||||||
|
const dom = new JSDOM(html, { runScripts: 'outside-only' })
|
||||||
|
Object.assign(dom.window, {
|
||||||
|
__WECHAT_EXPORT__: {
|
||||||
|
version: 2,
|
||||||
|
name: '合并转发索引',
|
||||||
|
exportedAt: '2026-08-04T00:00:00.000Z',
|
||||||
|
conversations: [
|
||||||
|
{ id: 'alpha', name: '聊天 A', type: 'user', messageCount: 2 },
|
||||||
|
{ id: 'beta', name: '聊天 B', type: 'group', messageCount: 1 }
|
||||||
|
],
|
||||||
|
messages: [
|
||||||
|
messageForArchive('alpha-1', 'alpha', '聊天 A', '普通文本甲', 1_767_225_600),
|
||||||
|
{
|
||||||
|
...messageForArchive('alpha-2', 'alpha', '聊天 A', '合并转发摘要', 1_767_225_700),
|
||||||
|
contentData: {
|
||||||
|
type: 'forwardBundle',
|
||||||
|
title: '目标聊天记录',
|
||||||
|
items: [
|
||||||
|
{ messageType: 1, sender: '张三', text: '第一层内容甲' },
|
||||||
|
{ messageType: 1, sender: '李四', text: '第一层内容乙' }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
messageForArchive('beta-1', 'beta', '聊天 B', '普通文本乙', 1_769_904_000)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
dom.window.eval(inlineScriptOf(html))
|
||||||
|
|
||||||
|
const search = dom.window.document.querySelector('#query') as HTMLInputElement
|
||||||
|
search.value = '合并转发摘要'
|
||||||
|
search.dispatchEvent(new dom.window.Event('input'))
|
||||||
|
|
||||||
|
const list = dom.window.document.querySelector('#messages')!
|
||||||
|
expect(list.querySelectorAll('.message')).toHaveLength(1)
|
||||||
|
const card = list.querySelector('[data-forward-open]') as HTMLElement
|
||||||
|
expect(card.getAttribute('data-forward-open')).toBe('0')
|
||||||
|
|
||||||
|
card.dispatchEvent(new dom.window.MouseEvent('click', { bubbles: true }))
|
||||||
|
|
||||||
|
const root = dom.window.document.querySelector('#forward-modal-root')!
|
||||||
|
expect(root.querySelectorAll('.forward-modal-window')).toHaveLength(1)
|
||||||
|
expect(root.querySelector('.forward-modal-title')?.textContent).toBe('目标聊天记录')
|
||||||
|
expect(root.textContent).toContain('第一层内容甲')
|
||||||
|
dom.window.close()
|
||||||
|
})
|
||||||
|
|
||||||
it('locates every filtered message kind in all messages, including outside the latest window', () => {
|
it('locates every filtered message kind in all messages, including outside the latest window', () => {
|
||||||
const html = renderExportPage('定位消息')
|
const html = renderExportPage('定位消息')
|
||||||
const dom = new JSDOM(html, { runScripts: 'outside-only' })
|
const dom = new JSDOM(html, { runScripts: 'outside-only' })
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { describe, expect, it } from 'vitest'
|
import { describe, expect, it } from 'vitest'
|
||||||
import { parseMessageContent } from '../../src/main/message-parser'
|
import { attachForwardBundleRecordDir, parseMessageContent } from '../../src/main/message-parser'
|
||||||
|
|
||||||
describe('message parser', () => {
|
describe('message parser', () => {
|
||||||
it('parses image, voice and sticker messages without confusing their types', () => {
|
it('parses image, voice and sticker messages without confusing their types', () => {
|
||||||
@@ -79,6 +79,45 @@ describe('message parser', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('parses forwarded images (datatype=2), nested forwards (datatype=17), and attaches Rec dir refs', () => {
|
||||||
|
const xml = `<msg><appmsg><type>19</type><title>群聊的聊天记录</title><recorditem><![CDATA[<recordinfo><title>群聊的聊天记录</title><datalist count="2"><dataitem datatype="2" dataid="img-1"><sourcename>张三</sourcename><sourcetime>2026-01-02 10:00</sourcetime><fullmd5>0123456789abcdef0123456789abcdef</fullmd5><thumbfullmd5>fedcba9876543210fedcba9876543210</thumbfullmd5><datasize>204800</datasize><thumbsize>8192</thumbsize></dataitem><dataitem datatype="17" dataid="nest-1"><sourcename>成员A</sourcename><datatitle>内层聊天记录</datatitle><recordxml><recordinfo><title>内层聊天记录</title><datalist count="2"><dataitem datatype="1" dataid="inner-1"><sourcename>成员B</sourcename><datadesc>内层文本消息</datadesc></dataitem><dataitem datatype="2" dataid="inner-2"><sourcename>成员B</sourcename><fullmd5>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</fullmd5></dataitem></datalist></recordinfo></recordxml></dataitem></datalist></recordinfo>]]></recorditem></appmsg></msg>`
|
||||||
|
const parsed = parseMessageContent(xml, 49)
|
||||||
|
expect(parsed.type).toBe('forwardBundle')
|
||||||
|
if (parsed.type === 'forwardBundle') {
|
||||||
|
const attached = attachForwardBundleRecordDir(parsed, 'fixture-rec-0001')
|
||||||
|
expect(attached.recordDir).toBe('fixture-rec-0001')
|
||||||
|
expect(attached.items).toHaveLength(2)
|
||||||
|
expect(attached.items[0]).toMatchObject({
|
||||||
|
messageType: 2,
|
||||||
|
sender: '张三',
|
||||||
|
text: '[图片]',
|
||||||
|
dataIndex: 0,
|
||||||
|
imageMd5: '0123456789abcdef0123456789abcdef',
|
||||||
|
thumbMd5: 'fedcba9876543210fedcba9876543210',
|
||||||
|
imageDatName: 'rec:fixture-rec-0001:0',
|
||||||
|
dataSize: 204800,
|
||||||
|
thumbSize: 8192
|
||||||
|
})
|
||||||
|
expect(attached.items[1]).toMatchObject({
|
||||||
|
messageType: 17,
|
||||||
|
nestedTitle: '内层聊天记录'
|
||||||
|
})
|
||||||
|
expect(attached.items[1].imageMd5).toBeUndefined()
|
||||||
|
expect(attached.items[1].thumbMd5).toBeUndefined()
|
||||||
|
expect(attached.items[1].nested).toHaveLength(2)
|
||||||
|
expect(attached.items[1].nested?.[0]).toMatchObject({
|
||||||
|
messageType: 1,
|
||||||
|
sender: '成员B',
|
||||||
|
text: '内层文本消息'
|
||||||
|
})
|
||||||
|
expect(attached.items[1].nested?.[1]).toMatchObject({
|
||||||
|
messageType: 2,
|
||||||
|
text: '[图片]',
|
||||||
|
imageMd5: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
['6', '测试附件.pdf'],
|
['6', '测试附件.pdf'],
|
||||||
['74', '发送中的附件.zip']
|
['74', '发送中的附件.zip']
|
||||||
|
|||||||
@@ -143,6 +143,25 @@ describe('VideoAssetService local fallback', () => {
|
|||||||
expect(service.pathForUrl(result.url!)).toBe(join(month, `${targetStem}.mp4`))
|
expect(service.pathForUrl(result.url!)).toBe(join(month, `${targetStem}.mp4`))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('prefers _raw original video over compressed mp4 when both exist', async () => {
|
||||||
|
const { accountRoot, service } = createService()
|
||||||
|
const month = join(accountRoot, 'msg', 'video', '2026-11')
|
||||||
|
mkdirSync(month, { recursive: true })
|
||||||
|
const stem = '0c0236112233445566778899aabbcee6'
|
||||||
|
const compressedPath = join(month, `${stem}.mp4`)
|
||||||
|
const rawPath = join(month, `${stem}_raw.mp4`)
|
||||||
|
const posterPath = join(month, `${stem}_thumb.jpg`)
|
||||||
|
writeFileSync(compressedPath, mp4Fixture(10, 'compressed'))
|
||||||
|
writeFileSync(rawPath, mp4Fixture(10, 'original-raw-video-bytes'))
|
||||||
|
writeFileSync(posterPath, jpegFixture(720, 1280))
|
||||||
|
|
||||||
|
const result = await service.resolve([stem])
|
||||||
|
|
||||||
|
expect(result.success).toBe(true)
|
||||||
|
expect(service.pathForUrl(result.url!)).toBe(rawPath)
|
||||||
|
expect(service.pathForUrl(result.poster!)).toBe(posterPath)
|
||||||
|
})
|
||||||
|
|
||||||
it('does not guess when multiple files match the same metadata', async () => {
|
it('does not guess when multiple files match the same metadata', async () => {
|
||||||
const { accountRoot, service } = createService()
|
const { accountRoot, service } = createService()
|
||||||
const month = join(accountRoot, 'msg', 'video', '2026-02')
|
const month = join(accountRoot, 'msg', 'video', '2026-02')
|
||||||
|
|||||||
Reference in new issue
Block a user