fix(protocol): decode current NT flash-transfer cards
Current clients put fileset identity on markdown extInfo and the open_fileset scheme, not data.fileSetId. Empty message arrays were the old scraper missing those fields. Fixes #358
This commit is contained in:
5 files changed
+257
-38
No files matched your search
@@ -0,0 +1 @@
|
||||
0ad2190a43088dc2daaf0d1218755f5f4b593230365877546767686e5857376954796a4d6718aa1928bec6acea0c3218755f74676a704f715241555444556f784775433953375551123508a601180b2080c4e2e40d28d32230efe2f5d30638015883016080c4e2e48d80808001708201e001d3228002cfb398af8beee6cb711ad3180ad0180a21080010efe2f5d3061880c4e2e40d2000280a300038860140024a06e5ae8be4bd13129916aa039516082d128e160ac5145be997aae4bca05d286d71716170693a2f2f6d61726b646f776e2f6e6f64653f6e6f6465547970653d726963687569266a736f6e3d2537422532326275734964253232253341253232466c6173685472616e7366657225323225324325323274656d706c6174654964253232253341253232666c61736825323225324325323276657273696f6e253232253341322532432532326c61796f7574253232253341253742253232766965774964253232253341253232666c6173685f66696c6525323225324325323277696474682532322533412d322532432532326865696768742532322533412d32253243253232646972656374696f6e253232253341253232686f72697a6f6e74616c2532322532432532326c61796f757425323225334125354225374225323276696577496425323225334125323270726f67726573734c656674253232253243253232766965775479706525323225334125323263697263756c617250726f67726573732532322532432532326865696768742532322533413238253243253232776964746825323225334132382532432532326d617267696e5269676874253232253341382532432532326772617669747925323225334125323263656e746572566572746963616c25323225374425324325374225323276696577496425323225334125323266696c65253232253243253232646972656374696f6e253232253341253232766572746963616c2532322532432532326865696768742532322533412d3225324325323277696474682532322533413236332532432532326c61796f7574253232253341253542253742253232766965774964253232253341253232696d6167652532322532432532327669657754797065253232253341253232696d61676525323225324325323277696474682532322533412d312532432532326865696768742532322533413138302537442532432537422532327669657749642532322533412532327469746c6525323225324325323276696577547970652532322533412532327465787425323225324325323277696474682532322533412d312532432532326865696768742532322533412d322532432532326d617267696e546f7025323225334131322532432532326d617267696e4c65667425323225334131322532432532326d617267696e526967687425323225334131322537442532432537422532327669657749642532322533412532326465736325323225324325323276696577547970652532322533412532327465787425323225324325323277696474682532322533412d312532432532326865696768742532322533412d322532432532326d617267696e4c65667425323225334131322532432532326d617267696e546f70253232253341342532432532326d617267696e526967687425323225334131322537442532432537422532327669657749642532322533412532326469766964657225323225324325323277696474682532322533412d31253243253232686569676874253232253341302e352532432532326d617267696e546f7025323225334131332537442532432537422532327669657749642532322533412532327461696c253232253243253232646972656374696f6e253232253341253232686f72697a6f6e74616c25323225324325323277696474682532322533412d3125324325323268656967687425323225334132322532432532326d617267696e4c65667425323225334131322532432532326c61796f75742532322533412535422537422532327669657749642532322533412532327461696c49636f6e2532322532432532327669657754797065253232253341253232696d6167652532322532432532327769647468253232253341313225324325323268656967687425323225334131322532432532326772617669747925323225334125323263656e746572566572746963616c2532322537442532432537422532327669657749642532322533412532327461696c5465787425323225324325323276696577547970652532322533412532327465787425323225324325323277696474682532322533412d322532432532326865696768742532322533412d322532432532326772617669747925323225334125323263656e746572566572746963616c2532322532432532326d617267696e4c6566742532322533413425374425354425374425354425374425324325374225323276696577496425323225334125323270726f67726573735269676874253232253243253232766965775479706525323225334125323263697263756c617250726f67726573732532322532432532326865696768742532322533413238253243253232776964746825323225334132382532432532326d617267696e4c656674253232253341382532432532326772617669747925323225334125323263656e746572566572746963616c25323225374425354425374425324325323261747472696275746573253232253341253742253232766965774964253232253341253232666c6173685f66696c652532322532432532326174747269627574657325323225334125354225374225323276696577496425323225334125323270726f67726573734c65667425323225324325323270726f67726573732532322533413025324325323273746174652532322533412532326e6f6e652532322532432532326576656e74253232253341253742253232696e697425323225334125374225323276697369626c6543747225323225334125374225323276697369626c652532322533412532322532342532346c65667450726f677265737356697369626c6525323225324325323276697369626c65426568617665253232253341253232676f6e652532322532432532327372632532322533412532323125323225374425374425374425374425324325374225323276696577496425323225334125323266696c652532322532432532327261646975732532322533413130253243253232736368656d612532322533412532326d7171726f75746572253341253246253246666c6173685f7472616e736665722532466f70656e5f66696c6573657425334666696c657365745f69642533445b555549445d253543753030323676657273696Line truncated
|
||||
@@ -1,7 +1,9 @@
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { protobuf_encode } from '@snowluma/proton';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import { decodeRichBody } from '../../src/msg-push/rich-body-decoder';
|
||||
import type { MessageBody } from '@snowluma/proto-defs/message';
|
||||
import type { MessageBody, PushMsg } from '@snowluma/proto-defs/message';
|
||||
import type { MarkdownData } from '@snowluma/proto-defs/action';
|
||||
|
||||
// Build a svc=45 richui markdown commonElem carrying a FlashTransfer card, the
|
||||
@@ -46,3 +48,119 @@ describe('decodeRichBody / 闪传 flash_file (#199/#200)', () => {
|
||||
expect(out[0]?.type).toBe('markdown');
|
||||
});
|
||||
});
|
||||
|
||||
// Current NT cards (#358) put fileset identity on MarkdownData.extInfo
|
||||
// (extType=1 / DecodeMdExtInfoFileTransfer) and in the click scheme. The
|
||||
// richui JSON no longer has `data.fileSetId`.
|
||||
function currentNtFlashBody(json: unknown, ext?: MarkdownData['extInfo'], summary?: string): MessageBody {
|
||||
const markdown = `[闪传](mqqapi://markdown/node?nodeType=richui&json=${encodeURIComponent(JSON.stringify(json))})`;
|
||||
const pbElem = protobuf_encode<MarkdownData>({
|
||||
content: markdown,
|
||||
summary,
|
||||
extType: ext ? 1 : undefined,
|
||||
extInfo: ext,
|
||||
});
|
||||
return {
|
||||
richText: { elems: [{ commonElem: { serviceType: 45, businessType: 3, pbElem } } as never] },
|
||||
};
|
||||
}
|
||||
|
||||
const currentNtCardJson = {
|
||||
busId: 'FlashTransfer',
|
||||
templateId: 'flash',
|
||||
version: 2,
|
||||
layout: { viewId: 'flash_file', width: -2, height: -2, direction: 'horizontal' },
|
||||
attributes: {
|
||||
viewId: 'flash_file',
|
||||
attributes: [{
|
||||
viewId: 'file',
|
||||
scheme: 'mqqrouter://flash_transfer/open_fileset?fileset_id=fs-nt-358&version=1&channel_id=1&src_type=internal&scene_type=1',
|
||||
}],
|
||||
},
|
||||
};
|
||||
|
||||
describe('decodeRichBody / 闪传 flash_file (#358 current NT card)', () => {
|
||||
it('reads filesetId and name from markdown extInfo when the JSON has no data.fileSetId', () => {
|
||||
const out = decodeRichBody(currentNtFlashBody(currentNtCardJson, {
|
||||
filesetId: 'fs-nt-358',
|
||||
name: 'cpwd截图.zip',
|
||||
fileSize: 9196055,
|
||||
expireTime: 1787815533,
|
||||
}, '[QQ闪传] cpwd截图.zip'), true);
|
||||
expect(out).toEqual([{
|
||||
type: 'flash_file',
|
||||
filesetId: 'fs-nt-358',
|
||||
fileName: 'cpwd截图.zip',
|
||||
sceneType: 1,
|
||||
}]);
|
||||
});
|
||||
|
||||
it('falls back to the open_fileset scheme when extInfo is absent', () => {
|
||||
const out = decodeRichBody(currentNtFlashBody(currentNtCardJson), true);
|
||||
expect(out).toEqual([{
|
||||
type: 'flash_file',
|
||||
filesetId: 'fs-nt-358',
|
||||
fileName: '',
|
||||
sceneType: 1,
|
||||
}]);
|
||||
});
|
||||
|
||||
it('still decodes from extInfo when the richui JSON is truncated', () => {
|
||||
const markdown = '[闪传](mqqapi://markdown/node?nodeType=richui&json=%7B%22busId%22%3A%22FlashTransfer%22%2C%22src%22%3A%22';
|
||||
const pbElem = protobuf_encode<MarkdownData>({
|
||||
content: markdown,
|
||||
summary: '[QQ闪传] report.pdf',
|
||||
extType: 1,
|
||||
extInfo: { filesetId: 'fs-from-ext', name: 'report.pdf' },
|
||||
});
|
||||
const out = decodeRichBody({
|
||||
richText: { elems: [{ commonElem: { serviceType: 45, businessType: 3, pbElem } } as never] },
|
||||
}, true);
|
||||
expect(out).toEqual([{
|
||||
type: 'flash_file',
|
||||
filesetId: 'fs-from-ext',
|
||||
fileName: 'report.pdf',
|
||||
sceneType: 0,
|
||||
}]);
|
||||
});
|
||||
|
||||
it('drops the compatibility text sibling after a successful flash_file decode', () => {
|
||||
const markdown = `[闪传](mqqapi://markdown/node?nodeType=richui&json=${encodeURIComponent(JSON.stringify(currentNtCardJson))})`;
|
||||
const pbElem = protobuf_encode<MarkdownData>({
|
||||
content: markdown,
|
||||
extType: 1,
|
||||
extInfo: { filesetId: 'fs-nt-358', name: 'a.zip' },
|
||||
});
|
||||
const out = decodeRichBody({
|
||||
richText: {
|
||||
elems: [
|
||||
{ commonElem: { serviceType: 45, businessType: 3, pbElem } } as never,
|
||||
{ text: { str: '[闪传]' } } as never,
|
||||
],
|
||||
},
|
||||
}, true);
|
||||
expect(out).toEqual([{
|
||||
type: 'flash_file',
|
||||
filesetId: 'fs-nt-358',
|
||||
fileName: 'a.zip',
|
||||
sceneType: 1,
|
||||
}]);
|
||||
});
|
||||
|
||||
it('decodes the sanitized #358 C2C push (extInfo + open_fileset scheme)', () => {
|
||||
const hex = readFileSync(
|
||||
fileURLToPath(new URL('./fixtures/issue-358-flash-push.hex', import.meta.url)),
|
||||
'utf8',
|
||||
).trim();
|
||||
const push = protobuf_decode<PushMsg>(Buffer.from(hex, 'hex'));
|
||||
const out = decodeRichBody(push.message?.body, false);
|
||||
// Reporter redacted the richui JSON (unterminated src), so scene_type
|
||||
// cannot be recovered from the scheme. extInfo still supplies fileset + name.
|
||||
expect(out).toEqual([{
|
||||
type: 'flash_file',
|
||||
filesetId: '[UUID]',
|
||||
fileName: 'cpwd截图.zip',
|
||||
sceneType: 0,
|
||||
}]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user