diff --git a/src/common/forward-msg-builder.ts b/src/common/forward-msg-builder.ts index 4c18e72e..256e0c35 100644 --- a/src/common/forward-msg-builder.ts +++ b/src/common/forward-msg-builder.ts @@ -55,10 +55,10 @@ export class ForwardMsgBuilder { const isGroupMsg = msg.some(m => m.isGroupMsg); if (!source) { source = isGroupMsg ? "群聊的聊天记录" : - msg.length - ? Array.from(new Set(msg.map(m => m.senderName))) - .join('和') + '的聊天记录' - : '聊天记录'; + msg.length + ? Array.from(new Set(msg.map(m => m.senderName))) + .join('和') + '的聊天记录' + : '聊天记录'; } if (!news) { news = msg.length === 0 ? [{ diff --git a/src/core/apis/file.ts b/src/core/apis/file.ts index 64a325bd..5202850a 100644 --- a/src/core/apis/file.ts +++ b/src/core/apis/file.ts @@ -378,8 +378,8 @@ export class NTQQFileApi { }; try { if (this.core.apis.PacketApi.available) { - let rkey_expired_private = !this.packetRkey || this.packetRkey[0].time + Number(this.packetRkey[0].ttl) < Date.now() / 1000; - let rkey_expired_group = !this.packetRkey || this.packetRkey[0].time + Number(this.packetRkey[0].ttl) < Date.now() / 1000; + const rkey_expired_private = !this.packetRkey || this.packetRkey[0].time + Number(this.packetRkey[0].ttl) < Date.now() / 1000; + const rkey_expired_group = !this.packetRkey || this.packetRkey[0].time + Number(this.packetRkey[0].ttl) < Date.now() / 1000; if (rkey_expired_private || rkey_expired_group) { this.packetRkey = await this.core.apis.PacketApi.sendRkeyPacket(); } diff --git a/src/core/apis/packet.ts b/src/core/apis/packet.ts index 5e18d1cb..22de2b4e 100644 --- a/src/core/apis/packet.ts +++ b/src/core/apis/packet.ts @@ -3,7 +3,7 @@ import { ChatType, InstanceContext, NapCatCore } from '..'; import offset from '@/core/external/offset.json'; import { PacketClient, RecvPacketData } from '@/core/packet/client'; import { PacketSession } from "@/core/packet/session"; -import {OidbPacket, PacketHexStr} from "@/core/packet/packer"; +import { OidbPacket, PacketHexStr } from "@/core/packet/packer"; import { NapProtoMsg } from '@/core/packet/proto/NapProto'; import { OidbSvcTrpcTcp0X9067_202_Rsp_Body } from '@/core/packet/proto/oidb/Oidb.0x9067_202'; import { OidbSvcTrpcTcpBase, OidbSvcTrpcTcpBaseRsp } from '@/core/packet/proto/oidb/OidbBase'; diff --git a/src/core/packet/highway/session.ts b/src/core/packet/highway/session.ts index 0f3ae108..6bbccc2c 100644 --- a/src/core/packet/highway/session.ts +++ b/src/core/packet/highway/session.ts @@ -167,7 +167,7 @@ export class PacketHighwaySession { }); await this.packetHighwayClient.upload( 1004, - fs.createReadStream(img.path, {highWaterMark: BlockSize}), + fs.createReadStream(img.path, { highWaterMark: BlockSize }), img.size, md5, extend @@ -207,7 +207,7 @@ export class PacketHighwaySession { }); await this.packetHighwayClient.upload( 1003, - fs.createReadStream(img.path, {highWaterMark: BlockSize}), + fs.createReadStream(img.path, { highWaterMark: BlockSize }), img.size, md5, extend @@ -244,10 +244,10 @@ export class PacketHighwaySession { hash: { fileSha1: await calculateSha1StreamBytes(video.filePath!) } - }) + }); await this.packetHighwayClient.upload( 1005, - fs.createReadStream(video.filePath!, {highWaterMark: BlockSize}), + fs.createReadStream(video.filePath!, { highWaterMark: BlockSize }), +video.fileSize!, md5, extend @@ -275,7 +275,7 @@ export class PacketHighwaySession { }); await this.packetHighwayClient.upload( 1006, - fs.createReadStream(video.thumbPath!, {highWaterMark: BlockSize}), + fs.createReadStream(video.thumbPath!, { highWaterMark: BlockSize }), +video.thumbSize!, md5, extend @@ -312,10 +312,10 @@ export class PacketHighwaySession { hash: { fileSha1: await calculateSha1StreamBytes(video.filePath!) } - }) + }); await this.packetHighwayClient.upload( 1001, - fs.createReadStream(video.filePath!, {highWaterMark: BlockSize}), + fs.createReadStream(video.filePath!, { highWaterMark: BlockSize }), +video.fileSize!, md5, extend @@ -343,7 +343,7 @@ export class PacketHighwaySession { }); await this.packetHighwayClient.upload( 1002, - fs.createReadStream(video.thumbPath!, {highWaterMark: BlockSize}), + fs.createReadStream(video.thumbPath!, { highWaterMark: BlockSize }), +video.thumbSize!, md5, extend @@ -379,10 +379,10 @@ export class PacketHighwaySession { hash: { fileSha1: [sha1] } - }) + }); await this.packetHighwayClient.upload( 1008, - fs.createReadStream(ptt.filePath, {highWaterMark: BlockSize}), + fs.createReadStream(ptt.filePath, { highWaterMark: BlockSize }), ptt.fileSize, md5, extend @@ -418,10 +418,10 @@ export class PacketHighwaySession { hash: { fileSha1: [sha1] } - }) + }); await this.packetHighwayClient.upload( 1007, - fs.createReadStream(ptt.filePath, {highWaterMark: BlockSize}), + fs.createReadStream(ptt.filePath, { highWaterMark: BlockSize }), ptt.fileSize, md5, extend @@ -484,10 +484,10 @@ export class PacketHighwaySession { } }, unknown200: 0, - }) + }); await this.packetHighwayClient.upload( 71, - fs.createReadStream(file.filePath, {highWaterMark: BlockSize}), + fs.createReadStream(file.filePath, { highWaterMark: BlockSize }), file.fileSize, file.fileMd5, ext @@ -549,10 +549,10 @@ export class PacketHighwaySession { }, unknown200: 1, unknown3: 0 - }) + }); await this.packetHighwayClient.upload( 95, - fs.createReadStream(file.filePath, {highWaterMark: BlockSize}), + fs.createReadStream(file.filePath, { highWaterMark: BlockSize }), file.fileSize, file.fileMd5, ext diff --git a/src/core/packet/highway/uploader.ts b/src/core/packet/highway/uploader.ts index 43acaa1e..49ee5fe7 100644 --- a/src/core/packet/highway/uploader.ts +++ b/src/core/packet/highway/uploader.ts @@ -30,7 +30,7 @@ abstract class HighwayUploader { reject(new Error(`[Highway] timeout after ${this.trans.timeout}s`)); }, (this.trans.timeout ?? Infinity) * 1000 ); - }) + }); } buildPicUpHead(offset: number, bodyLength: number, bodyMd5: Uint8Array): Uint8Array { @@ -100,7 +100,7 @@ export class HighwayTcpUploader extends HighwayUploader { const upload = new Promise((resolve, reject) => { const highwayTransForm = new HighwayTcpUploaderTransform(this); const socket = net.connect(this.trans.port, this.trans.server, () => { - this.trans.data.pipe(highwayTransForm).pipe(socket, {end: false}); + this.trans.data.pipe(highwayTransForm).pipe(socket, { end: false }); }); const handleRspHeader = (header: Buffer) => { const rsp = new NapProtoMsg(RespDataHighwayHead).decode(header); @@ -159,7 +159,7 @@ export class HighwayHttpUploader extends HighwayUploader { try { await this.uploadBlock(block, offset); } catch (err) { - throw new Error(`[Highway] httpUpload Error uploading block at offset ${offset}: ${err}`) + throw new Error(`[Highway] httpUpload Error uploading block at offset ${offset}: ${err}`); } offset += block.length; } diff --git a/src/core/packet/msg/builder.ts b/src/core/packet/msg/builder.ts index eef14eec..15fe5878 100644 --- a/src/core/packet/msg/builder.ts +++ b/src/core/packet/msg/builder.ts @@ -15,9 +15,9 @@ export class PacketMsgBuilder { protected static failBackText = new PacketMsgTextElement( { - textElement: {content: "[该消息类型暂不支持查看]"}! + textElement: { content: "[该消息类型暂不支持查看]" }! } as SendTextElement - ) + ); buildFakeMsg(selfUid: string, element: PacketMsg[]): NapProtoEncodeStructType[] { return element.map((node): NapProtoEncodeStructType => { diff --git a/src/core/packet/msg/element.ts b/src/core/packet/msg/element.ts index 5996e93c..e5808ebb 100644 --- a/src/core/packet/msg/element.ts +++ b/src/core/packet/msg/element.ts @@ -89,11 +89,11 @@ export class PacketMsgAtElement extends PacketMsgTextElement { text: { str: this.text, pbReserve: new NapProtoMsg(MentionExtra).encode({ - type: this.atAll ? 1 : 2, - uin: 0, - field5: 0, - uid: this.targetUid, - } + type: this.atAll ? 1 : 2, + uin: 0, + field5: 0, + uid: this.targetUid, + } ) } }]; @@ -308,7 +308,7 @@ export class PacketMsgVideoElement extends IPacketMsgElement { this.filePath = element.videoElement.filePath; this.thumbSize = element.videoElement.thumbSize; this.thumbPath = element.videoElement.thumbPath?.get(0); - this.fileMd5 = element.videoElement.videoMd5 + this.fileMd5 = element.videoElement.videoMd5; this.thumbMd5 = element.videoElement.thumbMd5; this.thumbWidth = element.videoElement.thumbWidth; this.thumbHeight = element.videoElement.thumbHeight; @@ -355,7 +355,7 @@ export class PacketMsgPttElement extends IPacketMsgElement { } buildElement(): NapProtoEncodeStructType[] { - return [] + return []; // if (!this.msgInfo) return []; // return [{ // commonElem: { @@ -382,7 +382,7 @@ export class PacketMsgFileElement extends IPacketMsgElement { isGroupFile?: boolean; _private_send_uid?: string; _private_recv_uid?: string; - _e37_800_rsp?: NapProtoEncodeStructType + _e37_800_rsp?: NapProtoEncodeStructType; constructor(element: SendFileElement) { super(element); @@ -423,7 +423,7 @@ export class PacketMsgFileElement extends IPacketMsgElement { destUid: this._private_recv_uid, } } - }) + }); } buildElement(): NapProtoEncodeStructType[] { @@ -443,7 +443,7 @@ export class PacketMsgFileElement extends IPacketMsgElement { fileMd5: this.fileMd5, } } - }) + }); lb.writeUInt16BE(transElemVal.length); return [{ transElem: { diff --git a/src/core/packet/packer.ts b/src/core/packet/packer.ts index 95a37a53..5135a871 100644 --- a/src/core/packet/packer.ts +++ b/src/core/packet/packer.ts @@ -61,7 +61,7 @@ export class PacketPacker { return { cmd: `OidbSvcTrpcTcp.0x${cmd.toString(16).toUpperCase()}_${subCmd}`, data: this.packetPacket(data) - } + }; } packPokePacket(peer: number, group?: number): OidbPacket { @@ -114,7 +114,7 @@ export class PacketPacker { packStatusPacket(uin: number): OidbPacket { const oidb_0xfe1_2 = new NapProtoMsg(OidbSvcTrpcTcp0XFE1_2).encode({ uin: uin, - key: [{key: 27372}] + key: [{ key: 27372 }] }); return this.packOidbPacket(0xfe1, 2, oidb_0xfe1_2); } @@ -240,68 +240,68 @@ export class PacketPacker { async packUploadC2CImgReq(peerUin: string, img: PacketMsgPicElement): Promise { const req = new NapProtoMsg(NTV2RichMediaReq).encode({ - reqHead: { - common: { - requestId: 1, - command: 100 + reqHead: { + common: { + requestId: 1, + command: 100 + }, + scene: { + requestType: 2, + businessType: 1, + sceneType: 1, + c2C: { + accountType: 2, + targetUid: peerUin }, - scene: { - requestType: 2, - businessType: 1, - sceneType: 1, - c2C: { - accountType: 2, - targetUid: peerUin + }, + client: { + agentType: 2, + } + }, + upload: { + uploadInfo: [ + { + fileInfo: { + fileSize: +img.size, + fileHash: img.md5, + fileSha1: img.sha1!, + fileName: img.name, + type: { + type: 1, + picFormat: img.picType, //TODO: extend NapCat imgType /cc @MliKiowa + videoFormat: 0, + voiceFormat: 0, + }, + width: img.width, + height: img.height, + time: 0, + original: 1 }, + subFileType: 0, + } + ], + tryFastUploadCompleted: true, + srvSendMsg: false, + clientRandomId: crypto.randomBytes(8).readBigUInt64BE() & BigInt('0x7FFFFFFFFFFFFFFF'), + compatQMsgSceneType: 1, + extBizInfo: { + pic: { + bytesPbReserveTroop: Buffer.from("0800180020004200500062009201009a0100a2010c080012001800200028003a00", 'hex'), + textSummary: "Nya~", // TODO: }, - client: { - agentType: 2, + video: { + bytesPbReserve: Buffer.alloc(0), + }, + ptt: { + bytesPbReserve: Buffer.alloc(0), + bytesReserve: Buffer.alloc(0), + bytesGeneralFlags: Buffer.alloc(0), } }, - upload: { - uploadInfo: [ - { - fileInfo: { - fileSize: +img.size, - fileHash: img.md5, - fileSha1: img.sha1!, - fileName: img.name, - type: { - type: 1, - picFormat: img.picType, //TODO: extend NapCat imgType /cc @MliKiowa - videoFormat: 0, - voiceFormat: 0, - }, - width: img.width, - height: img.height, - time: 0, - original: 1 - }, - subFileType: 0, - } - ], - tryFastUploadCompleted: true, - srvSendMsg: false, - clientRandomId: crypto.randomBytes(8).readBigUInt64BE() & BigInt('0x7FFFFFFFFFFFFFFF'), - compatQMsgSceneType: 1, - extBizInfo: { - pic: { - bytesPbReserveTroop: Buffer.from("0800180020004200500062009201009a0100a2010c080012001800200028003a00", 'hex'), - textSummary: "Nya~", // TODO: - }, - video: { - bytesPbReserve: Buffer.alloc(0), - }, - ptt: { - bytesPbReserve: Buffer.alloc(0), - bytesReserve: Buffer.alloc(0), - bytesGeneralFlags: Buffer.alloc(0), - } - }, - clientSeq: 0, - noNeedCompatMsg: false, - } + clientSeq: 0, + noNeedCompatMsg: false, } + } ); return this.packOidbPacket(0x11c5, 100, req, true, false); } @@ -538,7 +538,7 @@ export class PacketPacker { clientSeq: 0, noNeedCompatMsg: false } - }) + }); return this.packOidbPacket(0x126E, 100, req, true, false); } @@ -600,7 +600,7 @@ export class PacketPacker { clientSeq: 0, noNeedCompatMsg: false } - }) + }); return this.packOidbPacket(0x126D, 100, req, true, false); } @@ -642,7 +642,7 @@ export class PacketPacker { businessId: 3, clientType: 1, flagSupportMediaPlatform: 1 - }) + }); return this.packOidbPacket(0xE37, 1700, body, false, false); } @@ -664,13 +664,13 @@ export class PacketPacker { packGroupFileDownloadReq(groupUin: number, fileUUID: string): OidbPacket { return this.packOidbPacket(0x6D6, 2, new NapProtoMsg(OidbSvcTrpcTcp0x6D6).encode({ - download: { - groupUin: groupUin, - appId: 7, - busId: 102, - fileId: fileUUID - } - }), true, false + download: { + groupUin: groupUin, + appId: 7, + busId: 102, + fileId: fileUUID + } + }), true, false ); } diff --git a/src/core/packet/proto/message/component.ts b/src/core/packet/proto/message/component.ts index c83ed1e9..0981a73e 100644 --- a/src/core/packet/proto/message/component.ts +++ b/src/core/packet/proto/message/component.ts @@ -118,7 +118,7 @@ export const FileExtra = { export const PrivateFileExtra = { field2: ProtoField(2, () => PrivateFileExtraField2), -} +}; export const PrivateFileExtraField2 = { field1: ProtoField(1, ScalarType.UINT32), @@ -131,7 +131,7 @@ export const PrivateFileExtraField2 = { fileHash: ProtoField(14, ScalarType.STRING), selfUid: ProtoField(15, ScalarType.STRING), destUid: ProtoField(16, ScalarType.STRING), -} +}; export const GroupFileExtra = { field1: ProtoField(1, ScalarType.UINT32), diff --git a/src/core/packet/proto/oidb/Oidb.0XE37_800.ts b/src/core/packet/proto/oidb/Oidb.0XE37_800.ts index f2e6fe5b..dc708071 100644 --- a/src/core/packet/proto/oidb/Oidb.0XE37_800.ts +++ b/src/core/packet/proto/oidb/Oidb.0XE37_800.ts @@ -1,6 +1,6 @@ import { ScalarType } from "@protobuf-ts/runtime"; import { ProtoField } from "../NapProto"; -import {OidbSvcTrpcTcp0XE37_800_1200Metadata} from "@/core/packet/proto/oidb/Oidb.0xE37_1200"; +import { OidbSvcTrpcTcp0XE37_800_1200Metadata } from "@/core/packet/proto/oidb/Oidb.0xE37_1200"; export const OidbSvcTrpcTcp0XE37_800 = { subCommand: ProtoField(1, ScalarType.UINT32), @@ -59,4 +59,4 @@ export const OidbSvcTrpcTcp0XE37_800Response = { export const OidbSvcTrpcTcp0XE37_800ResponseBody = { field10: ProtoField(10, ScalarType.UINT32, true), field30: ProtoField(30, () => OidbSvcTrpcTcp0XE37_800_1200Metadata, true), -} +}; diff --git a/src/core/packet/proto/oidb/Oidb.0xE37_1700.ts b/src/core/packet/proto/oidb/Oidb.0xE37_1700.ts index 8d5c3f73..046dff8f 100644 --- a/src/core/packet/proto/oidb/Oidb.0xE37_1700.ts +++ b/src/core/packet/proto/oidb/Oidb.0xE37_1700.ts @@ -8,7 +8,7 @@ export const OidbSvcTrpcTcp0XE37_1700 = { businessId: ProtoField(101, ScalarType.INT32, true), clientType: ProtoField(102, ScalarType.INT32, true), flagSupportMediaPlatform: ProtoField(200, ScalarType.INT32, true), -} +}; export const ApplyUploadReqV3 = { senderUid: ProtoField(10, ScalarType.STRING, true), @@ -20,4 +20,4 @@ export const ApplyUploadReqV3 = { localPath: ProtoField(70, ScalarType.STRING, true), md5CheckSum: ProtoField(110, ScalarType.BYTES, true), sha3CheckSum: ProtoField(120, ScalarType.BYTES, true), -} +}; diff --git a/src/core/packet/proto/oidb/Oidb.0xEB7.ts b/src/core/packet/proto/oidb/Oidb.0xEB7.ts index b5543182..27cf8cee 100644 --- a/src/core/packet/proto/oidb/Oidb.0xEB7.ts +++ b/src/core/packet/proto/oidb/Oidb.0xEB7.ts @@ -9,4 +9,4 @@ export const OidbSvcTrpcTcp0XEB7_Body = { export const OidbSvcTrpcTcp0XEB7 = { body: ProtoField(2, () => OidbSvcTrpcTcp0XEB7_Body), -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/core/packet/utils/crypto/hash.ts b/src/core/packet/utils/crypto/hash.ts index 9576e2c0..56ab7524 100644 --- a/src/core/packet/utils/crypto/hash.ts +++ b/src/core/packet/utils/crypto/hash.ts @@ -2,7 +2,7 @@ import * as crypto from 'crypto'; import * as stream from 'stream'; import * as fs from 'fs'; -import {CalculateStreamBytesTransform} from "@/core/packet/utils/crypto/sha1StreamBytesTransform"; +import { CalculateStreamBytesTransform } from "@/core/packet/utils/crypto/sha1StreamBytesTransform"; function sha1Stream(readable: stream.Readable) { return new Promise((resolve, reject) => { diff --git a/src/core/packet/utils/crypto/sha1Stream.ts b/src/core/packet/utils/crypto/sha1Stream.ts index f1c344df..7eb5421c 100644 --- a/src/core/packet/utils/crypto/sha1Stream.ts +++ b/src/core/packet/utils/crypto/sha1Stream.ts @@ -73,7 +73,7 @@ export class Sha1Stream { this._count[1] = (this._count[1] + (dataLen >>> 29)) >>> 0; - let partLen = (this.Sha1BlockSize - index) >>> 0; + const partLen = (this.Sha1BlockSize - index) >>> 0; let i = 0; if (dataLen >= partLen) { @@ -100,11 +100,11 @@ export class Sha1Stream { public final(): Buffer { const digest = Buffer.allocUnsafe(this.Sha1DigestSize); - const bits = Buffer.allocUnsafe(8) + const bits = Buffer.allocUnsafe(8); bits.writeUInt32BE(this._count[1], 0); bits.writeUInt32BE(this._count[0], 4); - let index = ((this._count[0] >>> 3) & 0x3F) >>> 0; + const index = ((this._count[0] >>> 3) & 0x3F) >>> 0; const padLen = ((index < 56) ? (56 - index) : (120 - index)) >>> 0; this.update(this._padding, padLen); this.update(bits); diff --git a/src/core/packet/utils/crypto/sha1StreamBytesTransform.ts b/src/core/packet/utils/crypto/sha1StreamBytesTransform.ts index 38fd66eb..c6e229db 100644 --- a/src/core/packet/utils/crypto/sha1StreamBytesTransform.ts +++ b/src/core/packet/utils/crypto/sha1StreamBytesTransform.ts @@ -1,5 +1,5 @@ import * as stream from "node:stream"; -import {Sha1Stream} from "@/core/packet/utils/crypto/sha1Stream"; +import { Sha1Stream } from "@/core/packet/utils/crypto/sha1Stream"; export class CalculateStreamBytesTransform extends stream.Transform { private readonly blockSize = 1024 * 1024;