diff --git a/packages/onebot/src/event-converter/element-codecs.ts b/packages/onebot/src/event-converter/element-codecs.ts index 97163182..5b72728d 100644 --- a/packages/onebot/src/event-converter/element-codecs.ts +++ b/packages/onebot/src/event-converter/element-codecs.ts @@ -478,6 +478,7 @@ export const ELEMENT_CODECS = { title: element.fileName ?? '', file_set_id: element.filesetId ?? '', scene_type: element.sceneType ?? 0, + thumb: element.thumbUrl ?? '', }, }; }, diff --git a/packages/onebot/tests/flash-file-segment.test.ts b/packages/onebot/tests/flash-file-segment.test.ts index 91a8278f..c136932f 100644 --- a/packages/onebot/tests/flash-file-segment.test.ts +++ b/packages/onebot/tests/flash-file-segment.test.ts @@ -5,15 +5,21 @@ import type { MessageElement } from '@snowluma/protocol/events'; // The receive-side flash_file codec (#199/#200). Sending is a separate action // (send_flash_msg), so there is no fromSegment. describe('flash_file element → OneBot segment (#199/#200)', () => { - it('maps filesetId/fileName/sceneType → file_set_id/title/scene_type', async () => { - const el: MessageElement = { type: 'flash_file', filesetId: 'fs-1', fileName: 'a.pdf', sceneType: 2 }; + it('maps filesetId/fileName/sceneType/thumbUrl → file_set_id/title/scene_type/thumb', async () => { + const el: MessageElement = { + type: 'flash_file', filesetId: 'fs-1', fileName: 'a.pdf', sceneType: 2, + thumbUrl: 'https://example.test/cover.jpg', + }; const seg = await ELEMENT_CODECS.flash_file!.toSegment!(el, {} as never); - expect(seg).toEqual({ type: 'flash_file', data: { title: 'a.pdf', file_set_id: 'fs-1', scene_type: 2 } }); + expect(seg).toEqual({ + type: 'flash_file', + data: { title: 'a.pdf', file_set_id: 'fs-1', scene_type: 2, thumb: 'https://example.test/cover.jpg' }, + }); }); it('defaults missing fields to empty / 0', async () => { const seg = await ELEMENT_CODECS.flash_file!.toSegment!({ type: 'flash_file' } as MessageElement, {} as never); - expect(seg).toEqual({ type: 'flash_file', data: { title: '', file_set_id: '', scene_type: 0 } }); + expect(seg).toEqual({ type: 'flash_file', data: { title: '', file_set_id: '', scene_type: 0, thumb: '' } }); }); it('is receive-only (no fromSegment)', () => { diff --git a/packages/proto-defs/src/action.ts b/packages/proto-defs/src/action.ts index 9e58823c..424a9368 100644 --- a/packages/proto-defs/src/action.ts +++ b/packages/proto-defs/src/action.ts @@ -96,11 +96,24 @@ export interface MentionExtraSend { // Markdown commonElem (svc=45). Official DecodeMarkdownElement reads // content / process_msg / summary / extType / mdExtInfo. // extType=1 dispatches to DecodeMdExtInfoFileTransfer. +/** extInfo.thumbnail — cover download info, not raw image bytes. */ +export interface MarkdownFlashTransferThumbUrl { + field1?: pb<1, uint_32>; + downloadUrl?: pb<2, string>; +} + +export interface MarkdownFlashTransferThumb { + fileId?: pb<1, string>; + download?: pb<2, MarkdownFlashTransferThumbUrl>; + sha1?: pb<3, string>; + field4?: pb<4, uint_32>; +} + export interface MarkdownFlashTransferExt { filesetId?: pb<1, string>; name?: pb<2, string>; fileSize?: pb<3, uint_32>; - thumbnail?: pb<4, bytes>; + thumbnail?: pb<4, MarkdownFlashTransferThumb>; expireTime?: pb<6, uint_32>; } diff --git a/packages/protocol/src/element-manifest.ts b/packages/protocol/src/element-manifest.ts index 0cdef7af..ee5bd219 100644 --- a/packages/protocol/src/element-manifest.ts +++ b/packages/protocol/src/element-manifest.ts @@ -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 按设计不支持', }, diff --git a/packages/protocol/src/events.ts b/packages/protocol/src/events.ts index c77d1bc0..d17adc8d 100644 --- a/packages/protocol/src/events.ts +++ b/packages/protocol/src/events.ts @@ -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 = diff --git a/packages/protocol/src/msg-push/rich-body-decoder.ts b/packages/protocol/src/msg-push/rich-body-decoder.ts index ed6cb695..a4d061e2 100644 --- a/packages/protocol/src/msg-push/rich-body-decoder.ts +++ b/packages/protocol/src/msg-push/rich-body-decoder.ts @@ -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 } : {}), }; } diff --git a/packages/protocol/tests/msg-push/flash-transfer-decode.test.ts b/packages/protocol/tests/msg-push/flash-transfer-decode.test.ts index eeb94489..b3fe4e0b 100644 --- a/packages/protocol/tests/msg-push/flash-transfer-decode.test.ts +++ b/packages/protocol/tests/msg-push/flash-transfer-decode.test.ts @@ -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(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]', }]); }); });