refactor(api): move 17 group-file methods to GroupFileApi (#6 commit 4/13)
Inlines `actions/group-file.ts` into `apis/group-file.ts::GroupFileApi`,
deletes the old action file, removes the matching 17 facade methods
off `Bridge`, and slims `BridgeInterface` accordingly.
Method renaming follows the same "strip the redundant suffix" rule we
applied to GroupAdminApi:
uploadGroupFile → upload
uploadPrivateFile → uploadPrivate
sendGroupFileMessage → publish (OIDB 0x6d9_4)
fetchGroupFiles → list
fetchGroupFileCount → getCount
fetchGroupFileUrl → getUrl
fetchPrivateFileUrl → getPrivateUrl
fetchGroupPttUrlByNode → getPttUrl
fetchPrivatePttUrlByNode → getPrivatePttUrl
fetchGroupVideoUrlByNode → getVideoUrl
fetchPrivateVideoUrlByNode → getPrivateVideoUrl
deleteGroupFile → delete
moveGroupFile → move
createGroupFileFolder → createFolder
deleteGroupFileFolder → deleteFolder
renameGroupFileFolder → renameFolder
`upload`'s atomic upload+publish flow now calls `this.publish(...)`
directly instead of going through `bridge.sendGroupFileMessage`, and
`uploadPrivate` calls `this.ctx.apis.message.sendC2cFile(...)`.
Callers updated: `instance-context.ts`, `media-url-resolver.ts`,
`actions/group-file.ts` (onebot), `actions/extended.ts`,
`modules/{contact,media,message}-actions.ts`.
Tests: `group-file.test.ts` rewritten to use
`new GroupFileApi(bridge as any).method(...)`. The "verify publish was
called" assertions now use `vi.spyOn(api, 'publish').mockResolvedValue()`
since `publish` is an instance method on the same Api. `_helpers.ts`
gains `mockGroupFileApi()` for cross-Api callers and drops the flat
`sendGroupFileMessage` shim. `media-url-resolver.test.ts` and
`send-group-file.test.ts` switched to `bridge.apis.groupFile.*`; the
extended-actions `APIS_ROUTING` map now carries a `[area, newName]`
tuple so renamed methods auto-promote.
587/587 tests pass. The network-manager file remains as the only
failing test file (pre-existing infrastructure issue unrelated to #6).
This commit is contained in:
1 parent
0b91e4db8d
commit
dad501ebc0
17 files changed
+1241
-1185
No files matched your search
@@ -1142,7 +1142,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
if (!groupId || !folderId) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'group_id and folder_id are required');
|
||||
}
|
||||
await ctx.bridge.deleteGroupFileFolder(groupId, folderId);
|
||||
await ctx.bridge.apis.groupFile.deleteFolder(groupId, folderId);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
@@ -1215,7 +1215,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
}
|
||||
try {
|
||||
const node = await ctx.bridge.fetchAiVoice(groupId, character, text, chatType);
|
||||
const url = await ctx.bridge.fetchGroupPttUrlByNode(groupId, node);
|
||||
const url = await ctx.bridge.apis.groupFile.getPttUrl(groupId, node);
|
||||
return okResponse(url);
|
||||
} catch (err) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, err instanceof Error ? err.message : String(err));
|
||||
|
||||
@@ -58,7 +58,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
if (!groupId || !fileId) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'group_id and file_id are required');
|
||||
}
|
||||
await ctx.bridge.deleteGroupFile(groupId, fileId);
|
||||
await ctx.bridge.apis.groupFile.delete(groupId, fileId);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
@@ -70,7 +70,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
if (!groupId || !fileId || !parentDirectory || !targetDirectory) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'group_id, file_id, parent_directory and target_directory are required');
|
||||
}
|
||||
await ctx.bridge.moveGroupFile(groupId, fileId, parentDirectory, targetDirectory);
|
||||
await ctx.bridge.apis.groupFile.move(groupId, fileId, parentDirectory, targetDirectory);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
@@ -91,7 +91,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
if (!groupId || !folderId) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'group_id and folder_id are required');
|
||||
}
|
||||
await ctx.bridge.deleteGroupFileFolder(groupId, folderId);
|
||||
await ctx.bridge.apis.groupFile.deleteFolder(groupId, folderId);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
@@ -102,7 +102,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
if (!groupId || !folderId || !newName) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'group_id, folder_id and new_folder_name are required');
|
||||
}
|
||||
await ctx.bridge.renameGroupFileFolder(groupId, folderId, newName);
|
||||
await ctx.bridge.apis.groupFile.renameFolder(groupId, folderId, newName);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
|
||||
@@ -120,17 +120,17 @@ export function buildApiContext(ref: OneBotInstanceContext): ApiActionContext {
|
||||
|
||||
// Group file — fileId field extraction + defaults.
|
||||
uploadGroupFile: async (groupId, file, name, folderId, uploadFile) => {
|
||||
const result = await bridge.uploadGroupFile(groupId, file, name ?? '', folderId ?? '/', uploadFile ?? true);
|
||||
const result = await bridge.apis.groupFile.upload(groupId, file, name ?? '', folderId ?? '/', uploadFile ?? true);
|
||||
return result.fileId;
|
||||
},
|
||||
uploadPrivateFile: async (userId, file, name, uploadFile) => {
|
||||
const result = await bridge.uploadPrivateFile(userId, file, name ?? '', uploadFile ?? true);
|
||||
const result = await bridge.apis.groupFile.uploadPrivate(userId, file, name ?? '', uploadFile ?? true);
|
||||
return result.fileId;
|
||||
},
|
||||
getGroupFileUrl: (groupId, fileId, busId) => bridge.fetchGroupFileUrl(groupId, fileId, busId ?? 102),
|
||||
getGroupFileUrl: (groupId, fileId, busId) => bridge.apis.groupFile.getUrl(groupId, fileId, busId ?? 102),
|
||||
getGroupFiles: (groupId, folderId) => getGroupFiles(bridge, groupId, folderId),
|
||||
createGroupFileFolder: (groupId, name, parentId) => bridge.createGroupFileFolder(groupId, name, parentId ?? '/'),
|
||||
getPrivateFileUrl: (userId, fileId, fileHash) => bridge.fetchPrivateFileUrl(userId, fileId, fileHash),
|
||||
createGroupFileFolder: (groupId, name, parentId) => bridge.apis.groupFile.createFolder(groupId, name, parentId ?? '/'),
|
||||
getPrivateFileUrl: (userId, fileId, fileHash) => bridge.apis.groupFile.getPrivateUrl(userId, fileId, fileHash),
|
||||
|
||||
// Requests — name translation.
|
||||
handleFriendRequest: (flag, approve) => bridge.setFriendAddRequest(flag, approve),
|
||||
@@ -166,7 +166,7 @@ export function buildApiContext(ref: OneBotInstanceContext): ApiActionContext {
|
||||
setFriendRemark: (userId, remark) => bridge.setFriendRemark(userId, remark),
|
||||
setGroupRemark: (groupId, remark) => bridge.apis.groupAdmin.setRemark(groupId, remark),
|
||||
setGroupAvatar: (groupId, source) => bridge.setGroupAvatar(groupId, source),
|
||||
getGroupFileCount: (groupId) => bridge.fetchGroupFileCount(groupId),
|
||||
getGroupFileCount: (groupId) => bridge.apis.groupFile.getCount(groupId),
|
||||
|
||||
// Cross-store: looks up the meta then routes through Bridge.
|
||||
setMsgEmojiLike: async (messageId, emojiId, set) => {
|
||||
|
||||
@@ -26,9 +26,9 @@ export class MediaUrlResolver {
|
||||
private async populateUrl(element: MessageElement, isGroup: boolean, sessionId: number): Promise<void> {
|
||||
if (element.type === 'file' && element.fileId) {
|
||||
if (isGroup) {
|
||||
element.url = await this.bridge.fetchGroupFileUrl(sessionId, element.fileId);
|
||||
element.url = await this.bridge.apis.groupFile.getUrl(sessionId, element.fileId);
|
||||
} else if (element.fileHash) {
|
||||
element.url = await this.bridge.fetchPrivateFileUrl(sessionId, element.fileId, element.fileHash);
|
||||
element.url = await this.bridge.apis.groupFile.getPrivateUrl(sessionId, element.fileId, element.fileHash);
|
||||
} else {
|
||||
element.url = '';
|
||||
}
|
||||
@@ -38,12 +38,12 @@ export class MediaUrlResolver {
|
||||
if ((element.type === 'record' || element.type === 'video') && element.mediaNode) {
|
||||
if (isGroup) {
|
||||
element.url = element.type === 'record'
|
||||
? await this.bridge.fetchGroupPttUrlByNode(sessionId, element.mediaNode)
|
||||
: await this.bridge.fetchGroupVideoUrlByNode(sessionId, element.mediaNode);
|
||||
? await this.bridge.apis.groupFile.getPttUrl(sessionId, element.mediaNode)
|
||||
: await this.bridge.apis.groupFile.getVideoUrl(sessionId, element.mediaNode);
|
||||
} else {
|
||||
element.url = element.type === 'record'
|
||||
? await this.bridge.fetchPrivatePttUrlByNode(element.mediaNode)
|
||||
: await this.bridge.fetchPrivateVideoUrlByNode(element.mediaNode);
|
||||
? await this.bridge.apis.groupFile.getPrivatePttUrl(element.mediaNode)
|
||||
: await this.bridge.apis.groupFile.getPrivateVideoUrl(element.mediaNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ export async function getGroupFiles(
|
||||
groupId: number,
|
||||
folderId?: string,
|
||||
): Promise<JsonObject> {
|
||||
const result = await bridge.fetchGroupFiles(groupId, folderId ?? '/');
|
||||
const result = await bridge.apis.groupFile.list(groupId, folderId ?? '/');
|
||||
return {
|
||||
files: result.files.map((file) => ({
|
||||
group_id: groupId as any,
|
||||
|
||||
@@ -34,8 +34,8 @@ export async function getRecordInfo(
|
||||
if (!url && cached.mediaNode) {
|
||||
try {
|
||||
url = cached.isGroup
|
||||
? await bridge.fetchGroupPttUrlByNode(cached.sessionId, cached.mediaNode)
|
||||
: await bridge.fetchPrivatePttUrlByNode(cached.mediaNode);
|
||||
? await bridge.apis.groupFile.getPttUrl(cached.sessionId, cached.mediaNode)
|
||||
: await bridge.apis.groupFile.getPrivatePttUrl(cached.mediaNode);
|
||||
if (url) {
|
||||
mediaStore.updateRecordUrl(file, url);
|
||||
}
|
||||
|
||||
@@ -269,7 +269,7 @@ export async function sendGroupMessage(
|
||||
// wire. If this is the LAST element we still need a receipt so
|
||||
// the OneBot caller can cache the id; synthesise one from the
|
||||
// file_id hash + a fresh timestamp.
|
||||
await ref.bridge.sendGroupFileMessage(groupId, fileEl.fileId!);
|
||||
await ref.bridge.apis.groupFile.publish(groupId, fileEl.fileId!);
|
||||
logSentMessage(true, groupId, [fileEl]);
|
||||
if (!lastReceipt) {
|
||||
// Use a hash of the fileId as a stable pseudo-id; this gets
|
||||
|
||||
Reference in new issue
Block a user