mirror of
https://github.com/hansjone/dsh-im-ops.git
synced 2026-10-16 04:03:18 +08:00
feat: support inbound files across all channels
This commit is contained in:
parent
29bcb67a64
commit
0a26d7df92
45 changed files with 2651 additions and 343 deletions
|
|
@ -5,6 +5,7 @@ import test from 'node:test';
|
|||
import {
|
||||
createWeixinApi,
|
||||
decryptWeixinImage,
|
||||
extractWeixinFiles,
|
||||
extractWeixinText,
|
||||
normalizeWeixinApiBaseUrl,
|
||||
parseWeixinImageAesKey,
|
||||
|
|
@ -65,6 +66,42 @@ test('iLink image references download lazily from the canonical CDN and decrypt
|
|||
assert.equal(calls[0].init.redirect, 'manual');
|
||||
});
|
||||
|
||||
test('iLink native file items download lazily and decrypt without image size or type rules', async () => {
|
||||
const key = randomBytes(16);
|
||||
const plaintext = Buffer.from('weixin-native-file');
|
||||
const ciphertext = encryptImage(plaintext, key);
|
||||
const calls = [];
|
||||
const files = extractWeixinFiles({
|
||||
item_list: [{
|
||||
type: 4,
|
||||
file_item: {
|
||||
media: {
|
||||
encrypt_query_param: 'native-file-ticket',
|
||||
aes_key: Buffer.from(key.toString('hex')).toString('base64'),
|
||||
encrypt_type: 1,
|
||||
},
|
||||
file_name: '微信报告.zip',
|
||||
len: String(plaintext.length),
|
||||
},
|
||||
}],
|
||||
}, {
|
||||
fetchImpl: async (url, init) => {
|
||||
calls.push({ url: url.toString(), init });
|
||||
return new Response(ciphertext);
|
||||
},
|
||||
});
|
||||
|
||||
assert.equal(files.length, 1);
|
||||
assert.equal(files[0].name, '微信报告.zip');
|
||||
assert.equal(files[0].size, plaintext.length);
|
||||
assert.equal(calls.length, 0, 'file download stays lazy');
|
||||
assert.deepEqual(await files[0].load({}), plaintext);
|
||||
assert.deepEqual(calls, [{
|
||||
url: 'https://novac2c.cdn.weixin.qq.com/c2c/download?encrypted_query_param=native-file-ticket',
|
||||
init: { method: 'GET', signal: undefined, redirect: 'manual' },
|
||||
}]);
|
||||
});
|
||||
|
||||
test('Weixin image keys support both documented CDN encodings and reject unsafe URLs', () => {
|
||||
const key = randomBytes(16);
|
||||
assert.equal(parseWeixinImageAesKey({ aeskey: key.toString('hex') }).equals(key), true);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue