mirror of
https://wget.la/https://github.com/Wxw-Gu/WechatExplorer
synced 2026-11-30 16:02:58 +08:00
fix: 修复导出日期、语音和联系人名字问题
- 导出的 HTML:点月份先看日期,选中日期后才跳到对应消息。 - 语音转文字:不同账号、不同聊天里的语音不会再串到一起。 - 联系人名字:正常昵称显示不变;昵称异常时使用可见的备注或账号,导出文件名也能正常使用。
This commit is contained in:
1 parent
ab3b3731b7
commit
add16885fe
19 files changed
+702
-150
No files matched your search
@@ -0,0 +1,64 @@
|
||||
import type { Contact } from './types'
|
||||
|
||||
type ContactNameSource = Partial<Pick<
|
||||
Contact,
|
||||
| 'm_nsNickName'
|
||||
| 'm_nsUsrName'
|
||||
| 'remark'
|
||||
| 'alias'
|
||||
| 'wechatNickname'
|
||||
| 'wechatId'
|
||||
| 'wxid'
|
||||
>>
|
||||
|
||||
const nonRenderingCharacters = /[\p{Cc}\p{Cf}\p{Co}\p{Cs}]/gu
|
||||
const trailingPathCharacters = /[. ]+$/u
|
||||
const reservedDeviceName = /^(con|prn|aux|nul|com[0-9]|lpt[0-9])(?:\..*)?$/iu
|
||||
|
||||
/** Remove characters that can make a name invisible while preserving normal emoji and CJK text. */
|
||||
export function visibleNamePart(value: unknown): string {
|
||||
return String(value ?? '')
|
||||
.replace(nonRenderingCharacters, '')
|
||||
.replace(/[\r\n\t]+/gu, ' ')
|
||||
.replace(/ {2,}/gu, ' ')
|
||||
.trim()
|
||||
}
|
||||
|
||||
export function isVisibleName(value: unknown): boolean {
|
||||
return visibleNamePart(value).length > 0
|
||||
}
|
||||
|
||||
/** Resolve a contact label without ever exposing an all-invisible raw nickname. */
|
||||
export function displayContactName(
|
||||
contact: ContactNameSource | null | undefined,
|
||||
fallback = '未命名联系人'
|
||||
): string {
|
||||
const candidates = [
|
||||
contact?.m_nsNickName,
|
||||
contact?.remark,
|
||||
contact?.alias,
|
||||
contact?.wechatNickname,
|
||||
contact?.wechatId,
|
||||
contact?.wxid,
|
||||
contact?.m_nsUsrName
|
||||
]
|
||||
for (const candidate of candidates) {
|
||||
const visible = visibleNamePart(candidate)
|
||||
if (visible) return visible
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
/** Make a human-readable label safe for a file or directory name. */
|
||||
export function filesystemSafeName(value: unknown, fallback = '未命名联系人'): string {
|
||||
const visible = visibleNamePart(value)
|
||||
const replaced = visible
|
||||
.replace(/[\\/:*?"<>|]/gu, '_')
|
||||
.replace(/[\r\n\t]+/gu, ' ')
|
||||
.replace(/ {2,}/gu, ' ')
|
||||
.replace(trailingPathCharacters, '')
|
||||
.trim()
|
||||
const candidate = replaced || visibleNamePart(fallback) || '未命名联系人'
|
||||
if (reservedDeviceName.test(candidate)) return `${candidate}_`
|
||||
return Array.from(candidate).slice(0, 80).join('') || '未命名联系人'
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
import { visibleNamePart } from './contact-name'
|
||||
|
||||
export type MemberNameMode = 'groupNickname' | 'wechatNickname' | 'remark'
|
||||
|
||||
export interface MemberNameFields {
|
||||
@@ -9,7 +11,7 @@ export interface MemberNameFields {
|
||||
}
|
||||
|
||||
const firstName = (...values: Array<string | undefined>): string =>
|
||||
values.map((value) => String(value || '').trim()).find(Boolean) || ''
|
||||
values.map((value) => visibleNamePart(value)).find(Boolean) || ''
|
||||
|
||||
export function resolveMemberName(member: MemberNameFields, mode: MemberNameMode): string {
|
||||
if (mode === 'groupNickname') {
|
||||
|
||||
Reference in new issue
Block a user