Refactor Bridge APIs, slim Bridge and reorder imports
Move and standardize API implementations under bridge/apis, slim down the Bridge class (remove inline action implementations, caches and large comment blocks) and relocate related types/exports. Clean up and reorder imports across many bridge/api modules, normalize constructors, add logger imports where needed, and adjust WebUI routing/import ordering. These changes centralize API logic, reduce Bridge surface area, and tidy module boundaries and imports.
This commit is contained in:
1 parent
a52a9724cb
commit
a49e507e15
22 files changed
+144
-452
No files matched your search
@@ -1,12 +1,10 @@
|
||||
// ContactsApi — facade over the 6 contacts-related OIDB cmds (friend
|
||||
// roster / group roster / member roster / user profile / group request
|
||||
// list / download rkeys). Single-shot cmds forward straight to their
|
||||
// namespace; pagination and the per-group cache + inflight coalescing
|
||||
// for fetchGroupMemberList live here because they need cross-call
|
||||
// state.
|
||||
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
import type { DownloadRKeyInfo } from '../bridge';
|
||||
import { FetchDownloadRkeys } from '@snowluma/protocol/oidb-services/contacts/fetch-download-rkeys';
|
||||
import { FetchFriendListPage } from '@snowluma/protocol/oidb-services/contacts/fetch-friend-list-page';
|
||||
import { FetchGroupList } from '@snowluma/protocol/oidb-services/contacts/fetch-group-list';
|
||||
import { FetchGroupMemberListPage } from '@snowluma/protocol/oidb-services/contacts/fetch-group-member-list-page';
|
||||
import { FetchGroupRequests } from '@snowluma/protocol/oidb-services/contacts/fetch-group-requests';
|
||||
import { FetchUserProfile } from '@snowluma/protocol/oidb-services/contacts/fetch-user-profile';
|
||||
import { FetchUserProfileByUid } from '@snowluma/protocol/oidb-services/contacts/fetch-user-profile-by-uid';
|
||||
import type {
|
||||
FriendInfo,
|
||||
GroupMemberInfo,
|
||||
@@ -14,13 +12,8 @@ import type {
|
||||
QQGroupInfo,
|
||||
UserProfileInfo,
|
||||
} from '@snowluma/protocol/qq-info';
|
||||
import { FetchFriendListPage } from '@snowluma/protocol/oidb-services/contacts/fetch-friend-list-page';
|
||||
import { FetchGroupList } from '@snowluma/protocol/oidb-services/contacts/fetch-group-list';
|
||||
import { FetchGroupMemberListPage } from '@snowluma/protocol/oidb-services/contacts/fetch-group-member-list-page';
|
||||
import { FetchUserProfile } from '@snowluma/protocol/oidb-services/contacts/fetch-user-profile';
|
||||
import { FetchUserProfileByUid } from '@snowluma/protocol/oidb-services/contacts/fetch-user-profile-by-uid';
|
||||
import { FetchGroupRequests } from '@snowluma/protocol/oidb-services/contacts/fetch-group-requests';
|
||||
import { FetchDownloadRkeys } from '@snowluma/protocol/oidb-services/contacts/fetch-download-rkeys';
|
||||
import type { DownloadRKeyInfo } from '../bridge';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
|
||||
// ─── Helpers (previously in bridge-contacts.ts) ───────────────────
|
||||
|
||||
@@ -58,7 +51,7 @@ export class ContactsApi {
|
||||
private memberListInflight = new Map<number, Promise<GroupMemberInfo[]>>();
|
||||
private memberListLastFetch = new Map<number, { at: number; data: GroupMemberInfo[] }>();
|
||||
|
||||
constructor(private readonly ctx: BridgeContext) {}
|
||||
constructor(private readonly ctx: BridgeContext) { }
|
||||
|
||||
async fetchFriendList(): Promise<FriendInfo[]> {
|
||||
const friends: FriendInfo[] = [];
|
||||
|
||||
@@ -1,17 +1,12 @@
|
||||
// ExtrasApi — facade over Tier-2 napcat-parity OIDB cmds (group
|
||||
// todo CRUD / stranger status decode / AI voice list + synthesis).
|
||||
// Every method is a one-line forwarder to a self-contained namespace
|
||||
// under @snowluma/protocol/oidb-services/extras.
|
||||
|
||||
import type { MediaIndexNode } from './shared';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
import { GroupTodo } from '@snowluma/protocol/oidb-services/extras/group-todo';
|
||||
import { GetStrangerStatus, type StrangerStatus as NamespaceStrangerStatus } from '@snowluma/protocol/oidb-services/extras/get-stranger-status';
|
||||
import { FetchAiVoice } from '@snowluma/protocol/oidb-services/extras/fetch-ai-voice';
|
||||
import {
|
||||
FetchAiVoiceList,
|
||||
type AiVoiceCategory as NamespaceAiVoiceCategory,
|
||||
} from '@snowluma/protocol/oidb-services/extras/fetch-ai-voice-list';
|
||||
import { FetchAiVoice } from '@snowluma/protocol/oidb-services/extras/fetch-ai-voice';
|
||||
import { GetStrangerStatus, type StrangerStatus as NamespaceStrangerStatus } from '@snowluma/protocol/oidb-services/extras/get-stranger-status';
|
||||
import { GroupTodo } from '@snowluma/protocol/oidb-services/extras/group-todo';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
import type { MediaIndexNode } from './shared';
|
||||
|
||||
// ─────────────── public types (re-exported from bridge.ts as before) ───
|
||||
|
||||
@@ -32,7 +27,7 @@ export interface AiVoiceItem {
|
||||
}
|
||||
|
||||
export class ExtrasApi {
|
||||
constructor(private readonly ctx: BridgeContext) {}
|
||||
constructor(private readonly ctx: BridgeContext) { }
|
||||
|
||||
// ─────────────── Group todo (0xF90) ───────────────
|
||||
|
||||
|
||||
@@ -1,17 +1,4 @@
|
||||
// ForwardApi — long-message (聊天记录 / forward) upload + retrieval.
|
||||
// Inlined from `actions/forward.ts` (deleted alongside actions/* in
|
||||
// commit 13).
|
||||
//
|
||||
// The module-scoped `forwardResCache` stays at file scope (not on the
|
||||
// class instance) because forward res_ids are globally unique, and an
|
||||
// outbound upload often gets queried back through `fetch` on a
|
||||
// different Bridge instance (e.g. a different OneBot connection
|
||||
// hitting the same account). Keeping the cache shared across the
|
||||
// process matches NapCat's behaviour.
|
||||
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import { randomUUID } from 'crypto';
|
||||
import { gunzipSync, gzipSync } from 'zlib';
|
||||
import type { PacketInfo } from '@snowluma/common/protocol-types';
|
||||
import type {
|
||||
LongMsgResult,
|
||||
RecvLongMsgReq,
|
||||
@@ -20,12 +7,14 @@ import type {
|
||||
SendLongMsgResp,
|
||||
} from '@snowluma/proto-defs/longmsg';
|
||||
import type { FileExtra, PushMsg, PushMsgBody } from '@snowluma/proto-defs/message';
|
||||
import type { PacketInfo } from '@snowluma/common/protocol-types';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
import type { Bridge } from '../bridge';
|
||||
import { buildSendElems } from '@snowluma/protocol/element-builder';
|
||||
import type { ForwardNodePayload, MessageElement } from '@snowluma/protocol/events';
|
||||
import { parseMsgPush } from '@snowluma/protocol/msg-push';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import { randomUUID } from 'crypto';
|
||||
import { gunzipSync, gzipSync } from 'zlib';
|
||||
import type { Bridge } from '../bridge';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
import { resolveSelfUid, toInt } from './shared';
|
||||
|
||||
function asBridge(ctx: BridgeContext): Bridge { return ctx as unknown as Bridge; }
|
||||
@@ -214,7 +203,7 @@ function previewFromElements(elements: MessageElement[]): string {
|
||||
}
|
||||
|
||||
export class ForwardApi {
|
||||
constructor(private readonly ctx: BridgeContext) {}
|
||||
constructor(private readonly ctx: BridgeContext) { }
|
||||
|
||||
async upload(nodes: ForwardNodePayload[], groupId?: number, userId?: number): Promise<string> {
|
||||
const { resId } = await this.uploadRecursive(nodes, groupId, userId);
|
||||
|
||||
@@ -1,18 +1,10 @@
|
||||
// FriendApi — facade over friend-roster OIDB cmds. Every method is a
|
||||
// one-line forwarder to a self-contained namespace under
|
||||
// @snowluma/protocol/oidb-services/friend. The `delete()` facade method
|
||||
// adds a best-effort friend-list cache invalidation after the OIDB
|
||||
// call succeeds — that side-effect stays on the facade because it
|
||||
// reaches into `ctx.apis.contacts`, which the namespace deliberately
|
||||
// can't see.
|
||||
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
import { HandleFriendRequest } from '@snowluma/protocol/oidb-services/friend/handle-friend-request';
|
||||
import { DeleteFriend } from '@snowluma/protocol/oidb-services/friend/delete-friend';
|
||||
import { HandleFriendRequest } from '@snowluma/protocol/oidb-services/friend/handle-friend-request';
|
||||
import { SetFriendRemark } from '@snowluma/protocol/oidb-services/friend/set-friend-remark';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
|
||||
export class FriendApi {
|
||||
constructor(private readonly ctx: BridgeContext) {}
|
||||
constructor(private readonly ctx: BridgeContext) { }
|
||||
|
||||
/**
|
||||
* Accept or reject an inbound friend request. `uidOrFlag` is either a
|
||||
|
||||
@@ -1,31 +1,21 @@
|
||||
// GroupAdminApi — facade over Tier-2 napcat-parity group admin OIDB
|
||||
// cmds (mute / kick / admin / card / name / title / leave / join-policy
|
||||
// / add-request handling / @everyone budget). Every method is a
|
||||
// one-line forwarder to a self-contained namespace under
|
||||
// @snowluma/protocol/oidb-services/group-admin.
|
||||
//
|
||||
// The Apis facade keeps `bridge.apis.groupAdmin.X()` as the ergonomic
|
||||
// call site; the per-(cmd, subcmd) namespaces own the wire shape and
|
||||
// minimal capability surface.
|
||||
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
import { MuteMember } from '@snowluma/protocol/oidb-services/group-admin/mute-member';
|
||||
import { MuteAll } from '@snowluma/protocol/oidb-services/group-admin/mute-all';
|
||||
import { SetAddOption } from '@snowluma/protocol/oidb-services/group-admin/set-add-option';
|
||||
import { SetSearch } from '@snowluma/protocol/oidb-services/group-admin/set-search';
|
||||
import { SetAddRequest } from '@snowluma/protocol/oidb-services/group-admin/set-add-request';
|
||||
import { GetAtAllRemain } from '@snowluma/protocol/oidb-services/group-admin/get-at-all-remain';
|
||||
import { KickMember } from '@snowluma/protocol/oidb-services/group-admin/kick-member';
|
||||
import { KickMembers } from '@snowluma/protocol/oidb-services/group-admin/kick-members';
|
||||
import { LeaveGroup } from '@snowluma/protocol/oidb-services/group-admin/leave-group';
|
||||
import { MuteAll } from '@snowluma/protocol/oidb-services/group-admin/mute-all';
|
||||
import { MuteMember } from '@snowluma/protocol/oidb-services/group-admin/mute-member';
|
||||
import { SetAddOption } from '@snowluma/protocol/oidb-services/group-admin/set-add-option';
|
||||
import { SetAddRequest } from '@snowluma/protocol/oidb-services/group-admin/set-add-request';
|
||||
import { SetAdmin } from '@snowluma/protocol/oidb-services/group-admin/set-admin';
|
||||
import { SetMemberCard } from '@snowluma/protocol/oidb-services/group-admin/set-member-card';
|
||||
import { SetGroupName } from '@snowluma/protocol/oidb-services/group-admin/set-group-name';
|
||||
import { SetSpecialTitle } from '@snowluma/protocol/oidb-services/group-admin/set-special-title';
|
||||
import { SetGroupRemark } from '@snowluma/protocol/oidb-services/group-admin/set-group-remark';
|
||||
import { GetAtAllRemain } from '@snowluma/protocol/oidb-services/group-admin/get-at-all-remain';
|
||||
import { SetMemberCard } from '@snowluma/protocol/oidb-services/group-admin/set-member-card';
|
||||
import { SetSearch } from '@snowluma/protocol/oidb-services/group-admin/set-search';
|
||||
import { SetSpecialTitle } from '@snowluma/protocol/oidb-services/group-admin/set-special-title';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
|
||||
export class GroupAdminApi {
|
||||
constructor(private readonly ctx: BridgeContext) {}
|
||||
constructor(private readonly ctx: BridgeContext) { }
|
||||
|
||||
muteMember(groupId: number, userId: number, duration: number): Promise<void> {
|
||||
return MuteMember.invoke(this.ctx, { groupId, userId, duration });
|
||||
|
||||
@@ -1,10 +1,3 @@
|
||||
// GroupAlbumApi — group photo album operations (list/upload/comment/
|
||||
// like/delete + media listing). Inlined from `actions/group-album.ts`
|
||||
// and `web-actions/group-album.ts` (both deleted alongside actions/*
|
||||
// in commit 13). The pure-HTTP helpers in `web/group-album.ts` stay
|
||||
// where they are — they're transport-layer code, not Bridge actions.
|
||||
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type {
|
||||
DeleteMediasRequest,
|
||||
DeleteMediasResponse,
|
||||
@@ -15,9 +8,10 @@ import type {
|
||||
GetMediaListRequest,
|
||||
GetMediaListResponse,
|
||||
} from '@snowluma/proto-defs/oidb-actions/group-album';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
import type { Bridge } from '../bridge';
|
||||
import { getGroupAlbumList, uploadImageToGroupAlbum } from '@snowluma/protocol/web/group-album';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { Bridge } from '../bridge';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
// `getCookies` is part of WebApi — go through the hub so we don't
|
||||
// duplicate the cookie acquisition flow.
|
||||
|
||||
@@ -51,7 +45,7 @@ function convertBigIntToString(obj: any): any {
|
||||
}
|
||||
|
||||
export class GroupAlbumApi {
|
||||
constructor(private readonly ctx: BridgeContext) {}
|
||||
constructor(private readonly ctx: BridgeContext) { }
|
||||
|
||||
/** List a group's albums (HTTP-cookie-based, qzone.qq.com). */
|
||||
async list(groupId: number): Promise<any> {
|
||||
|
||||
@@ -1,39 +1,29 @@
|
||||
// GroupFileApi — group file CRUD + private (c2c) file upload + media
|
||||
// download URL resolvers.
|
||||
//
|
||||
// Single-OIDB-call methods are one-line forwarders to namespaces
|
||||
// under @snowluma/protocol/oidb-services/group-file. The multi-stage
|
||||
// methods (`upload` / `uploadPrivate`) stay here because they
|
||||
// orchestrate three discrete legs (OIDB preflight → highway PUT →
|
||||
// follow-on OIDB publish or message send) plus the upload-cache
|
||||
// bookkeeping the OneBot send path relies on.
|
||||
|
||||
import { protobuf_encode } from '@snowluma/proton';
|
||||
import { toHexUpper } from '@snowluma/common/hex';
|
||||
import { createLogger } from '@snowluma/common/logger';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
import type { Bridge } from '../bridge';
|
||||
import type { FileUploadExt } from '@snowluma/proto-defs/highway';
|
||||
import { fetchHighwaySession, uploadHighwayHttp } from '@snowluma/protocol/highway';
|
||||
import { computeHashes, computeMd5, FILE_UPLOAD_MAX_BYTES, loadBinarySource } from '@snowluma/protocol/highway/utils';
|
||||
import type { FileUploadExt } from '@snowluma/proto-defs/highway';
|
||||
import { protobuf_encode } from '@snowluma/proton';
|
||||
import type { Bridge } from '../bridge';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
import { resolveSelfUid, toInt, type MediaIndexNode } from './shared';
|
||||
|
||||
import { PublishGroupFile } from '@snowluma/protocol/oidb-services/group-file/publish-group-file';
|
||||
import { CreateGroupFolder } from '@snowluma/protocol/oidb-services/group-file/create-group-folder';
|
||||
import { DeleteGroupFile } from '@snowluma/protocol/oidb-services/group-file/delete-group-file';
|
||||
import { DeleteGroupFolder } from '@snowluma/protocol/oidb-services/group-file/delete-group-folder';
|
||||
import { GetGroupFileCount } from '@snowluma/protocol/oidb-services/group-file/get-group-file-count';
|
||||
import { GetGroupFileUrl } from '@snowluma/protocol/oidb-services/group-file/get-group-file-url';
|
||||
import { GetGroupPttUrl } from '@snowluma/protocol/oidb-services/group-file/get-group-ptt-url';
|
||||
import { GetGroupVideoUrl } from '@snowluma/protocol/oidb-services/group-file/get-group-video-url';
|
||||
import { GetPrivateFileUrl } from '@snowluma/protocol/oidb-services/group-file/get-private-file-url';
|
||||
import { GetPrivatePttUrl } from '@snowluma/protocol/oidb-services/group-file/get-private-ptt-url';
|
||||
import { GetPrivateVideoUrl } from '@snowluma/protocol/oidb-services/group-file/get-private-video-url';
|
||||
import { ListGroupFilesPage } from '@snowluma/protocol/oidb-services/group-file/list-group-files-page';
|
||||
import { MoveGroupFile } from '@snowluma/protocol/oidb-services/group-file/move-group-file';
|
||||
import { PublishGroupFile } from '@snowluma/protocol/oidb-services/group-file/publish-group-file';
|
||||
import { RenameGroupFolder } from '@snowluma/protocol/oidb-services/group-file/rename-group-folder';
|
||||
import { UploadGroupFileRequest } from '@snowluma/protocol/oidb-services/group-file/upload-group-file-request';
|
||||
import { UploadPrivateFileRequest } from '@snowluma/protocol/oidb-services/group-file/upload-private-file-request';
|
||||
import { ListGroupFilesPage } from '@snowluma/protocol/oidb-services/group-file/list-group-files-page';
|
||||
import { GetGroupFileUrl } from '@snowluma/protocol/oidb-services/group-file/get-group-file-url';
|
||||
import { GetPrivateFileUrl } from '@snowluma/protocol/oidb-services/group-file/get-private-file-url';
|
||||
import { DeleteGroupFile } from '@snowluma/protocol/oidb-services/group-file/delete-group-file';
|
||||
import { MoveGroupFile } from '@snowluma/protocol/oidb-services/group-file/move-group-file';
|
||||
import { CreateGroupFolder } from '@snowluma/protocol/oidb-services/group-file/create-group-folder';
|
||||
import { DeleteGroupFolder } from '@snowluma/protocol/oidb-services/group-file/delete-group-folder';
|
||||
import { RenameGroupFolder } from '@snowluma/protocol/oidb-services/group-file/rename-group-folder';
|
||||
import { GetGroupPttUrl } from '@snowluma/protocol/oidb-services/group-file/get-group-ptt-url';
|
||||
import { GetPrivatePttUrl } from '@snowluma/protocol/oidb-services/group-file/get-private-ptt-url';
|
||||
import { GetGroupVideoUrl } from '@snowluma/protocol/oidb-services/group-file/get-group-video-url';
|
||||
import { GetPrivateVideoUrl } from '@snowluma/protocol/oidb-services/group-file/get-private-video-url';
|
||||
import { ensureRetCodeZero } from '@snowluma/protocol/oidb-services/shared';
|
||||
|
||||
const log = createLogger('GroupFile');
|
||||
@@ -227,7 +217,7 @@ function buildPrivateFileUploadExt(
|
||||
}
|
||||
|
||||
export class GroupFileApi {
|
||||
constructor(private readonly ctx: BridgeContext) {}
|
||||
constructor(private readonly ctx: BridgeContext) { }
|
||||
|
||||
// ─────────────── publish (group file → chat) ───────────────
|
||||
|
||||
|
||||
@@ -1,23 +1,3 @@
|
||||
// ApiHub — the per-instance bag of typed Api classes hanging off
|
||||
// `bridge.apis`. Mirrors NapCat's `NapCatCore.apis = { MsgApi, …}`
|
||||
// pattern but uses camelCase keys (`apis.message.sendGroup`) to match
|
||||
// the rest of the SnowLuma TypeScript style.
|
||||
//
|
||||
// Each Api class is constructed once when the parent `Bridge` is
|
||||
// constructed (eager — every account that connects gets its own
|
||||
// `apis.*` set immediately). Api classes receive a `BridgeContext`
|
||||
// reference, NOT the concrete `Bridge`, so they remain easy to mock
|
||||
// without standing up a full Bridge instance.
|
||||
//
|
||||
// Adding a new Api:
|
||||
// 1. Create `bridge/apis/<name>.ts` exporting a `class XxxApi`.
|
||||
// 2. Add a property here.
|
||||
// 3. Construct it inside `buildApiHub(ctx)` below.
|
||||
// 4. Move the relevant methods OFF Bridge and onto the new Api.
|
||||
//
|
||||
// All 12 Api hubs are now live (#6 commits 1-12). The interface lists
|
||||
// every typed area an OneBot caller can reach via `bridge.apis.*`.
|
||||
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
import { ContactsApi } from './contacts';
|
||||
import { ExtrasApi } from './extras';
|
||||
@@ -99,3 +79,4 @@ export { MessageApi } from './message';
|
||||
export { MiscApi } from './misc';
|
||||
export { ProfileApi } from './profile';
|
||||
export { WebApi } from './web';
|
||||
|
||||
@@ -6,16 +6,16 @@
|
||||
// work (envelope build / encode / send / decode) lives in the
|
||||
// namespace files.
|
||||
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
import { SendPoke } from '@snowluma/protocol/oidb-services/interaction/send-poke';
|
||||
import { SendLike } from '@snowluma/protocol/oidb-services/interaction/send-like';
|
||||
import { SendPoke } from '@snowluma/protocol/oidb-services/interaction/send-poke';
|
||||
import { SetEssence } from '@snowluma/protocol/oidb-services/interaction/set-essence';
|
||||
import { SetReaction } from '@snowluma/protocol/oidb-services/reaction/set-reaction';
|
||||
import { FetchReactionSummary } from '@snowluma/protocol/oidb-services/reaction/fetch-reaction-summary';
|
||||
import { GetEmojiLikes } from '@snowluma/protocol/oidb-services/reaction/get-emoji-likes';
|
||||
import { SetReaction } from '@snowluma/protocol/oidb-services/reaction/set-reaction';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
|
||||
export class InteractionApi {
|
||||
constructor(private readonly ctx: BridgeContext) {}
|
||||
constructor(private readonly ctx: BridgeContext) { }
|
||||
|
||||
sendPoke(isGroup: boolean, peerUin: number, targetUin?: number): Promise<void> {
|
||||
return SendPoke.invoke(this.ctx, { isGroup, peerUin, targetUin });
|
||||
|
||||
@@ -1,17 +1,3 @@
|
||||
// MessageApi — send / recall / mark-read operations.
|
||||
//
|
||||
// Folds together the previous shapes:
|
||||
// - `Bridge.sendGroupMessage` / `sendPrivateMessage` / `sendC2cFileMessage`
|
||||
// (formerly inline on the Bridge class).
|
||||
// - `actions/group-message.ts` (recallGroup / recallPrivate /
|
||||
// markGroupRead / markPrivateRead).
|
||||
//
|
||||
// All implementations are inlined here — the previous indirection
|
||||
// through `actions/group-message.ts` exported functions was just
|
||||
// `(bridge, args) → method body`; once methods live on a typed Api
|
||||
// class the wrapper layer doesn't earn its keep.
|
||||
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type {
|
||||
SendMessageRequest,
|
||||
SendMessageResponse,
|
||||
@@ -22,8 +8,9 @@ import type {
|
||||
GroupRecallRequest,
|
||||
SsoReadedReportReq,
|
||||
} from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import type { MessageElement } from '@snowluma/protocol/events';
|
||||
import { buildSendElems } from '@snowluma/protocol/element-builder';
|
||||
import type { MessageElement } from '@snowluma/protocol/events';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
// `Bridge` is imported as a type only so we can narrow `ctx` back to
|
||||
// the concrete Bridge instance when passing it to `buildSendElems`
|
||||
@@ -38,7 +25,7 @@ import type { Bridge, SendMessageReceipt } from '../bridge';
|
||||
const SEND_MSG_CMD = 'MessageSvc.PbSendMsg';
|
||||
|
||||
export class MessageApi {
|
||||
constructor(private readonly ctx: BridgeContext) {}
|
||||
constructor(private readonly ctx: BridgeContext) { }
|
||||
|
||||
/**
|
||||
* Send a message to a QQ group.
|
||||
|
||||
@@ -1,21 +1,16 @@
|
||||
// MiscApi — odds & ends that don't fit the other Apis: translation,
|
||||
// mini-app ARK build, inline-keyboard button click, group sign-in.
|
||||
// Inlined from `actions/misc.ts` (deleted alongside actions/* in
|
||||
// commit 13).
|
||||
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type {
|
||||
MiniAppShareReq,
|
||||
MiniAppShareResp,
|
||||
} from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
// Migrated OIDB cmds — facade methods are one-line forwarders.
|
||||
import { TranslateEnToZh } from '@snowluma/protocol/oidb-services/misc/translate-en-to-zh';
|
||||
import { ClickInlineKeyboardButton } from '@snowluma/protocol/oidb-services/misc/click-inline-keyboard-button';
|
||||
import { SendGroupSign } from '@snowluma/protocol/oidb-services/misc/send-group-sign';
|
||||
import { TranslateEnToZh } from '@snowluma/protocol/oidb-services/misc/translate-en-to-zh';
|
||||
|
||||
export class MiscApi {
|
||||
constructor(private readonly ctx: BridgeContext) {}
|
||||
constructor(private readonly ctx: BridgeContext) { }
|
||||
|
||||
translateEn2Zh(words: string[]): Promise<string[]> {
|
||||
return TranslateEnToZh.invoke(this.ctx, { words });
|
||||
|
||||
@@ -1,8 +1,3 @@
|
||||
// ProfileApi — personal profile + status + avatar + likes + custom
|
||||
// faces + unidirectional friend list. Inlined from
|
||||
// `actions/profile.ts` (deleted alongside actions/* in commit 13).
|
||||
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type {
|
||||
FaceroamOpReq,
|
||||
FaceroamOpResp,
|
||||
@@ -10,21 +5,21 @@ import type {
|
||||
SetStatusReq,
|
||||
SetStatusResp,
|
||||
} from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
import type { Bridge } from '../bridge';
|
||||
import { fetchHighwaySession, uploadHighwayHttp } from '@snowluma/protocol/highway';
|
||||
import { computeHashes, loadBinarySource } from '@snowluma/protocol/highway/utils';
|
||||
// Migrated OIDB cmds — facade methods are one-line forwarders.
|
||||
import { SetProfile } from '@snowluma/protocol/oidb-services/profile/set-profile';
|
||||
import { SetSelfLongNick } from '@snowluma/protocol/oidb-services/profile/set-self-long-nick';
|
||||
import { SetInputStatus } from '@snowluma/protocol/oidb-services/profile/set-input-status';
|
||||
import { GetLike } from '@snowluma/protocol/oidb-services/profile/get-like';
|
||||
import { GetUnidirectionalFriendList } from '@snowluma/protocol/oidb-services/profile/get-unidirectional-friend-list';
|
||||
import { SetInputStatus } from '@snowluma/protocol/oidb-services/profile/set-input-status';
|
||||
import { SetProfile } from '@snowluma/protocol/oidb-services/profile/set-profile';
|
||||
import { SetSelfLongNick } from '@snowluma/protocol/oidb-services/profile/set-self-long-nick';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { Bridge } from '../bridge';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
|
||||
function asBridge(ctx: BridgeContext): Bridge { return ctx as unknown as Bridge; }
|
||||
|
||||
export class ProfileApi {
|
||||
constructor(private readonly ctx: BridgeContext) {}
|
||||
constructor(private readonly ctx: BridgeContext) { }
|
||||
|
||||
// ─────────────── status / profile setters ───────────────
|
||||
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
import type { Bridge } from '../bridge';
|
||||
|
||||
/**
|
||||
* Coerce numbers, strings, and bigints to a plain integer.
|
||||
* Returns 0 for anything we can't interpret — every action that
|
||||
* threads this through OIDB has an explicit `<=0` validation later.
|
||||
*/
|
||||
export function toInt(value: unknown): number {
|
||||
if (typeof value === 'number' && Number.isFinite(value)) return Math.trunc(value);
|
||||
if (typeof value === 'bigint') {
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
// WebApi — cookie-backed HTTP wrappers (group essence / honor / notice /
|
||||
// client-key / pskey / csrf-token / credentials). Inlined from the
|
||||
// per-feature files in `web-actions/` (all deleted in commit 13).
|
||||
// The pure HTTP transport stays in `web/*.ts` and stays unchanged —
|
||||
// only the Bridge-binding helpers move here.
|
||||
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
import type { Bridge } from '../bridge';
|
||||
import { ForceFetchClientKey, type ClientKeyInfo as NamespaceClientKeyInfo } from '@snowluma/protocol/oidb-services/web/force-fetch-client-key';
|
||||
import { GetPskey } from '@snowluma/protocol/oidb-services/web/get-pskey';
|
||||
import { getGroupEssenceMsg, getGroupEssenceMsgAll } from '@snowluma/protocol/web/group-essence';
|
||||
import { getHonorListWebAPI, WebHonorType } from '@snowluma/protocol/web/group-honor';
|
||||
import {
|
||||
@@ -15,10 +9,8 @@ import {
|
||||
uploadGroupNoticeImage,
|
||||
} from '@snowluma/protocol/web/group-notice';
|
||||
import { RequestUtil } from '@snowluma/protocol/web/request-util';
|
||||
// Migrated OIDB cmds — the two private helpers below are thin
|
||||
// forwarders into the namespaces.
|
||||
import { ForceFetchClientKey, type ClientKeyInfo as NamespaceClientKeyInfo } from '@snowluma/protocol/oidb-services/web/force-fetch-client-key';
|
||||
import { GetPskey } from '@snowluma/protocol/oidb-services/web/get-pskey';
|
||||
import type { Bridge } from '../bridge';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
|
||||
function asBridge(ctx: BridgeContext): Bridge { return ctx as unknown as Bridge; }
|
||||
|
||||
@@ -101,7 +93,7 @@ function getBknFromSKey(skey: string): number {
|
||||
}
|
||||
|
||||
export class WebApi {
|
||||
constructor(private readonly ctx: BridgeContext) {}
|
||||
constructor(private readonly ctx: BridgeContext) { }
|
||||
|
||||
// ─────────────── cookie / token primitives ───────────────
|
||||
|
||||
|
||||
Reference in new issue
Block a user