fix(protocol): get_group_file_system_info returns real counts + space (#196)

file_count 恒为 0(且 used_space/limit_count/total_space 是占位/写死值)。根因:
0x6D8 view 命令分三个 subcommand(1=List, 2=Count, 3=Space),但 getCount 错发到
**subCommand 3(Space)** 且 busId=0,并从 pb<1>/pb<2> 读计数——服务端根本没返回
Count 块,于是恒 0。

真机 RE(bot 在测试群传/删文件核对):
- Count 走 **0x6D8_2 + busId=6**,响应 Count 块里 fileCount=**field 4**、maxCount(文件
  数上限,如 1500)=**field 6**(旧 pb<1>/pb<2> 全落空)。
- Space 走 **0x6D8_3**,响应 Space 块 totalSpace=**field 4**、usedSpace=**field 5**(64 位)。
- 实测:fileCount=4、limitCount=1500、usedSpace=20103729、totalSpace=10737418240。

修复:改 GetGroupFileCount 到 subCommand 2 + busId 6 + 正确 tag;新增 GetGroupFileSpace
(0x6D8_3);action 并发查两者,四个字段全返回**服务端实际值**(优于 NapCat 的写死占位)。
含 count/space 编解码回归测试。catalog regen。

typecheck 12 包;protocol 591 / onebot 521 / core 472 全绿。
This commit is contained in:
DrSmoothl
2026-07-04 01:59:52 +08:00
parent 95b5878456
commit c027161a64
9 changed files with 146 additions and 32 deletions
@@ -12,6 +12,7 @@ import { CreateGroupFolder } from '@snowluma/protocol/oidb-services/group-file/c
import { DeleteGroupFile } from '@snowluma/protocol/oidb-services/group-file/delete-group-file';
import { DeleteGroupFolder } from '@snowluma/protocol/oidb-services/group-file/delete-group-folder';
import { GetGroupFileCount } from '@snowluma/protocol/oidb-services/group-file/get-group-file-count';
import { GetGroupFileSpace } from '@snowluma/protocol/oidb-services/group-file/get-group-file-space';
import { GetGroupFileUrl } from '@snowluma/protocol/oidb-services/group-file/get-group-file-url';
import { GetGroupPttUrl } from '@snowluma/protocol/oidb-services/group-file/get-group-ptt-url';
import { GetGroupVideoUrl } from '@snowluma/protocol/oidb-services/group-file/get-group-video-url';
@@ -250,6 +251,10 @@ export class GroupFileApi {
return GetGroupFileCount.invoke(this.ctx, { groupId });
}
getSpace(groupId: number): Promise<{ usedSpace: number; totalSpace: number }> {
return GetGroupFileSpace.invoke(this.ctx, { groupId });
}
// ─────────────── upload (3-stage: OIDB preflight → highway → publish) ───────────────
async upload(
+4 -4
View File
@@ -3276,7 +3276,7 @@
"name": "get_group_file_system_info",
"aliases": [],
"summary": "获取群文件系统信息",
"returns": "{ file_count, limit_count, used_space, total_space }:群文件数量与容量信息(used_space 恒 0,total_space 为固定 10GiB 常量)。",
"returns": "{ file_count, limit_count, used_space, total_space }:群文件数量与容量信息(均为服务端实际值)。",
"returnsSchema": {
"type": "object",
"properties": {
@@ -3286,15 +3286,15 @@
},
"limit_count": {
"type": "integer",
"description": "最大文件数"
"description": "文件数上限"
},
"used_space": {
"type": "integer",
"description": "已用空间(占位,恒 0)"
"description": "已用空间(字节)"
},
"total_space": {
"type": "integer",
"description": "总空间(占位,恒 10GiB)"
"description": "总空间(字节)"
}
},
"required": [
+4 -4
View File
@@ -3279,7 +3279,7 @@ export const ACTIONS: CatalogAction[] = [
"name": "get_group_file_system_info",
"aliases": [],
"summary": "获取群文件系统信息",
"returns": "{ file_count, limit_count, used_space, total_space }:群文件数量与容量信息(used_space 恒 0,total_space 为固定 10GiB 常量)。",
"returns": "{ file_count, limit_count, used_space, total_space }:群文件数量与容量信息(均为服务端实际值)。",
"returnsSchema": {
"type": "object",
"properties": {
@@ -3289,15 +3289,15 @@ export const ACTIONS: CatalogAction[] = [
},
"limit_count": {
"type": "integer",
"description": "最大文件数"
"description": "文件数上限"
},
"used_space": {
"type": "integer",
"description": "已用空间(占位,恒 0)"
"description": "已用空间(字节)"
},
"total_space": {
"type": "integer",
"description": "总空间(占位,恒 10GiB)"
"description": "总空间(字节)"
}
},
"required": [
+13 -9
View File
@@ -706,24 +706,28 @@ export const actions = [
name: 'get_group_file_system_info',
summary: '获取群文件系统信息',
readOnly: true,
returns: '{ file_count, limit_count, used_space, total_space }:群文件数量与容量信息(used_space 恒 0,total_space 为固定 10GiB 常量)。',
returns: '{ file_count, limit_count, used_space, total_space }:群文件数量与容量信息(均为服务端实际值)。',
returnsSchema: {
type: 'object',
properties: {
file_count: { type: 'integer', description: '当前文件数' },
limit_count: { type: 'integer', description: '最大文件数' },
used_space: { type: 'integer', description: '已用空间(占位,恒 0)' },
total_space: { type: 'integer', description: '总空间(占位,恒 10GiB)' },
limit_count: { type: 'integer', description: '文件数上限' },
used_space: { type: 'integer', description: '已用空间(字节)' },
total_space: { type: 'integer', description: '总空间(字节)' },
},
required: ['file_count', 'limit_count', 'used_space', 'total_space'],
},
run: async (p, ctx) => {
const info = await ctx.bridge.apis.groupFile.getCount(p.group_id);
// 0x6D8 count (subcmd 2) + space (subcmd 3) are separate queries (#196).
const [count, space] = await Promise.all([
ctx.bridge.apis.groupFile.getCount(p.group_id),
ctx.bridge.apis.groupFile.getSpace(p.group_id),
]);
return okResponse({
file_count: info.fileCount,
limit_count: info.maxCount,
used_space: 0,
total_space: 10737418240,
file_count: count.fileCount,
limit_count: count.maxCount,
used_space: space.usedSpace,
total_space: space.totalSpace,
});
},
}),
@@ -213,14 +213,30 @@ export interface OidbGroupFileCountReq {
appId?: pb<2, uint_32>;
busId?: pb<3, uint_32>;
}
// Count response (0x6D8_2): fileCount is field 4 and maxCount (the group's file
// ceiling, e.g. 1500) field 6 — RE'd from a live count query (#196). The old
// pb<1>/pb<2> tags matched nothing, so file_count always decoded to 0.
export interface OidbGroupFileCountResp {
fileCount?: pb<1, uint_32>;
maxCount?: pb<2, uint_32>;
isEnd?: pb<3, bool>;
fileCount?: pb<4, uint_32>;
maxCount?: pb<6, uint_32>;
isFull?: pb<7, bool>;
}
// Space request/response (0x6D8_3). Both values are 64-bit — the 10 GiB ceiling
// already exceeds uint32.
export interface OidbGroupFileSpaceReq {
groupUin?: pb<1, uint_32>;
appId?: pb<2, uint_32>;
}
export interface OidbGroupFileSpaceResp {
totalSpace?: pb<4, uint_64>;
usedSpace?: pb<5, uint_64>;
}
// count → subCommand 2, space → subCommand 3 (List is subCommand 1).
export interface OidbGroupFileCountViewReq {
count?: pb<3, OidbGroupFileCountReq>;
space?: pb<4, OidbGroupFileSpaceReq>;
}
export interface OidbGroupFileCountViewResp {
count?: pb<3, OidbGroupFileCountResp>;
space?: pb<4, OidbGroupFileSpaceResp>;
}
@@ -1,7 +1,8 @@
// 0x6D8_3 — fetch group file slot usage. Returns the current count
// alongside the server-side ceiling (NTQQ's `maxCount` default is
// 10000; we surface that fallback so the OneBot action can render
// the gauge without a second call when the server elides the field).
// 0x6D8_2 — fetch the group file slot count. The 0x6D8 view command splits
// into three subcommands: 1=List, 2=Count, 3=Space (see GetGroupFileSpace).
// This was previously mis-wired to subCommand 3 (Space) with busId=0, so the
// Count block was never returned and file_count always came back 0 (#196).
// The count request needs busId=6.
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
@@ -17,13 +18,13 @@ export interface GroupFileCount {
export namespace GetGroupFileCount {
export const command = 0x6D8;
export const subCommand = 3;
export const subCommand = 2;
export interface Params { groupId: number; }
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): OidbGroupFileCountViewReq => ({
count: { groupUin: p.groupId, appId: 7, busId: 0 },
count: { groupUin: p.groupId, appId: 7, busId: 6 },
});
export const deserialize = (_ctx: Deps, body: OidbGroupFileCountViewResp): GroupFileCount => ({
@@ -0,0 +1,42 @@
// 0x6D8_3 — fetch the group file space usage (used / total bytes). Sibling of
// GetGroupFileCount (0x6D8_2): the 0x6D8 view command's subCommand 3 = Space.
// RE'd from a live query (#196) — the response carries a Space block at field 4
// with totalSpace at field 4 and usedSpace at field 5 (both 64-bit).
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
OidbGroupFileCountViewReq, OidbGroupFileCountViewResp,
} from '@snowluma/proto-defs/oidb-actions/group-file';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export interface GroupFileSpace {
usedSpace: number;
totalSpace: number;
}
export namespace GetGroupFileSpace {
export const command = 0x6D8;
export const subCommand = 3;
export interface Params { groupId: number; }
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): OidbGroupFileCountViewReq => ({
space: { groupUin: p.groupId, appId: 7 },
});
export const deserialize = (_ctx: Deps, body: OidbGroupFileCountViewResp): GroupFileSpace => ({
usedSpace: Number(body.space?.usedSpace ?? 0),
totalSpace: Number(body.space?.totalSpace ?? 0),
});
export const encode = (env: OidbBase<OidbGroupFileCountViewReq>): Uint8Array =>
protobuf_encode<OidbBase<OidbGroupFileCountViewReq>>(env);
export const decode = (bytes: Uint8Array): OidbBase<OidbGroupFileCountViewResp> =>
protobuf_decode<OidbBase<OidbGroupFileCountViewResp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<GroupFileSpace> =>
invokeOidb(deps, GetGroupFileSpace, params);
}
@@ -17,21 +17,21 @@ function makeDeps(body?: OidbGroupFileCountViewResp) {
}
describe('GetGroupFileCount namespace', () => {
it('declares 0x6D8_3', () => {
it('declares 0x6D8_2 (Count subcommand)', () => {
expect(GetGroupFileCount.command).toBe(0x6D8);
expect(GetGroupFileCount.subCommand).toBe(3);
expect(GetGroupFileCount.subCommand).toBe(2);
});
it('routes to 0x6d8_3 with groupUin + appId=7 + busId=0', async () => {
it('routes to 0x6d8_2 with groupUin + appId=7 + busId=6 (#196)', async () => {
const deps = makeDeps({ count: { fileCount: 1, maxCount: 100 } });
await GetGroupFileCount.invoke(deps, { groupId: 12345 });
const [wire, bytes] = deps.sendRawPacket.mock.calls[0]!;
expect(wire).toBe('OidbSvcTrpcTcp.0x6d8_3');
expect(wire).toBe('OidbSvcTrpcTcp.0x6d8_2');
const env = protobuf_decode<OidbBase<OidbGroupFileCountViewReq>>(bytes);
expect(env.body?.count).toMatchObject({ groupUin: 12345, appId: 7 });
expect(env.body?.count).toMatchObject({ groupUin: 12345, appId: 7, busId: 6 });
});
it('decodes both counters as plain numbers', async () => {
it('decodes fileCount (field 4) + maxCount (field 6) as plain numbers', async () => {
const deps = makeDeps({ count: { fileCount: 42, maxCount: 1000 } });
const out = await GetGroupFileCount.invoke(deps, { groupId: 1 });
expect(out).toEqual({ fileCount: 42, maxCount: 1000 });
@@ -0,0 +1,46 @@
import { describe, expect, it, vi } from 'vitest';
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
OidbGroupFileCountViewReq, OidbGroupFileCountViewResp,
} from '@snowluma/proto-defs/oidb-actions/group-file';
import type { SendPacketResult } from '@snowluma/common/packet-sender';
import { GetGroupFileSpace } from '../../../src/oidb-services/group-file/get-group-file-space';
function makeDeps(body?: OidbGroupFileCountViewResp) {
const responseData = body !== undefined
? Buffer.from(protobuf_encode<OidbBase<OidbGroupFileCountViewResp>>({ body }))
: Buffer.alloc(0);
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData };
return { sendRawPacket: vi.fn(async () => r) };
}
describe('GetGroupFileSpace namespace (#196)', () => {
it('declares 0x6D8_3 (Space subcommand)', () => {
expect(GetGroupFileSpace.command).toBe(0x6D8);
expect(GetGroupFileSpace.subCommand).toBe(3);
});
it('routes to 0x6d8_3 with a space request (groupUin + appId=7)', async () => {
const deps = makeDeps({ space: {} });
await GetGroupFileSpace.invoke(deps, { groupId: 12345 });
const [wire, bytes] = deps.sendRawPacket.mock.calls[0]!;
expect(wire).toBe('OidbSvcTrpcTcp.0x6d8_3');
const env = protobuf_decode<OidbBase<OidbGroupFileCountViewReq>>(bytes);
expect(env.body?.space).toMatchObject({ groupUin: 12345, appId: 7 });
expect(env.body?.count).toBeNull();
});
it('decodes usedSpace (field 5) + totalSpace (field 4) as plain numbers', async () => {
const deps = makeDeps({ space: { usedSpace: 20103729n, totalSpace: 10737418240n } });
const out = await GetGroupFileSpace.invoke(deps, { groupId: 1 });
expect(out).toEqual({ usedSpace: 20103729, totalSpace: 10737418240 });
});
it('defaults to 0 when the server elides the space block', async () => {
const deps = makeDeps({ space: {} });
const out = await GetGroupFileSpace.invoke(deps, { groupId: 1 });
expect(out).toEqual({ usedSpace: 0, totalSpace: 0 });
});
});