feat(onebot): expose group folder upload metadata
Decode the folder modifier metadata returned by group file listings and project it as last upload time, uploader ID, and uploader name for both folder listing actions. Regenerate the MCP catalog and add protocol, bridge, OneBot projection, and action schema coverage for the new fields. Closes #248
This commit is contained in:
10 files changed
+208
-4
No files matched your search
@@ -58,6 +58,9 @@ export interface GroupFolderInfo {
|
|||||||
creator: number;
|
creator: number;
|
||||||
creatorName: string;
|
creatorName: string;
|
||||||
totalFileCount: number;
|
totalFileCount: number;
|
||||||
|
lastUploadTime: number;
|
||||||
|
lastUploader: number;
|
||||||
|
lastUploaderName: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GroupFilesResult {
|
export interface GroupFilesResult {
|
||||||
@@ -592,6 +595,8 @@ export class GroupFileApi {
|
|||||||
const folder = item.folderInfo;
|
const folder = item.folderInfo;
|
||||||
const creator = toInt(folder.creatorUin);
|
const creator = toInt(folder.creatorUin);
|
||||||
const cached = this.ctx.identity.findGroupMember(groupId, creator);
|
const cached = this.ctx.identity.findGroupMember(groupId, creator);
|
||||||
|
const lastUploader = toInt(folder.modifierUin);
|
||||||
|
const lastUploaderCached = this.ctx.identity.findGroupMember(groupId, lastUploader);
|
||||||
folders.push({
|
folders.push({
|
||||||
folderId: typeof folder.folderId === 'string' ? folder.folderId : '',
|
folderId: typeof folder.folderId === 'string' ? folder.folderId : '',
|
||||||
folderName: typeof folder.folderName === 'string' ? folder.folderName : '',
|
folderName: typeof folder.folderName === 'string' ? folder.folderName : '',
|
||||||
@@ -602,6 +607,12 @@ export class GroupFileApi {
|
|||||||
|| cached?.nickname
|
|| cached?.nickname
|
||||||
|| '',
|
|| '',
|
||||||
totalFileCount: toInt(folder.totalFileCount),
|
totalFileCount: toInt(folder.totalFileCount),
|
||||||
|
lastUploadTime: toInt(folder.modifiedTime),
|
||||||
|
lastUploader,
|
||||||
|
lastUploaderName: (typeof folder.modifierName === 'string' && folder.modifierName)
|
||||||
|
|| lastUploaderCached?.card
|
||||||
|
|| lastUploaderCached?.nickname
|
||||||
|
|| '',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -503,7 +503,18 @@ describe('apis/group-file', () => {
|
|||||||
isEnd: true,
|
isEnd: true,
|
||||||
items: [
|
items: [
|
||||||
{ type: 1, fileInfo: { fileId: 'f1', fileName: 'a.txt', uploaderUin: 1, uploaderName: 'alice' } },
|
{ type: 1, fileInfo: { fileId: 'f1', fileName: 'a.txt', uploaderUin: 1, uploaderName: 'alice' } },
|
||||||
{ type: 2, folderInfo: { folderId: 'd1', folderName: 'dir', creatorUin: 2, creatorName: 'bob' } },
|
{
|
||||||
|
type: 2,
|
||||||
|
folderInfo: {
|
||||||
|
folderId: 'd1',
|
||||||
|
folderName: 'dir',
|
||||||
|
creatorUin: 2,
|
||||||
|
creatorName: 'bob',
|
||||||
|
modifiedTime: 200,
|
||||||
|
modifierUin: 5_000_000_001n,
|
||||||
|
modifierName: 'alice',
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
} as any,
|
} as any,
|
||||||
},
|
},
|
||||||
@@ -513,7 +524,15 @@ describe('apis/group-file', () => {
|
|||||||
expect(out.files).toHaveLength(1);
|
expect(out.files).toHaveLength(1);
|
||||||
expect(out.files[0]).toMatchObject({ fileId: 'f1', fileName: 'a.txt', uploader: 1, uploaderName: 'alice' });
|
expect(out.files[0]).toMatchObject({ fileId: 'f1', fileName: 'a.txt', uploader: 1, uploaderName: 'alice' });
|
||||||
expect(out.folders).toHaveLength(1);
|
expect(out.folders).toHaveLength(1);
|
||||||
expect(out.folders[0]).toMatchObject({ folderId: 'd1', folderName: 'dir', creator: 2, creatorName: 'bob' });
|
expect(out.folders[0]).toMatchObject({
|
||||||
|
folderId: 'd1',
|
||||||
|
folderName: 'dir',
|
||||||
|
creator: 2,
|
||||||
|
creatorName: 'bob',
|
||||||
|
lastUploadTime: 200,
|
||||||
|
lastUploader: 5_000_000_001,
|
||||||
|
lastUploaderName: 'alice',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('getUrl builds the https URL from downloadDns + hex-encoded path', async () => {
|
it('getUrl builds the https URL from downloadDns + hex-encoded path', async () => {
|
||||||
|
|||||||
@@ -3660,6 +3660,18 @@
|
|||||||
"total_file_count": {
|
"total_file_count": {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"description": "文件夹内文件总数"
|
"description": "文件夹内文件总数"
|
||||||
|
},
|
||||||
|
"last_upload_time": {
|
||||||
|
"type": "integer",
|
||||||
|
"description": "最后上传时间戳"
|
||||||
|
},
|
||||||
|
"last_uploader": {
|
||||||
|
"type": "integer",
|
||||||
|
"description": "最后上传者 QQ 号"
|
||||||
|
},
|
||||||
|
"last_uploader_name": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "最后上传者昵称"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4590,6 +4602,18 @@
|
|||||||
"total_file_count": {
|
"total_file_count": {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"description": "文件夹内文件总数"
|
"description": "文件夹内文件总数"
|
||||||
|
},
|
||||||
|
"last_upload_time": {
|
||||||
|
"type": "integer",
|
||||||
|
"description": "最后上传时间戳"
|
||||||
|
},
|
||||||
|
"last_uploader": {
|
||||||
|
"type": "integer",
|
||||||
|
"description": "最后上传者 QQ 号"
|
||||||
|
},
|
||||||
|
"last_uploader_name": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "最后上传者昵称"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3663,6 +3663,18 @@ export const ACTIONS: CatalogAction[] = [
|
|||||||
"total_file_count": {
|
"total_file_count": {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"description": "文件夹内文件总数"
|
"description": "文件夹内文件总数"
|
||||||
|
},
|
||||||
|
"last_upload_time": {
|
||||||
|
"type": "integer",
|
||||||
|
"description": "最后上传时间戳"
|
||||||
|
},
|
||||||
|
"last_uploader": {
|
||||||
|
"type": "integer",
|
||||||
|
"description": "最后上传者 QQ 号"
|
||||||
|
},
|
||||||
|
"last_uploader_name": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "最后上传者昵称"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4593,6 +4605,18 @@ export const ACTIONS: CatalogAction[] = [
|
|||||||
"total_file_count": {
|
"total_file_count": {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"description": "文件夹内文件总数"
|
"description": "文件夹内文件总数"
|
||||||
|
},
|
||||||
|
"last_upload_time": {
|
||||||
|
"type": "integer",
|
||||||
|
"description": "最后上传时间戳"
|
||||||
|
},
|
||||||
|
"last_uploader": {
|
||||||
|
"type": "integer",
|
||||||
|
"description": "最后上传者 QQ 号"
|
||||||
|
},
|
||||||
|
"last_uploader_name": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "最后上传者昵称"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,6 +113,9 @@ export const actions = [
|
|||||||
creator: { type: 'integer', description: '创建者 QQ 号' },
|
creator: { type: 'integer', description: '创建者 QQ 号' },
|
||||||
create_name: { type: 'string', description: '创建者昵称' },
|
create_name: { type: 'string', description: '创建者昵称' },
|
||||||
total_file_count: { type: 'integer', description: '文件夹内文件总数' },
|
total_file_count: { type: 'integer', description: '文件夹内文件总数' },
|
||||||
|
last_upload_time: { type: 'integer', description: '最后上传时间戳' },
|
||||||
|
last_uploader: { type: 'integer', description: '最后上传者 QQ 号' },
|
||||||
|
last_uploader_name: { type: 'string', description: '最后上传者昵称' },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -165,6 +168,9 @@ export const actions = [
|
|||||||
creator: { type: 'integer', description: '创建者 QQ 号' },
|
creator: { type: 'integer', description: '创建者 QQ 号' },
|
||||||
create_name: { type: 'string', description: '创建者昵称' },
|
create_name: { type: 'string', description: '创建者昵称' },
|
||||||
total_file_count: { type: 'integer', description: '文件夹内文件总数' },
|
total_file_count: { type: 'integer', description: '文件夹内文件总数' },
|
||||||
|
last_upload_time: { type: 'integer', description: '最后上传时间戳' },
|
||||||
|
last_uploader: { type: 'integer', description: '最后上传者 QQ 号' },
|
||||||
|
last_uploader_name: { type: 'string', description: '最后上传者昵称' },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -290,4 +296,3 @@ export const actions = [
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -210,6 +210,9 @@ export async function getGroupFiles(
|
|||||||
creator: folder.creator,
|
creator: folder.creator,
|
||||||
create_name: folder.creatorName,
|
create_name: folder.creatorName,
|
||||||
total_file_count: folder.totalFileCount,
|
total_file_count: folder.totalFileCount,
|
||||||
|
last_upload_time: folder.lastUploadTime,
|
||||||
|
last_uploader: folder.lastUploader,
|
||||||
|
last_uploader_name: folder.lastUploaderName,
|
||||||
} as JsonObject)),
|
} as JsonObject)),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,21 @@ describe('action-docs', () => {
|
|||||||
expect(duration).toMatchObject({ type: 'int', required: false, default: 1800 });
|
expect(duration).toMatchObject({ type: 'int', required: false, default: 1800 });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it.each(['get_group_root_files', 'get_group_files_by_folder'])(
|
||||||
|
'documents folder last-upload metadata for %s',
|
||||||
|
(name) => {
|
||||||
|
const action = docs.find((d) => d.name === name);
|
||||||
|
const properties = action?.returnsSchema?.properties as Record<string, any> | undefined;
|
||||||
|
const folderProperties = properties?.folders?.items?.properties as Record<string, unknown> | undefined;
|
||||||
|
|
||||||
|
expect(folderProperties).toEqual(expect.objectContaining({
|
||||||
|
last_upload_time: expect.objectContaining({ type: 'integer' }),
|
||||||
|
last_uploader: expect.objectContaining({ type: 'integer' }),
|
||||||
|
last_uploader_name: expect.objectContaining({ type: 'string' }),
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
it('renders markdown with header + an action section', () => {
|
it('renders markdown with header + an action section', () => {
|
||||||
const md = renderActionDocsMarkdown(docs);
|
const md = renderActionDocsMarkdown(docs);
|
||||||
expect(md).toContain('# OneBot Actions');
|
expect(md).toContain('# OneBot Actions');
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import type {
|
|||||||
import {
|
import {
|
||||||
getFriendList,
|
getFriendList,
|
||||||
getGroupInfo,
|
getGroupInfo,
|
||||||
|
getGroupFiles,
|
||||||
getGroupList,
|
getGroupList,
|
||||||
getGroupMemberInfo,
|
getGroupMemberInfo,
|
||||||
getGroupMemberList,
|
getGroupMemberList,
|
||||||
@@ -164,6 +165,35 @@ describe('onebot/contact-actions / getFriendList', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('onebot/contact-actions / getGroupFiles', () => {
|
||||||
|
it('returns folder last-upload metadata in OneBot field names', async () => {
|
||||||
|
const list = vi.fn(async () => ({
|
||||||
|
files: [],
|
||||||
|
folders: [{
|
||||||
|
folderId: 'd1',
|
||||||
|
folderName: 'dir',
|
||||||
|
createTime: 100,
|
||||||
|
creator: 123,
|
||||||
|
creatorName: 'creator',
|
||||||
|
totalFileCount: 2,
|
||||||
|
lastUploadTime: 200,
|
||||||
|
lastUploader: 5_000_000_001,
|
||||||
|
lastUploaderName: 'uploader',
|
||||||
|
}],
|
||||||
|
}));
|
||||||
|
const bridge = fakeBridge({ apis: { groupFile: { list } } });
|
||||||
|
|
||||||
|
const out = await getGroupFiles(bridge, 12345, '/');
|
||||||
|
|
||||||
|
expect(out.folders).toEqual([expect.objectContaining({
|
||||||
|
last_upload_time: 200,
|
||||||
|
last_uploader: 5_000_000_001,
|
||||||
|
last_uploader_name: 'uploader',
|
||||||
|
})]);
|
||||||
|
expect(list).toHaveBeenCalledWith(12345, '/');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('onebot/contact-actions / getGroupList', () => {
|
describe('onebot/contact-actions / getGroupList', () => {
|
||||||
it('triggers fetch when the in-memory roster is empty', async () => {
|
it('triggers fetch when the in-memory roster is empty', async () => {
|
||||||
const fetched = [makeGroup(100, 'Group A')];
|
const fetched = [makeGroup(100, 'Group A')];
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ export interface OidbGroupFileListFolderResp {
|
|||||||
creatorUin?: pb<6, uint_32>;
|
creatorUin?: pb<6, uint_32>;
|
||||||
creatorName?: pb<7, string>;
|
creatorName?: pb<7, string>;
|
||||||
totalFileCount?: pb<8, uint_32>;
|
totalFileCount?: pb<8, uint_32>;
|
||||||
|
modifierUin?: pb<9, uint_64>;
|
||||||
|
modifierName?: pb<10, string>;
|
||||||
}
|
}
|
||||||
export interface OidbGroupFileListFileResp {
|
export interface OidbGroupFileListFileResp {
|
||||||
fileId?: pb<1, string>;
|
fileId?: pb<1, string>;
|
||||||
@@ -239,4 +241,4 @@ export interface OidbGroupFileCountViewReq {
|
|||||||
export interface OidbGroupFileCountViewResp {
|
export interface OidbGroupFileCountViewResp {
|
||||||
count?: pb<3, OidbGroupFileCountResp>;
|
count?: pb<3, OidbGroupFileCountResp>;
|
||||||
space?: pb<4, OidbGroupFileSpaceResp>;
|
space?: pb<4, OidbGroupFileSpaceResp>;
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,37 @@ import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
|||||||
|
|
||||||
import { ListGroupFilesPage } from '../../../src/oidb-services/group-file/list-group-files-page';
|
import { ListGroupFilesPage } from '../../../src/oidb-services/group-file/list-group-files-page';
|
||||||
|
|
||||||
|
function wireVarint(value: bigint): number[] {
|
||||||
|
const out: number[] = [];
|
||||||
|
let remaining = value;
|
||||||
|
do {
|
||||||
|
const byte = Number(remaining & 0x7fn);
|
||||||
|
remaining >>= 7n;
|
||||||
|
out.push(remaining === 0n ? byte : byte | 0x80);
|
||||||
|
} while (remaining !== 0n);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
function varintField(fieldNumber: number, value: bigint): number[] {
|
||||||
|
return [...wireVarint(BigInt(fieldNumber << 3)), ...wireVarint(value)];
|
||||||
|
}
|
||||||
|
|
||||||
|
function bytesField(fieldNumber: number, value: Uint8Array): number[] {
|
||||||
|
return [
|
||||||
|
...wireVarint(BigInt((fieldNumber << 3) | 2)),
|
||||||
|
...wireVarint(BigInt(value.length)),
|
||||||
|
...value,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
function stringField(fieldNumber: number, value: string): number[] {
|
||||||
|
return bytesField(fieldNumber, new TextEncoder().encode(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
function messageField(fieldNumber: number, value: number[]): number[] {
|
||||||
|
return bytesField(fieldNumber, Uint8Array.from(value));
|
||||||
|
}
|
||||||
|
|
||||||
function makeDeps(body?: OidbGroupFileViewResp) {
|
function makeDeps(body?: OidbGroupFileViewResp) {
|
||||||
const responseData = body !== undefined
|
const responseData = body !== undefined
|
||||||
? Buffer.from(protobuf_encode<OidbBase<OidbGroupFileViewResp>>({ body }))
|
? Buffer.from(protobuf_encode<OidbBase<OidbGroupFileViewResp>>({ body }))
|
||||||
@@ -48,6 +79,46 @@ describe('ListGroupFilesPage namespace', () => {
|
|||||||
expect(out?.items).toHaveLength(1);
|
expect(out?.items).toHaveLength(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('decodes the folder last-upload metadata from the QQ wire fields', async () => {
|
||||||
|
// Independent wire fixture confirmed against QQ's group-file list decoder:
|
||||||
|
// folder fields 5/9/10 are modify time, modifier UIN, and modifier name.
|
||||||
|
const folder = [
|
||||||
|
...stringField(1, 'd1'),
|
||||||
|
...stringField(3, 'dir'),
|
||||||
|
...varintField(4, 100n),
|
||||||
|
...varintField(5, 200n),
|
||||||
|
...varintField(6, 123n),
|
||||||
|
...stringField(7, 'creator'),
|
||||||
|
...varintField(8, 2n),
|
||||||
|
...varintField(9, 5_000_000_001n),
|
||||||
|
...stringField(10, 'uploader'),
|
||||||
|
];
|
||||||
|
const item = [...varintField(1, 2n), ...messageField(2, folder)];
|
||||||
|
const list = [...varintField(4, 1n), ...messageField(5, item)];
|
||||||
|
const body = messageField(2, list);
|
||||||
|
const responseData = Buffer.from(messageField(4, body));
|
||||||
|
const deps = {
|
||||||
|
sendRawPacket: vi.fn(async (): Promise<SendPacketResult> => ({
|
||||||
|
success: true,
|
||||||
|
gotResponse: true,
|
||||||
|
errorCode: 0,
|
||||||
|
errorMessage: '',
|
||||||
|
responseData,
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
|
||||||
|
const out = await ListGroupFilesPage.invoke(deps, {
|
||||||
|
groupId: 1, targetDirectory: '/', startIndex: 0, pageSize: 10,
|
||||||
|
});
|
||||||
|
const decoded = out?.items?.[0]?.folderInfo as Record<string, unknown> | undefined;
|
||||||
|
|
||||||
|
expect(decoded).toMatchObject({
|
||||||
|
modifiedTime: 200,
|
||||||
|
modifierUin: 5_000_000_001n,
|
||||||
|
modifierName: 'uploader',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('returns null when the server elides the list slot', async () => {
|
it('returns null when the server elides the list slot', async () => {
|
||||||
const deps = makeDeps({});
|
const deps = makeDeps({});
|
||||||
const out = await ListGroupFilesPage.invoke(deps, {
|
const out = await ListGroupFilesPage.invoke(deps, {
|
||||||
|
|||||||
Reference in new issue
Block a user