mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
fix
This commit is contained in:
parent
76b404cdd8
commit
21b228552d
@ -2,6 +2,7 @@ import { Data, WebSocket } from "ws";
|
|||||||
import { IPacketClient, RecvPacket } from "@/core/packet/client/baseClient";
|
import { IPacketClient, RecvPacket } from "@/core/packet/client/baseClient";
|
||||||
import { PacketContext } from "@/core/packet/context/packetContext";
|
import { PacketContext } from "@/core/packet/context/packetContext";
|
||||||
import { LogStack } from "@/core/packet/context/clientContext";
|
import { LogStack } from "@/core/packet/context/clientContext";
|
||||||
|
import { ErrorEvent } from "ws";
|
||||||
|
|
||||||
export class WsPacketClient extends IPacketClient {
|
export class WsPacketClient extends IPacketClient {
|
||||||
private websocket: WebSocket | null = null;
|
private websocket: WebSocket | null = null;
|
||||||
@ -85,11 +86,11 @@ export class WsPacketClient extends IPacketClient {
|
|||||||
this.websocket.onmessage = (event) => this.handleMessage(event.data).catch(err => {
|
this.websocket.onmessage = (event) => this.handleMessage(event.data).catch(err => {
|
||||||
this.context.logger.error(`处理消息时出错: ${err}`);
|
this.context.logger.error(`处理消息时出错: ${err}`);
|
||||||
});
|
});
|
||||||
this.websocket.onerror = (error) => {
|
this.websocket.onerror = (event: ErrorEvent) => {
|
||||||
this.available = false;
|
this.available = false;
|
||||||
this.context.logger.error(`WebSocket 出错: ${error.message}`);
|
this.context.logger.error(`WebSocket 出错: ${event.message}`);
|
||||||
this.websocket?.close();
|
this.websocket?.close();
|
||||||
reject(error);
|
reject(new Error(`WebSocket 出错: ${event.message}`));
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ export class PacketClientSession {
|
|||||||
return this.context.operation;
|
return this.context.operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: global message element adapter (?
|
// work: global message element adapter (?
|
||||||
get msgConverter() {
|
get msgConverter() {
|
||||||
return this.context.msgConverter;
|
return this.context.msgConverter;
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ const clientPriority: clientPriority = {
|
|||||||
|
|
||||||
export class LogStack {
|
export class LogStack {
|
||||||
private stack: string[] = [];
|
private stack: string[] = [];
|
||||||
private logger: PacketLogger;
|
private readonly logger: PacketLogger;
|
||||||
|
|
||||||
constructor(logger: PacketLogger) {
|
constructor(logger: PacketLogger) {
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
@ -82,25 +82,28 @@ export class PacketClientContext {
|
|||||||
const prefer = this.context.napcore.config.packetBackend;
|
const prefer = this.context.napcore.config.packetBackend;
|
||||||
let client: IPacketClient | null;
|
let client: IPacketClient | null;
|
||||||
switch (prefer) {
|
switch (prefer) {
|
||||||
case "native":
|
case "native":
|
||||||
this.context.logger.info("使用指定的 NativePacketClient 作为后端");
|
this.context.logger.info("使用指定的 NativePacketClient 作为后端");
|
||||||
client = new NativePacketClient(this.context, this.logStack);
|
client = new NativePacketClient(this.context, this.logStack);
|
||||||
break;
|
break;
|
||||||
case "frida":
|
case "frida":
|
||||||
this.context.logger.info("[Core] [Packet] 使用指定的 FridaPacketClient 作为后端");
|
this.context.logger.info("[Core] [Packet] 使用指定的 FridaPacketClient 作为后端");
|
||||||
client = new WsPacketClient(this.context, this.logStack);
|
client = new WsPacketClient(this.context, this.logStack);
|
||||||
break;
|
break;
|
||||||
case "auto":
|
case "auto":
|
||||||
case undefined:
|
case undefined:
|
||||||
client = this.judgeClient();
|
client = this.judgeClient();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
this.context.logger.error(`未知的PacketBackend ${prefer},请检查配置文件!`);
|
this.context.logger.error(`未知的PacketBackend ${prefer},请检查配置文件!`);
|
||||||
client = null;
|
client = null;
|
||||||
}
|
}
|
||||||
if (!(client && client.check())) {
|
if (!client?.check()) {
|
||||||
throw new Error("[Core] [Packet] 无可用的后端,NapCat.Packet将不会加载!");
|
throw new Error("[Core] [Packet] 无可用的后端,NapCat.Packet将不会加载!");
|
||||||
}
|
}
|
||||||
|
if (!client) {
|
||||||
|
throw new Error("[Core] [Packet] 后端异常,NapCat.Packet将不会加载!");
|
||||||
|
}
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { LogLevel, LogWrapper } from "@/common/log";
|
import { LogLevel, LogWrapper } from "@/common/log";
|
||||||
import { PacketContext } from "@/core/packet/context/packetContext";
|
import { PacketContext } from "@/core/packet/context/packetContext";
|
||||||
|
|
||||||
// TODO: check bind?
|
// work: check bind?
|
||||||
export class PacketLogger {
|
export class PacketLogger {
|
||||||
private readonly napLogger: LogWrapper;
|
private readonly napLogger: LogWrapper;
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ export interface PacketHighwaySig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class PacketHighwayContext {
|
export class PacketHighwayContext {
|
||||||
private context: PacketContext;
|
private readonly context: PacketContext;
|
||||||
protected sig: PacketHighwaySig;
|
protected sig: PacketHighwaySig;
|
||||||
protected logger: PacketLogger;
|
protected logger: PacketLogger;
|
||||||
protected hwClient: PacketHighwayClient;
|
protected hwClient: PacketHighwayClient;
|
||||||
@ -223,7 +223,7 @@ export class PacketHighwayContext {
|
|||||||
msgInfoBody: preRespData.upload.msgInfo.msgInfoBody,
|
msgInfoBody: preRespData.upload.msgInfo.msgInfoBody,
|
||||||
blockSize: BlockSize,
|
blockSize: BlockSize,
|
||||||
hash: {
|
hash: {
|
||||||
fileSha1: await calculateSha1StreamBytes(video.filePath!)
|
fileSha1: await calculateSha1StreamBytes(video.filePath)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
await this.hwClient.upload(
|
await this.hwClient.upload(
|
||||||
@ -288,7 +288,7 @@ export class PacketHighwayContext {
|
|||||||
msgInfoBody: preRespData.upload.msgInfo.msgInfoBody,
|
msgInfoBody: preRespData.upload.msgInfo.msgInfoBody,
|
||||||
blockSize: BlockSize,
|
blockSize: BlockSize,
|
||||||
hash: {
|
hash: {
|
||||||
fileSha1: await calculateSha1StreamBytes(video.filePath!)
|
fileSha1: await calculateSha1StreamBytes(video.filePath)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
await this.hwClient.upload(
|
await this.hwClient.upload(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user