style: lint
This commit is contained in:
1 parent
a9201826a6
commit
0dc6aa46d0
27 files changed
+167
-167
No files matched your search
+14
-14
@@ -1,9 +1,9 @@
|
||||
import {LogWrapper} from "@/common/log";
|
||||
import {LRUCache} from "@/common/lru-cache";
|
||||
import WebSocket, {Data} from "ws";
|
||||
import crypto, {createHash} from "crypto";
|
||||
import {NapCatCore} from "@/core";
|
||||
import {PacketHexStr} from "@/core/packet/packer";
|
||||
import { LogWrapper } from "@/common/log";
|
||||
import { LRUCache } from "@/common/lru-cache";
|
||||
import WebSocket, { Data } from "ws";
|
||||
import crypto, { createHash } from "crypto";
|
||||
import { NapCatCore } from "@/core";
|
||||
import { PacketHexStr } from "@/core/packet/packer";
|
||||
|
||||
export interface RecvPacket {
|
||||
type: string, // 仅recv
|
||||
@@ -24,7 +24,7 @@ export class PacketClient {
|
||||
private maxReconnectAttempts: number = 5;
|
||||
private cb = new LRUCache<string, (json: RecvPacketData) => Promise<void>>(500); // trace_id-type callback
|
||||
private readonly clientUrl: string = '';
|
||||
private readonly napCatCore: NapCatCore
|
||||
private readonly napCatCore: NapCatCore;
|
||||
private readonly logger: LogWrapper;
|
||||
|
||||
constructor(url: string, core: NapCatCore) {
|
||||
@@ -39,7 +39,7 @@ export class PacketClient {
|
||||
|
||||
private randText(len: number) {
|
||||
let text = '';
|
||||
let possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
for (let i = 0; i < len; i++) {
|
||||
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
||||
}
|
||||
@@ -147,10 +147,10 @@ export class PacketClient {
|
||||
|
||||
private async handleMessage(message: Data): Promise<void> {
|
||||
try {
|
||||
let json: RecvPacket = JSON.parse(message.toString());
|
||||
let trace_id_md5 = json.trace_id_md5;
|
||||
let action = json?.type ?? 'init';
|
||||
let event = this.cb.get(trace_id_md5 + action);
|
||||
const json: RecvPacket = JSON.parse(message.toString());
|
||||
const trace_id_md5 = json.trace_id_md5;
|
||||
const action = json?.type ?? 'init';
|
||||
const event = this.cb.get(trace_id_md5 + action);
|
||||
if (event) {
|
||||
await event(json.data);
|
||||
}
|
||||
@@ -168,8 +168,8 @@ export class PacketClient {
|
||||
this.logger.logError('NapCat.Packet is not init');
|
||||
return undefined;
|
||||
}
|
||||
let md5 = crypto.createHash('md5').update(data).digest('hex');
|
||||
let trace_id = (this.randText(4) + md5 + data).slice(0, data.length / 2);
|
||||
const md5 = crypto.createHash('md5').update(data).digest('hex');
|
||||
const trace_id = (this.randText(4) + md5 + data).slice(0, data.length / 2);
|
||||
this.sendCommand(cmd, data, trace_id, rsp, 5000, async () => {
|
||||
await this.napCatCore.context.session.getMsgService().sendSsoCmdReqByContend(cmd, trace_id);
|
||||
}).then((res) => resolve(res)).catch((e) => reject(e));
|
||||
|
||||
Reference in new issue
Block a user