fix(file): route group publish through OIDB 0x6d9_4 and cache upload meta for c2c resend

The chat-publish step after upload_group_file used to ship a PbSendMsg
with a transElem(elemType=24) — but that wire shape is RECEIVE-side
only, and current QQ-NT rejects it on send with `result=79`. Lagrange.
Core V2 uses a dedicated `OidbSvcTrpcTcp.0x6d9_4` for the publish
(`GroupSendFileService.cs`); mirror that. Send_group_msg with a
`{type:'file', file_id}` segment now routes through the same path
after the OneBot layer splits file segments out (matching the c2c
file split pattern).

Separately, send_private_msg with just `{file_id}` was shipping a 0 B
file because the wire packet for c2c file send needs fileSize/fileMd5/
fileName/fileHash but the OneBot caller only echoes the file_id from
upload_private_file. Add a bounded (1024-entry, FIFO) bridge cache
populated at upload time so the send-message path can rehydrate the
full tuple; inline segment fields still take precedence so callers
that track the metadata themselves can bypass the cache. Parser now
also accepts `file_hash`/`fileHash` on file segments.

Also: file segments no longer get a `[空消息]` log line — the format
string now shows `[文件:<name-or-id>]`.
This commit is contained in:
DrSmoothl committed 2026-05-20 13:30:13 +08:00
1 parent 6de2e071be
commit c83c333e73
12 files changed
+634 -158

No files matched your search

+13 -41
View File
@@ -93,16 +93,18 @@ describe('element-builder / commonElem.businessType per scene', () => {
});
});
describe('element-builder / group file element wire shape', () => {
// Regression for the same `result=79` class: the GroupFileExtra outer
// wrapper was missing the magic `field1=6` + `fileName` slots and the
// inner GroupFileInfo had fileSha/extInfoString/fileMd5 shifted one
// tag to the left (5/6/7 instead of the correct 6/7/8). Both
// mistakes made the current QQ-NT server reject the chat post. This
// test decodes the element back through the proton-generated codec
// and asserts each field lands at the right tag.
it('encodes outer field1=6 + fileName, and inner fields at tags 6/7/8', async () => {
const [elem] = await buildSendElems(
describe('element-builder / file element is no longer carried in elems[]', () => {
// Regression for the `result=79` class: previously the element-builder
// emitted a `transElem(elemType=24, ...)` for `{type:'file'}` segments
// and the QQ-NT server rejected the outgoing PbSendMsg with that wire
// shape. The fix moves group-file publishing onto a dedicated OIDB
// call (`OidbSvcTrpcTcp.0x6d9_4`), driven from the OneBot layer in
// `modules/message-actions.ts::sendGroupMessage` after the file
// segment is split off. The element-builder therefore must NOT emit
// any element for `{type:'file'}` anymore — if it does, the message
// ships with a transElem(24) payload and result=79 returns.
it('produces an empty elems[] for a {type:"file"} segment (must be split out at OneBot layer)', async () => {
const result = await buildSendElems(
[{
type: 'file',
fileId: 'fid-abc',
@@ -113,36 +115,6 @@ describe('element-builder / group file element wire shape', () => {
} as any],
{ bridge: fakeBridge, groupId: 12345 },
);
const transElem = (elem as any).transElem as { elemType: number; elemValue: Uint8Array };
expect(transElem.elemType).toBe(24);
// 0x01 prefix + BE16 length + payload
expect(transElem.elemValue[0]).toBe(0x01);
const len = (transElem.elemValue[1] << 8) | transElem.elemValue[2];
const payload = transElem.elemValue.subarray(3, 3 + len);
// Hand-walk the wire bytes to verify each tag lands where the
// server expects. Each varint tag = (field << 3) | wire_type:
// outer field1=6 → tag 8 (wire 0 / varint), value 6
// outer fileName → tag 18 (wire 2 / length-delimited), 'doc.txt'
// outer inner → tag 58 (field 7 wire 2)
// inner.info → tag 18 (field 2 wire 2)
// info.busId → tag 8 (field 1 wire 0), value 102
// info.fileId → tag 18 (field 2 wire 2)
// info.fileSize → tag 24 (field 3 wire 0), value 123
// info.fileName → tag 34 (field 4 wire 2)
// info.fileSha → tag 50 (field 6 wire 2) ← was 42 (field 5)
// info.extInfoString → tag 58 (field 7 wire 2) ← was 50 (field 6)
// info.fileMd5 → tag 66 (field 8 wire 2) ← was 58 (field 7)
const tagAt = (i: number) => payload[i];
expect(tagAt(0)).toBe(8); // outer field1 tag — regression: missing entirely before
expect(payload[1]).toBe(6); // value of field1 (NapCat hardcodes 6)
expect(tagAt(2)).toBe(18); // outer fileName tag — regression: missing
// Locate the inner GroupFileExtraInfo by scanning for tag 50 (was 42
// in the bug). A naive scan for `0x32` is enough because no string
// field happens to contain that byte in this test fixture.
expect(payload.includes(50)).toBe(true); // fileSha at tag 50 (field 6)
expect(payload.includes(58)).toBe(true); // extInfoString at tag 58 (field 7)
expect(payload.includes(66)).toBe(true); // fileMd5 at tag 66 (field 8)
expect(payload.includes(42)).toBe(false); // sanity: nothing at the old (wrong) tag for fileSha
expect(result).toEqual([]);
});
});