fix(onebot): add canonical fields to file segment and fix log rendering (#94)

* fix(onebot): support inline file url/path in send_group/private_msg

* test(onebot): update file segment parser test for inline url/path support

* fix(onebot): add canonical fields to file segment and fix log rendering
This commit is contained in:
游手好闲的言柒 authored and GitHub committed 2026-06-11 15:40:47 +08:00
1 parent d804a3b2e0
commit d2a67cb560
4 files changed
+35 -6

No files matched your search

@@ -104,12 +104,22 @@ async function elementToSegment(
if (element.type === 'file') {
const url = mediaUrlResolver ? await mediaUrlResolver(element, isGroup, sessionId) : (element.url ?? '');
const fileName = element.fileName ?? '';
const fileSize = element.fileSize ?? 0;
const fileId = element.fileId ?? '';
return {
type: 'file',
data: {
name: element.fileName ?? '',
size: element.fileSize ?? 0,
id: element.fileId ?? '',
// NapCat/LLOneBot-style canonical fields — most downstream
// OneBot adapters read these (`file`/`file_id`/`file_size`).
file: fileName,
file_id: fileId,
file_size: fileSize,
// Legacy SnowLuma field names, kept for backward compat with
// any consumer that already reads name/size/id.
name: fileName,
size: fileSize,
id: fileId,
url,
file_hash: element.fileHash ?? '',
},
@@ -438,14 +438,18 @@ describe('convertEvent — message elements (13 segment types)', () => {
expect((seg2.data as Record<string, unknown>).resid).toBe(50);
});
it('file: name + size + id + url + file_hash, url via mediaUrlResolver', async () => {
it('file: canonical file/file_id/file_size + legacy name/size/id + url + file_hash', async () => {
const seg = await segment(
{ type: 'file', fileName: 'doc.pdf', fileSize: 7, fileId: 'fid', fileHash: 'h' },
{ mediaUrlResolver: async () => 'http://download' },
);
expect(seg.type).toBe('file');
expect(seg.data).toEqual({
name: 'doc.pdf', size: 7, id: 'fid', url: 'http://download', file_hash: 'h',
// NapCat/LLOneBot-style canonical fields
file: 'doc.pdf', file_id: 'fid', file_size: 7,
// legacy SnowLuma fields
name: 'doc.pdf', size: 7, id: 'fid',
url: 'http://download', file_hash: 'h',
});
});