mirror of
https://wget.la/https://github.com/Wxw-Gu/WechatExplorer
synced 2026-12-01 01:05:30 +08:00
feat: macOS发送和windows统一
This commit is contained in:
1 parent
518a9662a7
commit
9b2174a097
11 files changed
+710
-972
No files matched your search
@@ -131,4 +131,40 @@ describe('resolveExternalComponent', () => {
|
||||
|
||||
expect(resolveExternalComponent(env(), 'win32')).toBeNull()
|
||||
})
|
||||
|
||||
it('macOS 校验通过时返回完整 Pro WCDB 与 Runtime 组件路径', () => {
|
||||
const homeDir = path.join(tmpRoot, 'MacHome')
|
||||
const proRoot = path.join(homeDir, 'Library', 'Application Support', 'TraceMemo', 'Pro', 'macos-arm64')
|
||||
const versionDir = path.join(proRoot, '1.0.0')
|
||||
const wcdbApi = writeFile(path.join(versionDir, 'libwcdb_api.dylib'), Buffer.alloc(2048, 0x11))
|
||||
const wcdb = writeFile(path.join(versionDir, 'libWCDB.dylib'), Buffer.alloc(4096, 0x22))
|
||||
const helper = writeFile(path.join(versionDir, 'tm-wcdb-config-helper'), Buffer.alloc(1024, 0x33))
|
||||
const license = writeFile(path.join(versionDir, 'libtmlicense.dylib'), Buffer.alloc(512, 0x44))
|
||||
const host = writeFile(path.join(versionDir, 'tm-wechat-host'), Buffer.alloc(1024, 0x55))
|
||||
|
||||
const manifest = {
|
||||
schemaVersion: 1,
|
||||
componentVersion: '1.0.0',
|
||||
worktreeDirty: false,
|
||||
files: [
|
||||
{ path: 'libwcdb_api.dylib', size: wcdbApi.length, sha256: sha256(wcdbApi) },
|
||||
{ path: 'libWCDB.dylib', size: wcdb.length, sha256: sha256(wcdb) },
|
||||
{ path: 'tm-wcdb-config-helper', size: helper.length, sha256: sha256(helper) },
|
||||
{ path: 'libtmlicense.dylib', size: license.length, sha256: sha256(license) },
|
||||
{ path: 'tm-wechat-host', size: host.length, sha256: sha256(host) }
|
||||
]
|
||||
}
|
||||
writeFile(path.join(versionDir, 'manifest.json'), JSON.stringify(manifest, null, 2))
|
||||
writeFile(
|
||||
path.join(proRoot, 'current.json'),
|
||||
JSON.stringify({ version: '1.0.0', dir: versionDir }, null, 2)
|
||||
)
|
||||
|
||||
const found = resolveExternalComponent({ HOME: homeDir }, 'darwin')
|
||||
expect(found).not.toBeNull()
|
||||
expect(found?.dir).toBe(versionDir)
|
||||
expect(found?.helperPath).toBe(path.join(versionDir, 'tm-wcdb-config-helper'))
|
||||
expect(found?.version).toBe('1.0.0')
|
||||
expect(found?.dirty).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -122,7 +122,44 @@ describe('macOS message-source send routing', () => {
|
||||
type: 'image', to: 'fixture-contact', path: stagedPath
|
||||
})
|
||||
expect(stagedPath).not.toBe(filePath)
|
||||
expect(existsSync(stagedPath)).toBe(false)
|
||||
// 暂存图必须保留:微信在 /sendMsg 返回后才异步读取,立刻删除会让消息静默丢失。
|
||||
expect(existsSync(stagedPath)).toBe(true)
|
||||
})
|
||||
|
||||
it('只清扫超过保留期的历史暂存图,不动保留期内的文件', async () => {
|
||||
const root = temporaryDirectory()
|
||||
const filePath = join(root, 'fixture-image.png')
|
||||
writeFileSync(filePath, 'fixture-image')
|
||||
const imageTemp = join(root, 'wxid_fixture_self', 'temp', 'ImageTemp', '2026-11')
|
||||
mkdirSync(imageTemp, { recursive: true })
|
||||
const stale = join(imageTemp, 'tm-stale-0001.png')
|
||||
const fresh = join(imageTemp, 'tm-fresh-0001.png')
|
||||
const unrelated = join(imageTemp, 'wechat-own.png')
|
||||
for (const p of [stale, fresh, unrelated]) writeFileSync(p, 'x')
|
||||
const old = new Date(Date.now() - 60 * 60 * 1000)
|
||||
utimesSync(stale, old, old)
|
||||
utimesSync(unrelated, old, old)
|
||||
runtimeMocks.getSendMechanism.mockResolvedValue('tm-message-source-send')
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
status: 200,
|
||||
json: async () => ({ code: 0, ok: true, message: 'sent' })
|
||||
})
|
||||
)
|
||||
|
||||
await new PersonalWechatSendService(root).send({
|
||||
type: 'image',
|
||||
to: 'fixture-contact',
|
||||
isGroup: false,
|
||||
filePath
|
||||
})
|
||||
|
||||
expect(existsSync(stale)).toBe(false)
|
||||
expect(existsSync(fresh)).toBe(true)
|
||||
// 非 tm- 前缀的文件不属于我们,过期也不能删。
|
||||
expect(existsSync(unrelated)).toBe(true)
|
||||
})
|
||||
|
||||
it('uses the legacy image path only when source preparation is definitively rejected', async () => {
|
||||
|
||||
Reference in new issue
Block a user