refactor(onebot): inline ctx.bridge.apis.groupFile direct calls
Remove 6 passthrough fields from ApiActionContext for the group-file area (`uploadGroupFile / uploadPrivateFile / getGroupFileUrl / createGroupFileFolder / getPrivateFileUrl / getGroupFileCount`). Action sites (`actions/group-file.ts` and one site in `actions/extended.ts`) now call `ctx.bridge.apis.groupFile.<method>` directly. `getGroupFiles` stays on the ctx because its module helper (`getGroupFiles(bridge, groupId, folderId)` in `modules/contact-actions.ts`) does identity-lookup enrichment of uploader/creator names — not a pure passthrough. Behavior preserved: same default values (`name = ''`, `folderId = '/'`, `busId = 102`, `uploadFile = true`) — they were baked into the ctx wrapper before, now they're explicit in the action site (`asString` returns `''`, `... || '/'`, `... || 102`, `asBoolean(..., true)`). The result-unwrap (`fileId` extraction from `UploadFileResult`) moves from the ctx wrapper into the action handler. Part 2 of the OneBot-side slim-down. 552/552 tests still green.
This commit is contained in:
4 files changed
+18
-38
No files matched your search
@@ -573,18 +573,10 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
h.registerAction('get_group_file_system_info', async (params) => {
|
||||
const groupId = asNumber(params.group_id);
|
||||
if (!groupId) return failedResponse(RETCODE.BAD_REQUEST, 'group_id is required');
|
||||
if (ctx.getGroupFileCount) {
|
||||
const info = await ctx.getGroupFileCount(groupId);
|
||||
return okResponse({
|
||||
file_count: info.fileCount,
|
||||
limit_count: info.maxCount,
|
||||
used_space: 0,
|
||||
total_space: 10737418240,
|
||||
});
|
||||
}
|
||||
const info = await ctx.bridge.apis.groupFile.getCount(groupId);
|
||||
return okResponse({
|
||||
file_count: 0,
|
||||
limit_count: 10000,
|
||||
file_count: info.fileCount,
|
||||
limit_count: info.maxCount,
|
||||
used_space: 0,
|
||||
total_space: 10737418240,
|
||||
});
|
||||
|
||||
@@ -11,8 +11,8 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const folderId = asString(params.folder) || asString(params.folder_id) || '/';
|
||||
const uploadFile = asBoolean(params.upload_file, true);
|
||||
if (!groupId || !file) return failedResponse(RETCODE.BAD_REQUEST, 'group_id and file are required');
|
||||
const fileId = await ctx.uploadGroupFile(groupId, file, name, folderId, uploadFile);
|
||||
return okResponse({ file_id: fileId });
|
||||
const result = await ctx.bridge.apis.groupFile.upload(groupId, file, name, folderId, uploadFile);
|
||||
return okResponse({ file_id: result.fileId });
|
||||
});
|
||||
|
||||
h.registerAction('upload_private_file', async (params) => {
|
||||
@@ -21,8 +21,8 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const name = asString(params.name);
|
||||
const uploadFile = asBoolean(params.upload_file, true);
|
||||
if (!userId || !file) return failedResponse(RETCODE.BAD_REQUEST, 'user_id and file are required');
|
||||
const fileId = await ctx.uploadPrivateFile(userId, file, name, uploadFile);
|
||||
return okResponse({ file_id: fileId });
|
||||
const result = await ctx.bridge.apis.groupFile.uploadPrivate(userId, file, name, uploadFile);
|
||||
return okResponse({ file_id: result.fileId });
|
||||
});
|
||||
|
||||
h.registerAction('get_group_file_url', async (params) => {
|
||||
@@ -32,7 +32,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
if (!groupId || !fileId) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'group_id and file_id are required');
|
||||
}
|
||||
return okResponse({ url: await ctx.getGroupFileUrl(groupId, fileId, busId) });
|
||||
return okResponse({ url: await ctx.bridge.apis.groupFile.getUrl(groupId, fileId, busId) });
|
||||
});
|
||||
|
||||
h.registerAction('get_group_root_files', async (params) => {
|
||||
@@ -81,7 +81,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
if (!groupId || !name) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'group_id and name are required');
|
||||
}
|
||||
await ctx.createGroupFileFolder(groupId, name, parentId);
|
||||
await ctx.bridge.apis.groupFile.createFolder(groupId, name, parentId);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
@@ -113,6 +113,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
if (!userId || !fileId || !fileHash) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'user_id, file_id and file_hash are required');
|
||||
}
|
||||
return okResponse({ url: await ctx.getPrivateFileUrl(userId, fileId, fileHash) });
|
||||
return okResponse({ url: await ctx.bridge.apis.groupFile.getPrivateUrl(userId, fileId, fileHash) });
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user