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:
7 files changed
+48
-7
No files matched your search
@@ -478,6 +478,7 @@ export const ELEMENT_CODECS = {
|
||||
title: element.fileName ?? '',
|
||||
file_set_id: element.filesetId ?? '',
|
||||
scene_type: element.sceneType ?? 0,
|
||||
thumb: element.thumbUrl ?? '',
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
@@ -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)', () => {
|
||||
|
||||
@@ -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>;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 按设计不支持',
|
||||
},
|
||||
|
||||
@@ -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]',
|
||||
}]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user