Refactor bridge modules: imports & cleanup
Standardize and reorganize imports, type usages and minor formatting across the bridge modules. This commit moves protobuf helpers, makeOidbEnvelope/runOidb, OidbBase and logger imports into consistent places, reorders and groups action/contacts exports in Bridge, removes or trims file-level comments, and fixes whitespace/logic ordering in several highway, element-builder and msg-push files. These are refactors and import/type adjustments across many files under packages/core/src (bridge, highway, msg-push, webui, utils, etc.) with no intended behavioral changes.
This commit is contained in:
1 parent
c49ae1c8d9
commit
b56868878c
83 files changed
+356
-919
No files matched your search
@@ -1,12 +1,8 @@
|
||||
import type { ApiHandler, ApiActionContext } from '../api-handler';
|
||||
import { asMessage, asNumber, asString, asBoolean } from '../api-handler';
|
||||
import type { ApiActionContext, ApiHandler } from '../api-handler';
|
||||
import { asBoolean, asMessage, asNumber, asString } from '../api-handler';
|
||||
import type { ForwardPreviewMeta } from '../modules/message-actions';
|
||||
import { RETCODE, failedResponse, okResponse } from '../types';
|
||||
|
||||
// Bounded download for the OneBot `download_file` action. An authenticated
|
||||
// client could otherwise hand us a multi-GB URL (or chunked response with
|
||||
// no Content-Length) and OOM the bot — `await response.arrayBuffer()`
|
||||
// happily allocates the whole payload before any size check fires.
|
||||
const DOWNLOAD_FILE_MAX_BYTES = 1024 * 1024 * 1024; // 1 GiB
|
||||
const DOWNLOAD_FILE_TIMEOUT_MS = 60_000;
|
||||
|
||||
|
||||
@@ -1,12 +1,3 @@
|
||||
// Bridge event -> OneBot top-level event conversion.
|
||||
//
|
||||
// Replaces the old `EventConverter` class. The class held four
|
||||
// resolver fields (image-url / media-url / message-id / media-segment
|
||||
// sink) wired in lazily via setters; the new shape passes them as a
|
||||
// `ConverterContext` object so each case is a pure function and the
|
||||
// per-case test setup is two lines, not a class instance plus four
|
||||
// setter calls.
|
||||
|
||||
import type { MessageElement, QQEventVariant } from '../../bridge/events';
|
||||
import type { JsonObject } from '../types';
|
||||
import {
|
||||
@@ -84,26 +75,26 @@ export async function convertEvent(
|
||||
switch (event.kind) {
|
||||
// Messages.
|
||||
case 'friend_message': return convertFriendMessage(ctx, event);
|
||||
case 'group_message': return convertGroupMessage(ctx, event);
|
||||
case 'temp_message': return convertTempMessage(ctx, event);
|
||||
case 'group_message': return convertGroupMessage(ctx, event);
|
||||
case 'temp_message': return convertTempMessage(ctx, event);
|
||||
|
||||
// Notices.
|
||||
case 'group_member_join': return convertGroupMemberJoin(ctx, event);
|
||||
case 'group_member_join': return convertGroupMemberJoin(ctx, event);
|
||||
case 'group_member_leave': return convertGroupMemberLeave(ctx, event);
|
||||
case 'group_mute': return convertGroupMute(ctx, event);
|
||||
case 'group_admin': return convertGroupAdmin(ctx, event);
|
||||
case 'friend_recall': return convertFriendRecall(ctx, event);
|
||||
case 'group_recall': return convertGroupRecall(ctx, event);
|
||||
case 'friend_poke': return convertFriendPoke(ctx, event);
|
||||
case 'group_poke': return convertGroupPoke(ctx, event);
|
||||
case 'group_essence': return convertGroupEssence(ctx, event);
|
||||
case 'group_file_upload': return convertGroupFileUpload(ctx, event);
|
||||
case 'friend_add': return convertFriendAdd(ctx, event);
|
||||
case 'group_mute': return convertGroupMute(ctx, event);
|
||||
case 'group_admin': return convertGroupAdmin(ctx, event);
|
||||
case 'friend_recall': return convertFriendRecall(ctx, event);
|
||||
case 'group_recall': return convertGroupRecall(ctx, event);
|
||||
case 'friend_poke': return convertFriendPoke(ctx, event);
|
||||
case 'group_poke': return convertGroupPoke(ctx, event);
|
||||
case 'group_essence': return convertGroupEssence(ctx, event);
|
||||
case 'group_file_upload': return convertGroupFileUpload(ctx, event);
|
||||
case 'friend_add': return convertFriendAdd(ctx, event);
|
||||
case 'group_msg_emoji_like': return convertGroupMsgEmojiLike(ctx, event);
|
||||
|
||||
// Requests.
|
||||
case 'friend_request': return convertFriendRequest(ctx, event);
|
||||
case 'group_invite': return convertGroupInvite(ctx, event);
|
||||
case 'friend_request': return convertFriendRequest(ctx, event);
|
||||
case 'group_invite': return convertGroupInvite(ctx, event);
|
||||
|
||||
default:
|
||||
return null;
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
// Message-kind handlers: friend_message, group_message, temp_message.
|
||||
// Each takes a ConverterContext (which carries selfId + the four
|
||||
// resolver/sink callbacks) and the typed bridge event, and returns the
|
||||
// OneBot top-level event JSON.
|
||||
|
||||
import type { QQEventVariant } from '../../bridge/events';
|
||||
import type { JsonObject } from '../types';
|
||||
import { GROUP_MESSAGE_EVENT, PRIVATE_MESSAGE_EVENT } from '../message-id';
|
||||
import type { JsonObject } from '../types';
|
||||
import type { ConverterContext } from './index';
|
||||
import { elementsToJson } from './to-segment';
|
||||
import { applyMessageIdResolver, segmentsToRawMessage } from './utils';
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
// Notice-kind handlers (10 cases). These produce OneBot `notice` events
|
||||
// with no message body / no element conversion — pure field projections
|
||||
// from the bridge event into the OneBot wire shape. None of them call
|
||||
// resolvers except the two recall handlers and group_essence, which
|
||||
// need a message-id resolution.
|
||||
|
||||
import type { QQEventVariant } from '../../bridge/events';
|
||||
import type { JsonObject } from '../types';
|
||||
import { GROUP_MESSAGE_EVENT, PRIVATE_MESSAGE_EVENT } from '../message-id';
|
||||
import type { JsonObject } from '../types';
|
||||
import type { ConverterContext } from './index';
|
||||
import { applyMessageIdResolver, isSameActor } from './utils';
|
||||
|
||||
|
||||
@@ -1,8 +1,3 @@
|
||||
// Request-kind handlers (2 cases). OneBot `request` events for friend
|
||||
// adds and group invites/joins — both carry the bridge-supplied `flag`
|
||||
// that the caller later passes back to `set_friend_add_request` /
|
||||
// `set_group_add_request`.
|
||||
|
||||
import type { QQEventVariant } from '../../bridge/events';
|
||||
import type { JsonObject } from '../types';
|
||||
import type { ConverterContext } from './index';
|
||||
|
||||
@@ -1,8 +1,3 @@
|
||||
// Per-element converter: 13 element types -> one OneBot message segment.
|
||||
// Used by message-events (friend/group/temp) for inline elements AND by
|
||||
// modules/message-actions.ts for forward-message rebuilding (re-exported
|
||||
// from this module via the index barrel as `elementsToOneBotSegments`).
|
||||
|
||||
import type { MessageElement } from '../../bridge/events';
|
||||
import type { JsonArray, JsonObject } from '../types';
|
||||
import type {
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
// Pure helpers shared across the per-post_type converter modules.
|
||||
//
|
||||
// Nothing here touches I/O or class state; everything is a small
|
||||
// function so the per-event tests can import what they need without
|
||||
// dragging in resolver wiring.
|
||||
|
||||
import type { JsonArray, JsonObject } from '../types';
|
||||
import { GROUP_MESSAGE_EVENT, PRIVATE_MESSAGE_EVENT } from '../message-id';
|
||||
import type { JsonArray, JsonObject } from '../types';
|
||||
import type { MessageIdResolver } from './index';
|
||||
|
||||
export function parseSelfId(instanceUin: string): number {
|
||||
|
||||
@@ -1,11 +1,4 @@
|
||||
import type { JsonObject, JsonValue, MessageFormat } from './types';
|
||||
|
||||
/**
|
||||
* Per-adapter view of how an event should be reported.
|
||||
*
|
||||
* Built once from each adapter's own configuration at (re)load time so the
|
||||
* per-publish dispatch loop is just a couple of object lookups.
|
||||
*/
|
||||
export interface EventReportOptions {
|
||||
/** Effective `messageFormat` for this adapter. */
|
||||
messageFormat: MessageFormat;
|
||||
|
||||
@@ -1,15 +1,7 @@
|
||||
// Per-kind bridge → OneBot event handlers.
|
||||
//
|
||||
// Replaces the legacy single-firehose `OneBotInstance.onBridgeEvent` switch.
|
||||
// Every bridge event kind gets a small async handler bound to a shared
|
||||
// `OneBotInstanceContext`; subscribers register on `ctx.bridge.events` so
|
||||
// multiple unrelated downstream concerns (meta caching, OB11 conversion,
|
||||
// dispatch) compose cleanly without one giant switch statement.
|
||||
|
||||
import type { OneBotInstanceContext } from './instance-context';
|
||||
import { convertEvent } from './event-converter';
|
||||
import { GROUP_MESSAGE_EVENT, PRIVATE_MESSAGE_EVENT, hashMessageIdInt32 } from './message-id';
|
||||
import type { QQEventVariant } from '../bridge/events';
|
||||
import { convertEvent } from './event-converter';
|
||||
import type { OneBotInstanceContext } from './instance-context';
|
||||
import { GROUP_MESSAGE_EVENT, PRIVATE_MESSAGE_EVENT, hashMessageIdInt32 } from './message-id';
|
||||
|
||||
/**
|
||||
* Subscribe every `OneBotInstanceContext`-aware handler onto the bridge
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import type { BridgeInterface } from '../bridge/bridge-interface';
|
||||
import type { BridgeManager } from '../bridge/manager';
|
||||
import { createLogger } from '../utils/logger';
|
||||
import { loadOneBotConfig } from './config';
|
||||
import { OneBotInstance } from './instance';
|
||||
import { createLogger } from '../utils/logger';
|
||||
|
||||
const log = createLogger('OneBot');
|
||||
const VERBOSE_WARMUP = process.env.SNOWLUMA_VERBOSE_WARMUP === '1';
|
||||
@@ -18,9 +18,6 @@ export class OneBotManager {
|
||||
bridgeManager.setSessionClosedCallback((uin) => {
|
||||
this.onSessionClosed(uin);
|
||||
});
|
||||
|
||||
// Per-kind subscriptions to `bridge.events` happen inside
|
||||
// `OneBotInstance` itself; no global firehose to wire here.
|
||||
}
|
||||
|
||||
getInstance(uin: string): OneBotInstance | null {
|
||||
|
||||
@@ -1,23 +1,15 @@
|
||||
// Side-channel observer that watches every image / record / video
|
||||
// segment emitted by the event converter and writes a row into the
|
||||
// MediaStore so later `get_image` / `get_record` OneBot actions can
|
||||
// resolve the original `data.file` back to a URL + metadata.
|
||||
//
|
||||
// Used as the `mediaSegmentSink` callback in `ConverterContext`.
|
||||
//
|
||||
// The fan-out is uniform (always one rememberX call per segment), but
|
||||
// each mediaType maps to a slightly different MediaStore record shape;
|
||||
// keeping the three field maps in one place makes the divergence
|
||||
// visible at a glance.
|
||||
|
||||
import type { MessageElement } from '../bridge/events';
|
||||
import type { JsonObject } from './types';
|
||||
import type { MediaStore } from './media-store';
|
||||
import type { JsonObject } from './types';
|
||||
|
||||
export type MediaType = 'image' | 'record' | 'video';
|
||||
|
||||
export class MediaIndexer {
|
||||
constructor(private readonly mediaStore: MediaStore) {}
|
||||
constructor(private readonly mediaStore: MediaStore) { }
|
||||
|
||||
remember(
|
||||
mediaType: MediaType,
|
||||
|
||||
@@ -3,24 +3,10 @@
|
||||
// The `get_image` / `get_record` actions need to map a `data.file` (or related
|
||||
// identifier) we previously emitted in a message segment back to the URL,
|
||||
// size, name, and any OIDB media-node info needed to re-resolve a stale URL.
|
||||
//
|
||||
// Earlier this lived in an in-memory `MediaCache`, which meant the lookup
|
||||
// table was lost on every restart. This implementation persists everything
|
||||
// alongside the message store so OneBot consumers can always resolve the
|
||||
// media that produced any segment ever stored, even after the bot restarts.
|
||||
//
|
||||
// Schema overview (single SQLite file per UIN, e.g. `data/<uin>/media.db`):
|
||||
// media_entries(type, primary_key, data JSON, last_seen) -- one row per logical media item
|
||||
// media_keys(type, key, primary_key) -- secondary index for every alias
|
||||
//
|
||||
// `rememberImage` / `rememberRecord` upsert exactly one entry row plus one
|
||||
// alias row per identifier (file / fileName / fileId / url). The alias rows
|
||||
// always point to the canonical entry so URL refreshes propagate to every
|
||||
// alias automatically.
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { DatabaseSync, type StatementSync } from 'node:sqlite';
|
||||
import path from 'path';
|
||||
|
||||
import type { MessageElement } from '../bridge/events';
|
||||
|
||||
|
||||
@@ -1,17 +1,3 @@
|
||||
// Resolves the URL for an image / record / video / file element on its
|
||||
// way out of the bridge into an OneBot segment.
|
||||
//
|
||||
// Two steps:
|
||||
// 1. If the bridge event arrived without a `url` (the receive path
|
||||
// sometimes does), fetch a fresh URL from the right Bridge API
|
||||
// based on element.type + isGroup, mutating the element in-place
|
||||
// so any downstream cache sees the URL too.
|
||||
// 2. Apply the cached RKey (the per-UIN signed download key) the
|
||||
// RKeyCache knows about — both to brand-new URLs from step 1 and
|
||||
// to URLs that came in with the event already.
|
||||
//
|
||||
// Used as the `mediaUrlResolver` callback in `ConverterContext`.
|
||||
|
||||
import type { BridgeInterface } from '../bridge/bridge-interface';
|
||||
import type { MessageElement } from '../bridge/events';
|
||||
import type { RKeyCache } from './instance-rkey';
|
||||
@@ -20,7 +6,7 @@ export class MediaUrlResolver {
|
||||
constructor(
|
||||
private readonly bridge: BridgeInterface,
|
||||
private readonly rkeyCache: RKeyCache,
|
||||
) {}
|
||||
) { }
|
||||
|
||||
async resolve(element: MessageElement, isGroup: boolean, sessionId: number): Promise<string> {
|
||||
if (!element.url) {
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
// OneBot11 message segment parser.
|
||||
// Converts OneBot message format (string with CQ codes or JSON segment arrays)
|
||||
// into internal MessageElement arrays for sending.
|
||||
|
||||
import type { MessageElement } from '../bridge/events';
|
||||
import type { JsonValue } from './types';
|
||||
import { createLogger } from '../utils/logger';
|
||||
import type { JsonValue } from './types';
|
||||
|
||||
const log = createLogger('MsgParser');
|
||||
|
||||
@@ -140,12 +136,12 @@ async function segmentToElement(type: string, data: Record<string, unknown>, opt
|
||||
if (options?.resolveReplySequence) {
|
||||
const resolved = options.resolveReplySequence(id);
|
||||
if (typeof resolved === 'number' && resolved > 0) {
|
||||
const element: MessageElement = {
|
||||
type: 'reply',
|
||||
const element: MessageElement = {
|
||||
type: 'reply',
|
||||
replySeq: resolved,
|
||||
replyMessageId: id // Keep the original messageId for logging
|
||||
};
|
||||
|
||||
|
||||
// Try to get additional meta info for better reply display
|
||||
if (options?.resolveReplyMeta) {
|
||||
const meta = options.resolveReplyMeta(id);
|
||||
@@ -155,7 +151,7 @@ async function segmentToElement(type: string, data: Record<string, unknown>, opt
|
||||
element.replyRandom = meta.random;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return element;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
// SQLite-backed message store using node:sqlite (DatabaseSync).
|
||||
// Refactored to use a single unified `messages` table for all message types.
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { DatabaseSync } from 'node:sqlite';
|
||||
import path from 'path';
|
||||
import type { JsonObject, MessageMeta } from './types';
|
||||
|
||||
export class MessageStore {
|
||||
@@ -82,7 +79,7 @@ export class MessageStore {
|
||||
const row = this.db.prepare(
|
||||
'SELECT data FROM messages WHERE message_hash = ? AND data IS NOT NULL',
|
||||
).get(messageId) as { data: string } | undefined;
|
||||
|
||||
|
||||
if (!row?.data) return null;
|
||||
try {
|
||||
return JSON.parse(row.data) as JsonObject;
|
||||
@@ -123,7 +120,7 @@ export class MessageStore {
|
||||
if (!Number.isInteger(sessionId) || sessionId <= 0 || !isValidMessageId(messageId)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
// For private messages, we cannot rely on session_id matching because:
|
||||
// - When receiving: session_id is the sender's UIN
|
||||
// - When sending reply: sessionId parameter is the recipient's UIN (who we're sending to)
|
||||
@@ -141,7 +138,7 @@ export class MessageStore {
|
||||
WHERE is_group = 0 AND message_hash = ?
|
||||
LIMIT 1`
|
||||
).get(messageId) as { sequence: number } | undefined;
|
||||
|
||||
|
||||
if (!row || !Number.isInteger(row.sequence) || row.sequence <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,15 +1,6 @@
|
||||
// Base abstractions for OneBot network adapters.
|
||||
//
|
||||
// Modeled on NapCat's `IOB11NetworkAdapter` so each entry under
|
||||
// `config.networks.{httpServers,httpClients,wsServers,wsClients}` becomes
|
||||
// exactly one adapter instance, identified by `name`. The previous design
|
||||
// rolled multiple servers/clients into a single transport class; the
|
||||
// per-entry split makes hot-reload, lifecycle, and event isolation much
|
||||
// simpler to reason about.
|
||||
|
||||
import type { ApiHandler } from '../api-handler';
|
||||
import type { JsonObject, NetworkBase } from '../types';
|
||||
import type { DispatchPayload } from '../event-filter';
|
||||
import type { JsonObject, NetworkBase } from '../types';
|
||||
|
||||
export interface NetworkAdapterContext {
|
||||
/** Self UIN as string — written into outbound headers. */
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
// Outbound HTTP webhook adapter — one instance per `httpClients[]` entry.
|
||||
//
|
||||
// Forwards every event to the configured URL via HTTP POST and interprets
|
||||
// any JSON response body as a OneBot v11 quick-operation.
|
||||
|
||||
import type { HttpClientNetwork, JsonObject } from '../types';
|
||||
import { createLogger, type Logger } from '../../utils/logger';
|
||||
import {
|
||||
pickDispatchJson,
|
||||
resolveReportOptions,
|
||||
type DispatchPayload,
|
||||
type EventReportOptions,
|
||||
} from '../event-filter';
|
||||
import { createLogger, type Logger } from '../../utils/logger';
|
||||
import type { HttpClientNetwork, JsonObject } from '../types';
|
||||
import { IOneBotNetworkAdapter, NetworkReloadType, type NetworkAdapterContext } from './adapter';
|
||||
import { executeQuickOperation } from './quick-operation';
|
||||
|
||||
|
||||
@@ -1,18 +1,12 @@
|
||||
// Inbound HTTP API server — one instance per `httpServers[]` entry.
|
||||
//
|
||||
// Pure request/response: incoming POST/GET maps to `ApiHandler.handle`,
|
||||
// the response body is JSON-serialized back. `onEvent` is a deliberate
|
||||
// no-op since this transport never pushes events.
|
||||
|
||||
import {
|
||||
createServer,
|
||||
type IncomingMessage,
|
||||
type Server,
|
||||
type ServerResponse,
|
||||
} from 'http';
|
||||
import type { HttpServerNetwork, JsonObject, JsonValue } from '../types';
|
||||
import type { DispatchPayload } from '../event-filter';
|
||||
import { createLogger, type Logger } from '../../utils/logger';
|
||||
import type { DispatchPayload } from '../event-filter';
|
||||
import type { HttpServerNetwork, JsonObject, JsonValue } from '../types';
|
||||
import { IOneBotNetworkAdapter, NetworkReloadType, type NetworkAdapterContext } from './adapter';
|
||||
import { isAuthorized, normalizePath } from './utils';
|
||||
|
||||
@@ -263,4 +257,4 @@ function writeJson(res: ServerResponse, statusCode: number, data: unknown): void
|
||||
res.statusCode = statusCode;
|
||||
res.setHeader('Content-Type', 'application/json; charset=utf-8');
|
||||
res.end(JSON.stringify(data));
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
// Public surface for the OneBot network package.
|
||||
|
||||
export { IOneBotNetworkAdapter, NetworkReloadType, type NetworkAdapterContext } from './adapter';
|
||||
export { OneBotNetworkManager } from './network-manager';
|
||||
export { WsServerAdapter } from './ws-server-adapter';
|
||||
export { WsClientAdapter } from './ws-client-adapter';
|
||||
export { HttpServerAdapter } from './http-server-adapter';
|
||||
export { HttpPostAdapter } from './http-post-adapter';
|
||||
export { HttpServerAdapter } from './http-server-adapter';
|
||||
export { OneBotNetworkManager } from './network-manager';
|
||||
export { executeQuickOperation } from './quick-operation';
|
||||
export { WsClientAdapter } from './ws-client-adapter';
|
||||
export { WsServerAdapter } from './ws-server-adapter';
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
// OneBot network manager.
|
||||
//
|
||||
// Mirrors NapCat's `OB11NetworkManager`: holds a `Map<name, adapter>`, fans
|
||||
// events out to every active adapter in parallel, and provides primitives
|
||||
// the OneBot instance uses to register, hot-reload, and tear adapters down.
|
||||
|
||||
import type { JsonObject, NetworkBase } from '../types';
|
||||
import { buildDispatchPayload } from '../event-filter';
|
||||
import { IOneBotNetworkAdapter } from './adapter';
|
||||
import { createLogger } from '../../utils/logger';
|
||||
import { buildDispatchPayload } from '../event-filter';
|
||||
import type { JsonObject, NetworkBase } from '../types';
|
||||
import { IOneBotNetworkAdapter } from './adapter';
|
||||
|
||||
const log = createLogger('OneBot.Network');
|
||||
|
||||
|
||||
@@ -1,10 +1,3 @@
|
||||
// OneBot v11 hidden API: `.handle_quick_operation`.
|
||||
//
|
||||
// When an HTTP POST event report receives a JSON body in response, that body
|
||||
// is interpreted as a "quick operation" — short-cuts to common follow-up
|
||||
// API calls (reply, recall, ban, kick, approve/reject). Spec:
|
||||
// https://github.com/botuniverse/onebot-11/blob/master/api/hidden.md
|
||||
|
||||
import type { ApiHandler } from '../api-handler';
|
||||
import type { JsonObject, JsonValue } from '../types';
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Helpers shared between OneBot network adapters.
|
||||
|
||||
import type { IncomingMessage } from 'http';
|
||||
import type { WebSocket } from '@snowluma/websocket';
|
||||
import type { IncomingMessage } from 'http';
|
||||
|
||||
/** Validate a request's bearer token / `?access_token=` query against the configured token. */
|
||||
export function isAuthorized(request: IncomingMessage, token: string): boolean {
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
// Reverse (client) WebSocket adapter — one instance per `wsClients[]` entry.
|
||||
//
|
||||
// Connects out to a remote OneBot endpoint, manages reconnects, forwards
|
||||
// pushed events on `onEvent`, and dispatches incoming API messages to the
|
||||
// shared ApiHandler.
|
||||
|
||||
import { WebSocket } from '@snowluma/websocket';
|
||||
import type { WsClientNetwork, WsRole, JsonObject } from '../types';
|
||||
import { createLogger, type Logger } from '../../utils/logger';
|
||||
import {
|
||||
pickDispatchJson,
|
||||
resolveReportOptions,
|
||||
@@ -13,7 +7,7 @@ import {
|
||||
type DispatchPayload,
|
||||
type EventReportOptions,
|
||||
} from '../event-filter';
|
||||
import { createLogger, type Logger } from '../../utils/logger';
|
||||
import type { JsonObject, WsClientNetwork, WsRole } from '../types';
|
||||
import { IOneBotNetworkAdapter, NetworkReloadType, type NetworkAdapterContext } from './adapter';
|
||||
import { rawDataToString, safeClose, safeSend } from './utils';
|
||||
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
// Forward (server) WebSocket adapter — one instance per `wsServers[]` entry.
|
||||
//
|
||||
// Each adapter owns its own `WebSocketServer`, accepts inbound forward
|
||||
// connections (api / event / universal roles), and pushes events to all live
|
||||
// event-receiving sockets when `onEvent` fires.
|
||||
|
||||
import { WebSocket, WebSocketServer } from '@snowluma/websocket';
|
||||
import type { IncomingMessage } from 'http';
|
||||
import type { WsRole, WsServerNetwork, JsonObject } from '../types';
|
||||
import { createLogger, type Logger } from '../../utils/logger';
|
||||
import {
|
||||
pickDispatchJson,
|
||||
resolveReportOptions,
|
||||
@@ -14,9 +8,9 @@ import {
|
||||
type DispatchPayload,
|
||||
type EventReportOptions,
|
||||
} from '../event-filter';
|
||||
import { createLogger, type Logger } from '../../utils/logger';
|
||||
import type { JsonObject, WsRole, WsServerNetwork } from '../types';
|
||||
import { IOneBotNetworkAdapter, NetworkReloadType, type NetworkAdapterContext } from './adapter';
|
||||
import { isAuthorized, parseRequestPath, rawDataToString, safeClose, safeSend, normalizePath } from './utils';
|
||||
import { isAuthorized, normalizePath, parseRequestPath, rawDataToString, safeClose, safeSend } from './utils';
|
||||
|
||||
const moduleLog = createLogger('OneBot.WS-Server');
|
||||
|
||||
|
||||
Reference in new issue
Block a user