feat: 支持按导出媒体文件名精确搜索

离线 HTML 搜索支持使用不含扩展名的完整图片或视频哈希文件名进行精确匹配,并保持其他消息字段的模糊搜索行为。\n\n补充图片和视频命中、大小写兼容、哈希片段及带扩展名不命中的 DOM 回归测试。
This commit is contained in:
Nanin
2026-08-12 22:02:43 +08:00
parent 34b86af0be
commit 8fac752e2b
2 changed files with 73 additions and 3 deletions
+17 -2
View File
@@ -995,6 +995,19 @@ const renderExportScript = (name: string): string => `
message.contentData && forwardedSearchText(message.contentData.items),
message.exportMediaName
].filter(Boolean).join(' ').toLowerCase()
const exportedImageOrVideoFileStem = (message) => {
const mediaType = message.exportMediaType || (message.contentData && message.contentData.type)
if (mediaType !== 'image' && mediaType !== 'video') return ''
const mediaUrl = String(message.exportMediaUrl || '').split(/[?#]/, 1)[0]
const fileName = mediaUrl.slice(mediaUrl.lastIndexOf('/') + 1)
if (!fileName) return ''
let decodedFileName = fileName
try {
decodedFileName = decodeURIComponent(fileName)
} catch {}
const extensionIndex = decodedFileName.lastIndexOf('.')
return (extensionIndex > 0 ? decodedFileName.slice(0, extensionIndex) : decodedFileName).toLowerCase()
}
const shareLabel = (typeVal) => {
if (String(typeVal) === '5') return '公众号链接'
@@ -1516,7 +1529,9 @@ const renderExportScript = (name: string): string => `
return allMessages.filter((message) =>
(activeConversation === 'all' || message.exportConversationId === activeConversation) &&
(activeKind === 'all' || kindOf(message) === activeKind) &&
(!term || searchText(message).includes(term))
(!term ||
searchText(message).includes(term) ||
exportedImageOrVideoFileStem(message) === term)
)
}
const applyFilters = (restorePosition = false) => {
@@ -1779,7 +1794,7 @@ export function renderExportPage(name: string): string {
</div>
</div>
<div class="controls">
<input id="query" type="search" placeholder="搜索发送者消息内容…" aria-label="搜索消息">
<input id="query" type="search" placeholder="搜索发送者消息内容或媒体文件名(不含后缀)…" aria-label="搜索消息">
</div>
<div class="filters" id="filters">
<button class="filter-button active" type="button" data-kind="all">全部</button>