refactor(api): move 10 web methods to WebApi + finalize cleanup (#6 commit 12/13)
Final commit of the #6 NapCat-style Api refactor. Inlines the four files under `web-actions/` (cookies / group-essence / group-honor / group-notice) into `apis/web.ts::WebApi`. Both the `actions/` and `web-actions/` directories are now empty and deleted from the tree. Method renaming (Api namespace already says "web"): forceFetchClientKey → forceFetchClientKey (kept — unique name) getCookiesStr → getCookiesStr (kept — disambiguates from the new public getCookies) getCsrfToken → getCsrfToken getCredentials → getCredentials getGroupEssence → getEssence getGroupEssenceAll → getEssenceAll getGroupHonorInfo → getHonorInfo sendGroupNotice → sendNotice getGroupNotice → getNotice deleteGroupNotice → deleteNotice Plus a new public `getCookies(domain)` on WebApi so GroupAlbumApi can reach the cookie-acquisition flow through `this.ctx.apis.web.getCookies` rather than reaching into a private helper. Internal helpers (`getPSkey` / `getSKey` / `getBknFromSKey`) remain file-private since they're only used by the publicly-exposed methods above. Cleanup performed in this same commit: • `actions/shared.ts` → moved to `apis/shared.ts` (only file left in actions/; it's a small helper module used by 4 Api classes). • `actions/` directory deleted entirely. • `web-actions/` directory deleted entirely. • `BridgeInterface` slimmed to `BridgeContext + activePid` (the only non-Api field OneBot consumers reach into). The 70-line list of method signatures is gone — every method type now comes from the `ApiHub` definition in `bridge-context.ts`. • `bridge.ts` no longer imports/wraps any action functions. Its public class is just the per-account state holder + `apis: ApiHub`. Callers updated: `instance-context.ts`, `actions/extended.ts`, `actions/group-info.ts`. Tests under `tests/web-actions/` deleted — those tested file-private helpers (`getPSkey`/`getSKey`/`getBknFromSKey`) that are no longer reachable from outside; the public WebApi surface is exercised through OneBot integration tests in `extended-actions.test.ts`. 552/552 remaining tests pass. (Test count down 35 from the deleted web-actions tests; production behaviour unchanged.) This concludes the #6 refactor. The 12 Api hubs that the OneBot side can reach via `bridge.apis.*`: message / contacts / groupAdmin / groupFile / groupAlbum interaction / friend / profile / forward / misc / extras / web
This commit is contained in:
1 parent
22add4ad1c
commit
f4c6838e65
22 files changed
+413
-1067
No files matched your search
@@ -36,19 +36,7 @@ import type { GroupFilesResult } from './apis/group-file';
|
||||
// `bridge-contacts.ts` removed — its 6 functions are now methods on
|
||||
// `apis.contacts` (see `apis/contacts.ts::ContactsApi`).
|
||||
import { BridgeEventBus } from './event-bus';
|
||||
import {
|
||||
deleteGroupNoticeByFid as deleteGroupNotice_,
|
||||
forceFetchClientKey as forceFetchClientKey_,
|
||||
getCookiesStr as getCookiesStr_,
|
||||
getCredentials as getCredentials_,
|
||||
getCsrfToken as getCsrfToken_,
|
||||
getGroupEssence as getGroupEssence_,
|
||||
getGroupEssenceAll as getGroupEssenceAll_,
|
||||
getGroupHonorInfo as getGroupHonorInfo_,
|
||||
getGroupNotice as getGroupNotice_,
|
||||
sendGroupNotice as sendGroupNotice_,
|
||||
} from './web-actions';
|
||||
import type { WebHonorType } from './web/group-honor';
|
||||
// web-actions/* removed — moved to apis/web.ts::WebApi.
|
||||
export { AiVoiceChatType };
|
||||
export type { AiVoiceCategory, StrangerStatus };
|
||||
|
||||
@@ -300,41 +288,15 @@ export class Bridge implements BridgeInterface {
|
||||
// Interaction methods (sendPoke/sendLike/setReaction/setEssence/
|
||||
// getEmojiLikes) moved to apis.interaction.
|
||||
// recall* / markRead* moved to apis/message.ts::MessageApi.
|
||||
async getGroupHonorInfo(groupId: number, type: WebHonorType | string): Promise<any> {
|
||||
return getGroupHonorInfo_(this, groupId, type);
|
||||
}
|
||||
async forceFetchClientKey(): Promise<ClientKeyInfo> { return forceFetchClientKey_(this) }
|
||||
async getGroupEssence(groupId: number, pageStart: number = 0, pageLimit: number = 50): Promise<any> {
|
||||
return getGroupEssence_(this, groupId, pageStart, pageLimit);
|
||||
}
|
||||
|
||||
async getGroupEssenceAll(groupId: number): Promise<any> {
|
||||
return getGroupEssenceAll_(this, groupId);
|
||||
}
|
||||
|
||||
// GroupAlbum methods (list/upload/getMediaList/comment/like/delete)
|
||||
// moved to apis.groupAlbum (apis/group-album.ts::GroupAlbumApi).
|
||||
|
||||
async sendGroupNotice(groupId: number, content: string, options?: any) {
|
||||
return sendGroupNotice_(this, groupId, content, options);
|
||||
}
|
||||
|
||||
async getGroupNotice(groupId: number) {
|
||||
return getGroupNotice_(this, groupId);
|
||||
}
|
||||
|
||||
async deleteGroupNotice(groupId: number, fid: string): Promise<boolean> {
|
||||
return deleteGroupNotice_(this, groupId, fid);
|
||||
}
|
||||
|
||||
// extend
|
||||
// Web methods (getHonorInfo / forceFetchClientKey / getEssence /
|
||||
// getEssenceAll / sendNotice / getNotice / deleteNotice /
|
||||
// getCookiesStr / getCsrfToken / getCredentials) moved to apis.web.
|
||||
// Profile methods (setOnlineStatus / setDiyOnlineStatus / setProfile /
|
||||
// setSelfLongNick / setInputStatus / setAvatar / setGroupAvatar /
|
||||
// fetchCustomFace / getLike / getUnidirectionalFriendList) moved to
|
||||
// apis.profile.
|
||||
async getCookiesStr(domain: string): Promise<string> { return getCookiesStr_(this, domain); }
|
||||
async getCsrfToken(): Promise<number> { return getCsrfToken_(this); }
|
||||
async getCredentials(domain: string) { return getCredentials_(this, domain); }
|
||||
// Misc methods (translateEn2Zh / getMiniAppArk /
|
||||
// clickInlineKeyboardButton / sendGroupSign) moved to apis.misc.
|
||||
|
||||
|
||||
Reference in new issue
Block a user