feat(flash-file): expose cover URL as flash_file.thumb

Incoming flash cards already carry a cover link; map it to
flash_file.data.thumb. Older cards without a cover leave it empty.

Fixes #367
This commit is contained in:
DrSmoothl committed 2026-08-14 14:00:18 +08:00
1 parent 8e9e228a0f
commit 925d9c0ac7
7 files changed
+48 -7

No files matched your search

+1 -1
View File
@@ -213,7 +213,7 @@ export const ELEMENT_MANIFEST = {
},
flash_file: {
directions: { D: 'yes', S: 'yes', P: 'by-design-no', W: 'by-design-no' },
fields: fieldsFor<'flash_file'>()(['filesetId', 'sceneType', 'fileName']),
fields: fieldsFor<'flash_file'>()(['filesetId', 'sceneType', 'fileName', 'thumbUrl']),
requiredFields: ['filesetId'],
note: '闪传文件:收侧解码 markdown commonElem(旧卡 JSON data.fileSetId,现网 extType=1/extInfo + open_fileset scheme,#199/#200/#358);发送走 send_flash_msg,故 P/W 按设计不支持',
},
+2
View File
@@ -191,6 +191,8 @@ export interface FlashFileElement {
filesetId: string;
sceneType?: number;
fileName?: string;
/** Cover URL from the incoming card, when present. */
thumbUrl?: string;
}
type MessageElementVariant =
@@ -1070,11 +1070,13 @@ function decodeFlashTransfer(md: MarkdownData): MessageElement | null {
fileName = md.summary.replace(/^\[QQ闪传\]\s*/, '').trim();
}
const thumbUrl = (ext?.thumbnail?.download?.downloadUrl ?? '').trim();
return {
type: 'flash_file',
filesetId,
fileName,
sceneType: card?.sceneType ?? 0,
...(thumbUrl ? { thumbUrl } : {}),
};
}
@@ -95,6 +95,21 @@ describe('decodeRichBody / 闪传 flash_file (#358 current NT card)', () => {
}]);
});
it('reads the cover URL from extInfo.thumbnail', () => {
const out = decodeRichBody(currentNtFlashBody(currentNtCardJson, {
filesetId: 'fs-nt-358',
name: 'a.zip',
thumbnail: { download: { field1: 2, downloadUrl: 'https://example.test/cover.jpg' } },
}), true);
expect(out).toEqual([{
type: 'flash_file',
filesetId: 'fs-nt-358',
fileName: 'a.zip',
sceneType: 1,
thumbUrl: 'https://example.test/cover.jpg',
}]);
});
it('falls back to the open_fileset scheme when extInfo is absent', () => {
const out = decodeRichBody(currentNtFlashBody(currentNtCardJson), true);
expect(out).toEqual([{
@@ -155,12 +170,14 @@ describe('decodeRichBody / 闪传 flash_file (#358 current NT card)', () => {
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.
// cannot be recovered from the scheme. extInfo still supplies fileset + name
// and the cover URL (placeholder).
expect(out).toEqual([{
type: 'flash_file',
filesetId: '[UUID]',
fileName: 'cpwd截图.zip',
sceneType: 0,
thumbUrl: '[FILE_URL]',
}]);
});
});