style: lint

This commit is contained in:
手瓜一十雪 2024-10-25 18:09:41 +08:00
parent dac6709f27
commit 63f746c237
15 changed files with 118 additions and 118 deletions

View File

@ -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 ? [{

View File

@ -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();
}

View File

@ -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';

View File

@ -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

View File

@ -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<void>((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;
}

View File

@ -15,9 +15,9 @@ export class PacketMsgBuilder {
protected static failBackText = new PacketMsgTextElement(
{
textElement: {content: "[该消息类型暂不支持查看]"}!
textElement: { content: "[该消息类型暂不支持查看]" }!
} as SendTextElement
)
);
buildFakeMsg(selfUid: string, element: PacketMsg[]): NapProtoEncodeStructType<typeof PushMsgBody>[] {
return element.map((node): NapProtoEncodeStructType<typeof PushMsgBody> => {

View File

@ -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<SendVideoElement> {
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<SendPttElement> {
}
buildElement(): NapProtoEncodeStructType<typeof Elem>[] {
return []
return [];
// if (!this.msgInfo) return [];
// return [{
// commonElem: {
@ -382,7 +382,7 @@ export class PacketMsgFileElement extends IPacketMsgElement<SendFileElement> {
isGroupFile?: boolean;
_private_send_uid?: string;
_private_recv_uid?: string;
_e37_800_rsp?: NapProtoEncodeStructType<typeof OidbSvcTrpcTcp0XE37_800Response>
_e37_800_rsp?: NapProtoEncodeStructType<typeof OidbSvcTrpcTcp0XE37_800Response>;
constructor(element: SendFileElement) {
super(element);
@ -423,7 +423,7 @@ export class PacketMsgFileElement extends IPacketMsgElement<SendFileElement> {
destUid: this._private_recv_uid,
}
}
})
});
}
buildElement(): NapProtoEncodeStructType<typeof Elem>[] {
@ -443,7 +443,7 @@ export class PacketMsgFileElement extends IPacketMsgElement<SendFileElement> {
fileMd5: this.fileMd5,
}
}
})
});
lb.writeUInt16BE(transElemVal.length);
return [{
transElem: {

View File

@ -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<OidbPacket> {
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
);
}

View File

@ -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),

View File

@ -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),
}
};

View File

@ -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),
}
};

View File

@ -9,4 +9,4 @@ export const OidbSvcTrpcTcp0XEB7_Body = {
export const OidbSvcTrpcTcp0XEB7 = {
body: ProtoField(2, () => OidbSvcTrpcTcp0XEB7_Body),
}
};

View File

@ -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) => {

View File

@ -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);

View File

@ -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;