Cleanup imports and formatting in bridge
Reorder and tidy imports, re-export types, and apply minor formatting fixes across the bridge package. Changes include: - Reordered imports and grouped related imports in hook-manager, hook-session, pipe-watcher, qq-hook-client, qq-port-probe and others. - Moved several type re-exports (HookProcessBaseInfo, QqPortLoginInfo, HookProcessInfo/Status) in hook-manager and consolidated exports in package entry index.ts. - Minor whitespace/style tweaks: constructor spacing, for-loop formatting, empty catch handlers, and small refactors that do not change runtime behavior. These are non-functional housekeeping changes to improve consistency and readability.
This commit is contained in:
1 parent
a49e507e15
commit
afbec8ed44
7 files changed
+22
-29
No files matched your search
@@ -1,22 +1,20 @@
|
|||||||
import fs from 'fs';
|
import { createLogger, type Logger } from '@snowluma/common/logger';
|
||||||
import type { PacketSender } from '@snowluma/common/packet-sender';
|
import type { PacketSender } from '@snowluma/common/packet-sender';
|
||||||
import type { PacketInfo, PacketSink } from '@snowluma/common/protocol-types';
|
import type { PacketInfo, PacketSink } from '@snowluma/common/protocol-types';
|
||||||
import { createLogger, type Logger } from '@snowluma/common/logger';
|
import fs from 'fs';
|
||||||
|
import { HookSession, type HookSessionDeps } from './hook-session';
|
||||||
import {
|
import {
|
||||||
injectHookProcess,
|
injectHookProcess,
|
||||||
listHookProcesses,
|
listHookProcesses,
|
||||||
unloadHookProcess,
|
unloadHookProcess,
|
||||||
type HookProcessBaseInfo,
|
type HookProcessBaseInfo,
|
||||||
} from './injector';
|
} from './injector';
|
||||||
import { HookSession, type HookSessionDeps } from './hook-session';
|
|
||||||
import { PipeWatcher } from './pipe-watcher';
|
import { PipeWatcher } from './pipe-watcher';
|
||||||
import { QqHookClient } from './qq-hook-client';
|
import { QqHookClient } from './qq-hook-client';
|
||||||
import type { HookProcessInfo } from './types';
|
|
||||||
import { probeQqLoginInfo, type QqPortLoginInfo } from './qq-port-probe';
|
import { probeQqLoginInfo, type QqPortLoginInfo } from './qq-port-probe';
|
||||||
|
import type { HookProcessInfo } from './types';
|
||||||
|
|
||||||
|
|
||||||
export type { HookProcessInfo, HookProcessStatus } from './types';
|
|
||||||
export type { HookProcessBaseInfo } from './injector';
|
|
||||||
export type { QqPortLoginInfo } from './qq-port-probe';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sink that the hook layer calls back into when it observes a new login,
|
* Sink that the hook layer calls back into when it observes a new login,
|
||||||
@@ -229,7 +227,7 @@ export class HookManager {
|
|||||||
if (this.disposed) return;
|
if (this.disposed) return;
|
||||||
for (const session of this.sessions.values()) {
|
for (const session of this.sessions.values()) {
|
||||||
if ((session.status === 'connecting' || session.status === 'disconnected')
|
if ((session.status === 'connecting' || session.status === 'disconnected')
|
||||||
&& this.pipeWatcher.isPipeLive(session.pid)) {
|
&& this.pipeWatcher.isPipeLive(session.pid)) {
|
||||||
session.onPipeUp();
|
session.onPipeUp();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -311,3 +309,6 @@ export function shouldAutoLoadPid(pid: number, log: Logger): boolean {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
export type { HookProcessBaseInfo } from './injector';
|
||||||
|
export type { QqPortLoginInfo } from './qq-port-probe';
|
||||||
|
export type { HookProcessInfo, HookProcessStatus } from './types';
|
||||||
@@ -2,7 +2,7 @@ import type { PacketSender, SendPacketResult } from '@snowluma/common/packet-sen
|
|||||||
import { QqHookClient, type QqHookSendReply } from './qq-hook-client';
|
import { QqHookClient, type QqHookSendReply } from './qq-hook-client';
|
||||||
|
|
||||||
export class HookPacketClient implements PacketSender {
|
export class HookPacketClient implements PacketSender {
|
||||||
constructor(private readonly client: QqHookClient) {}
|
constructor(private readonly client: QqHookClient) { }
|
||||||
|
|
||||||
async sendPacket(serviceCmd: string, body: Buffer, timeoutMs = 15000): Promise<SendPacketResult> {
|
async sendPacket(serviceCmd: string, body: Buffer, timeoutMs = 15000): Promise<SendPacketResult> {
|
||||||
if (!this.client.isLoggedIn) {
|
if (!this.client.isLoggedIn) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { EventEmitter } from 'events';
|
|
||||||
import type { PacketSink } from '@snowluma/common/protocol-types';
|
|
||||||
import { createLogger, type Logger } from '@snowluma/common/logger';
|
import { createLogger, type Logger } from '@snowluma/common/logger';
|
||||||
|
import type { PacketSink } from '@snowluma/common/protocol-types';
|
||||||
|
import { EventEmitter } from 'events';
|
||||||
import { HookPacketClient } from './hook-packet-client';
|
import { HookPacketClient } from './hook-packet-client';
|
||||||
import type { HookInjectResult } from './injector';
|
import type { HookInjectResult } from './injector';
|
||||||
import type { QqHookClient, QqHookLoginState, QqHookPacket } from './qq-hook-client';
|
import type { QqHookClient, QqHookLoginState, QqHookPacket } from './qq-hook-client';
|
||||||
|
|||||||
@@ -1,13 +1,5 @@
|
|||||||
// Public entry — re-exports the hook orchestration surface that the
|
|
||||||
// top-level app (and webui readers) consume. Everything else is
|
|
||||||
// internal to the package.
|
|
||||||
|
|
||||||
export {
|
export {
|
||||||
HookManager,
|
HookManager, type BridgeManagerSink, type HookManagerDeps, type HookProcessBaseInfo, type HookProcessInfo,
|
||||||
type HookManagerDeps,
|
type HookProcessStatus, type QqPortLoginInfo
|
||||||
type BridgeManagerSink,
|
|
||||||
type HookProcessInfo,
|
|
||||||
type HookProcessStatus,
|
|
||||||
type HookProcessBaseInfo,
|
|
||||||
type QqPortLoginInfo,
|
|
||||||
} from './hook-manager';
|
} from './hook-manager';
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { EventEmitter } from 'events';
|
|
||||||
import { createLogger, type Logger } from '@snowluma/common/logger';
|
import { createLogger, type Logger } from '@snowluma/common/logger';
|
||||||
|
import { EventEmitter } from 'events';
|
||||||
import type { HookProcessBaseInfo } from './injector';
|
import type { HookProcessBaseInfo } from './injector';
|
||||||
|
|
||||||
const DEFAULT_INTERVAL_MS = 1500;
|
const DEFAULT_INTERVAL_MS = 1500;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
|
import { EventEmitter } from 'events';
|
||||||
|
import { promises as fs } from 'fs';
|
||||||
import net from 'net';
|
import net from 'net';
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { promises as fs } from 'fs';
|
|
||||||
import { EventEmitter } from 'events';
|
|
||||||
|
|
||||||
export const PIPE_MAGIC = 0x31504851;
|
export const PIPE_MAGIC = 0x31504851;
|
||||||
export const PIPE_VERSION = 1;
|
export const PIPE_VERSION = 1;
|
||||||
@@ -235,7 +235,7 @@ function encodeFrame({
|
|||||||
class FrameReader {
|
class FrameReader {
|
||||||
private buffer = Buffer.alloc(0);
|
private buffer = Buffer.alloc(0);
|
||||||
|
|
||||||
constructor(private readonly onFrame: (frame: PipeFrame) => void) {}
|
constructor(private readonly onFrame: (frame: PipeFrame) => void) { }
|
||||||
|
|
||||||
push(chunk: Buffer): void {
|
push(chunk: Buffer): void {
|
||||||
this.buffer = Buffer.concat([this.buffer, chunk]);
|
this.buffer = Buffer.concat([this.buffer, chunk]);
|
||||||
@@ -513,7 +513,7 @@ export class QqHookClient extends EventEmitter {
|
|||||||
const workerCount = Math.max(1, Math.min(concurrency | 0, items.length || 1));
|
const workerCount = Math.max(1, Math.min(concurrency | 0, items.length || 1));
|
||||||
|
|
||||||
const worker = async () => {
|
const worker = async () => {
|
||||||
for (;;) {
|
for (; ;) {
|
||||||
const index = nextIndex;
|
const index = nextIndex;
|
||||||
nextIndex += 1;
|
nextIndex += 1;
|
||||||
if (index >= items.length) return;
|
if (index >= items.length) return;
|
||||||
@@ -624,7 +624,7 @@ export class QqHookClient extends EventEmitter {
|
|||||||
else resolve();
|
else resolve();
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
this.controlWriteChain = writePromise.catch(() => {});
|
this.controlWriteChain = writePromise.catch(() => { });
|
||||||
return writePromise;
|
return writePromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import net from 'net';
|
|
||||||
import { exec } from 'child_process';
|
import { exec } from 'child_process';
|
||||||
|
import net from 'net';
|
||||||
import { promisify } from 'util';
|
import { promisify } from 'util';
|
||||||
|
|
||||||
const execAsync = promisify(exec);
|
const execAsync = promisify(exec);
|
||||||
|
|||||||
Reference in new issue
Block a user