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
@@ -1,96 +1,22 @@
|
||||
import type { SendPacketResult } from '../protocol/packet-sender';
|
||||
import type { ApiHub } from './apis';
|
||||
import type {
|
||||
ClientKeyInfo,
|
||||
DownloadRKeyInfo,
|
||||
UploadedFileMeta,
|
||||
} from './bridge';
|
||||
import type { BridgeEventBus } from './event-bus';
|
||||
import type { IdentityService } from './identity-service';
|
||||
import type { WebHonorType } from './web/group-honor';
|
||||
// BridgeInterface — the public Bridge surface for OneBot-side
|
||||
// consumers. Slimmed down to BridgeContext + the few extra fields
|
||||
// OneBot reaches into directly (most notably `activePid`).
|
||||
//
|
||||
// Most OneBot code paths reach business methods through
|
||||
// `bridge.apis.<area>.method()` — those types come from `ApiHub`
|
||||
// inside `bridge-context.ts`. The remaining members below are the
|
||||
// non-Api state that doesn't fit into a typed Api hub.
|
||||
//
|
||||
// Internal Api implementations should depend on `BridgeContext`
|
||||
// instead (the narrower contract). `BridgeInterface` is for callers
|
||||
// that need the activePid hook or for backwards compatibility with
|
||||
// pre-#6 code that imported `BridgeInterface` as the bridge type.
|
||||
|
||||
export interface BridgeInterface {
|
||||
// ─── Shared state ───
|
||||
readonly identity: IdentityService;
|
||||
readonly events: BridgeEventBus;
|
||||
import type { BridgeContext } from './bridge-context';
|
||||
|
||||
export interface BridgeInterface extends BridgeContext {
|
||||
/** Last-active process id — used by `OneBotManager` to thread
|
||||
* per-process state into the right instance. `null` when no
|
||||
* process has bound yet. */
|
||||
readonly activePid: number | null;
|
||||
/**
|
||||
* Typed Api hub — `apis.message.sendGroup(...)`, `apis.message.recallGroup(...)`,
|
||||
* etc. The shape of `ApiHub` grows commit-by-commit as the #6
|
||||
* refactor moves the remaining areas (group-admin, group-file,
|
||||
* profile, …) off Bridge and onto their dedicated Api classes.
|
||||
*/
|
||||
readonly apis: ApiHub;
|
||||
|
||||
// ─── Resolution ───
|
||||
resolveUserUid(uin: number, groupId?: number): Promise<string>;
|
||||
|
||||
// ─── Raw packet (deliberate escape hatch for `send_packet` action) ───
|
||||
// OneBot clients use this to debug or invoke commands SnowLuma has no
|
||||
// typed wrapper for. Every other method on this interface eventually
|
||||
// routes through here.
|
||||
sendRawPacket(serviceCmd: string, body: Uint8Array, timeoutMs?: number): Promise<SendPacketResult>;
|
||||
|
||||
// ─── Send-side protocol helpers (used by Api classes) ───
|
||||
nextMessageRandom(): number;
|
||||
nextClientSequence(): number;
|
||||
|
||||
// ─── Send (messages) ───
|
||||
// Moved to `apis.message.{sendGroup, sendPrivate, sendC2cFile,
|
||||
// recallGroup, recallPrivate, markGroupRead, markPrivateRead}`.
|
||||
|
||||
// ─── Fetch (contacts / profile / system) — moved to apis.contacts ───
|
||||
|
||||
// ─── Group admin (moved to apis.groupAdmin) ───
|
||||
// ─── Group reaction / essence (moved to apis.interaction) ───
|
||||
|
||||
// ─── Friend (moved to apis.friend) ───
|
||||
// - handleRequest / delete / setRemark
|
||||
|
||||
// ─── Files (moved to apis.groupFile) ───
|
||||
// - upload / uploadPrivate / publish
|
||||
// - list / getCount
|
||||
// - getUrl / getPrivateUrl / getPttUrl / getPrivatePttUrl
|
||||
// - getVideoUrl / getPrivateVideoUrl
|
||||
// - delete / move / createFolder / deleteFolder / renameFolder
|
||||
/** Cache file metadata so a later send_msg with just `file_id` can rehydrate it. */
|
||||
rememberUploadedFile(meta: UploadedFileMeta): void;
|
||||
recallUploadedFile(fileId: string): UploadedFileMeta | undefined;
|
||||
|
||||
// ─── Group Album (moved to apis.groupAlbum) ───
|
||||
// - list / upload / getMediaList / comment / like / delete
|
||||
|
||||
// ─── Forward (moved to apis.forward) ───
|
||||
// - upload / fetch
|
||||
|
||||
// ─── Message ops (moved to apis.message) ───
|
||||
|
||||
// ─── Interaction (moved to apis.interaction) ───
|
||||
// - sendPoke / sendLike / setReaction / setEssence / getEmojiLikes
|
||||
|
||||
// ─── Web-backed ───
|
||||
getGroupHonorInfo(groupId: number, type: WebHonorType | string): Promise<any>;
|
||||
forceFetchClientKey(): Promise<ClientKeyInfo>;
|
||||
getGroupEssence(groupId: number, pageStart?: number, pageLimit?: number): Promise<any>;
|
||||
getGroupEssenceAll(groupId: number): Promise<any>;
|
||||
sendGroupNotice(groupId: number, content: string, options?: any): Promise<any>;
|
||||
getGroupNotice(groupId: number): Promise<any>;
|
||||
deleteGroupNotice(groupId: number, fid: string): Promise<boolean>;
|
||||
getCookiesStr(domain: string): Promise<string>;
|
||||
getCsrfToken(): Promise<number>;
|
||||
getCredentials(domain: string): Promise<any>;
|
||||
|
||||
// ─── Personal profile (moved to apis.profile) ───
|
||||
// - setOnlineStatus / setDiyOnlineStatus
|
||||
// - setProfile / setSelfLongNick / setInputStatus
|
||||
// - setAvatar / setGroupAvatar / fetchCustomFace
|
||||
// - getLike / getUnidirectionalFriendList
|
||||
|
||||
// ─── Misc (moved to apis.misc) ───
|
||||
// - translateEn2Zh / getMiniAppArk / clickInlineKeyboardButton / sendGroupSign
|
||||
|
||||
// ─── Tier-2 napcat parity extras (moved to apis.extras) ───
|
||||
// - setGroupTodo / completeGroupTodo / cancelGroupTodo
|
||||
// - getStrangerStatus
|
||||
// - fetchAiVoiceList / fetchAiVoice
|
||||
}
|
||||
Reference in new issue
Block a user