fix(onebot): get_group_files_by_folder 不再丢弃子文件夹 (#2095)
该接口的 returnSchema 声明了 folders(文件夹列表),actionDescription 也写着「获取指定群文件夹下的文件及子文件夹列表」,但 _handle 把 folders 硬编码成空数组。 它调用的 MsgApi.getGroupFileList 与 get_group_root_files 相同,返回项 既可能带 fileInfo 也可能带 folderInfo;兄弟实现 GetGroupRootFiles 把 两类都映射了出来。后果是进入某个子目录后无法继续往下遍历,调用方永远 只能拿到空的 folders。 改为按兄弟接口的方式映射 folderInfo。
This commit is contained in:
@@ -43,7 +43,8 @@ export class GetGroupFilesByFolder extends OneBotAction<PayloadType, ReturnType>
|
||||
return {
|
||||
files: ret.filter(item => item.fileInfo)
|
||||
.map(item => OB11Construct.file(item.peerId, item.fileInfo!)),
|
||||
folders: [],
|
||||
folders: ret.filter(item => item.folderInfo)
|
||||
.map(item => OB11Construct.folder(item.peerId, item.folderInfo!)),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
// StreamBasic must be evaluated before OneBotAction: the two modules import each other,
|
||||
// and loading OneBotAction first leaves BasicStream extending an uninitialized binding.
|
||||
import '../napcat-onebot/action/stream/StreamBasic';
|
||||
import { describe, expect, test, vi } from 'vitest';
|
||||
import { GetGroupFilesByFolder } from '../napcat-onebot/action/go-cqhttp/GetGroupFilesByFolder';
|
||||
|
||||
const FOLDER_ITEM = {
|
||||
peerId: '123',
|
||||
folderInfo: {
|
||||
folderId: 'sub_folder_1',
|
||||
folderName: '子目录',
|
||||
createTime: 1,
|
||||
createUin: '9',
|
||||
creatorName: '创建者',
|
||||
totalFileCount: 2,
|
||||
modifyTime: 2,
|
||||
modifyUin: '9',
|
||||
modifyName: '修改者',
|
||||
},
|
||||
};
|
||||
|
||||
function createAction (items: unknown[]) {
|
||||
const getGroupFileList = vi.fn().mockResolvedValue(items);
|
||||
const action = new GetGroupFilesByFolder(
|
||||
undefined as never,
|
||||
{
|
||||
apis: {
|
||||
MsgApi: { getGroupFileList },
|
||||
},
|
||||
} as never
|
||||
);
|
||||
return { action, getGroupFileList };
|
||||
}
|
||||
|
||||
describe('get_group_files_by_folder subfolders', () => {
|
||||
test('maps folderInfo entries into folders', async () => {
|
||||
const { action } = createAction([FOLDER_ITEM]);
|
||||
|
||||
const res = await action._handle({ group_id: '123', file_count: 50 });
|
||||
|
||||
expect(res.folders).toHaveLength(1);
|
||||
expect(res.folders[0]).toMatchObject({
|
||||
group_id: 123,
|
||||
folder_id: 'sub_folder_1',
|
||||
folder_name: '子目录',
|
||||
total_file_count: 2,
|
||||
});
|
||||
expect(res.files).toHaveLength(0);
|
||||
});
|
||||
|
||||
test('returns empty arrays when the folder holds nothing', async () => {
|
||||
const { action } = createAction([]);
|
||||
|
||||
const res = await action._handle({ group_id: '123', file_count: 50 });
|
||||
|
||||
expect(res.files).toHaveLength(0);
|
||||
expect(res.folders).toHaveLength(0);
|
||||
});
|
||||
|
||||
test('passes the requested folder id through to the core API', async () => {
|
||||
const { action, getGroupFileList } = createAction([]);
|
||||
|
||||
await action._handle({ group_id: '123', file_count: 50, folder_id: 'parent_1' });
|
||||
|
||||
expect(getGroupFileList).toHaveBeenCalledWith('123', expect.objectContaining({ folderId: 'parent_1' }));
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user