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

@ -378,8 +378,8 @@ export class NTQQFileApi {
}; };
try { try {
if (this.core.apis.PacketApi.available) { if (this.core.apis.PacketApi.available) {
let rkey_expired_private = !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;
let rkey_expired_group = !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) { if (rkey_expired_private || rkey_expired_group) {
this.packetRkey = await this.core.apis.PacketApi.sendRkeyPacket(); 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 offset from '@/core/external/offset.json';
import { PacketClient, RecvPacketData } from '@/core/packet/client'; import { PacketClient, RecvPacketData } from '@/core/packet/client';
import { PacketSession } from "@/core/packet/session"; 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 { NapProtoMsg } from '@/core/packet/proto/NapProto';
import { OidbSvcTrpcTcp0X9067_202_Rsp_Body } from '@/core/packet/proto/oidb/Oidb.0x9067_202'; import { OidbSvcTrpcTcp0X9067_202_Rsp_Body } from '@/core/packet/proto/oidb/Oidb.0x9067_202';
import { OidbSvcTrpcTcpBase, OidbSvcTrpcTcpBaseRsp } from '@/core/packet/proto/oidb/OidbBase'; import { OidbSvcTrpcTcpBase, OidbSvcTrpcTcpBaseRsp } from '@/core/packet/proto/oidb/OidbBase';

View File

@ -167,7 +167,7 @@ export class PacketHighwaySession {
}); });
await this.packetHighwayClient.upload( await this.packetHighwayClient.upload(
1004, 1004,
fs.createReadStream(img.path, {highWaterMark: BlockSize}), fs.createReadStream(img.path, { highWaterMark: BlockSize }),
img.size, img.size,
md5, md5,
extend extend
@ -207,7 +207,7 @@ export class PacketHighwaySession {
}); });
await this.packetHighwayClient.upload( await this.packetHighwayClient.upload(
1003, 1003,
fs.createReadStream(img.path, {highWaterMark: BlockSize}), fs.createReadStream(img.path, { highWaterMark: BlockSize }),
img.size, img.size,
md5, md5,
extend extend
@ -244,10 +244,10 @@ export class PacketHighwaySession {
hash: { hash: {
fileSha1: await calculateSha1StreamBytes(video.filePath!) fileSha1: await calculateSha1StreamBytes(video.filePath!)
} }
}) });
await this.packetHighwayClient.upload( await this.packetHighwayClient.upload(
1005, 1005,
fs.createReadStream(video.filePath!, {highWaterMark: BlockSize}), fs.createReadStream(video.filePath!, { highWaterMark: BlockSize }),
+video.fileSize!, +video.fileSize!,
md5, md5,
extend extend
@ -275,7 +275,7 @@ export class PacketHighwaySession {
}); });
await this.packetHighwayClient.upload( await this.packetHighwayClient.upload(
1006, 1006,
fs.createReadStream(video.thumbPath!, {highWaterMark: BlockSize}), fs.createReadStream(video.thumbPath!, { highWaterMark: BlockSize }),
+video.thumbSize!, +video.thumbSize!,
md5, md5,
extend extend
@ -312,10 +312,10 @@ export class PacketHighwaySession {
hash: { hash: {
fileSha1: await calculateSha1StreamBytes(video.filePath!) fileSha1: await calculateSha1StreamBytes(video.filePath!)
} }
}) });
await this.packetHighwayClient.upload( await this.packetHighwayClient.upload(
1001, 1001,
fs.createReadStream(video.filePath!, {highWaterMark: BlockSize}), fs.createReadStream(video.filePath!, { highWaterMark: BlockSize }),
+video.fileSize!, +video.fileSize!,
md5, md5,
extend extend
@ -343,7 +343,7 @@ export class PacketHighwaySession {
}); });
await this.packetHighwayClient.upload( await this.packetHighwayClient.upload(
1002, 1002,
fs.createReadStream(video.thumbPath!, {highWaterMark: BlockSize}), fs.createReadStream(video.thumbPath!, { highWaterMark: BlockSize }),
+video.thumbSize!, +video.thumbSize!,
md5, md5,
extend extend
@ -379,10 +379,10 @@ export class PacketHighwaySession {
hash: { hash: {
fileSha1: [sha1] fileSha1: [sha1]
} }
}) });
await this.packetHighwayClient.upload( await this.packetHighwayClient.upload(
1008, 1008,
fs.createReadStream(ptt.filePath, {highWaterMark: BlockSize}), fs.createReadStream(ptt.filePath, { highWaterMark: BlockSize }),
ptt.fileSize, ptt.fileSize,
md5, md5,
extend extend
@ -418,10 +418,10 @@ export class PacketHighwaySession {
hash: { hash: {
fileSha1: [sha1] fileSha1: [sha1]
} }
}) });
await this.packetHighwayClient.upload( await this.packetHighwayClient.upload(
1007, 1007,
fs.createReadStream(ptt.filePath, {highWaterMark: BlockSize}), fs.createReadStream(ptt.filePath, { highWaterMark: BlockSize }),
ptt.fileSize, ptt.fileSize,
md5, md5,
extend extend
@ -484,10 +484,10 @@ export class PacketHighwaySession {
} }
}, },
unknown200: 0, unknown200: 0,
}) });
await this.packetHighwayClient.upload( await this.packetHighwayClient.upload(
71, 71,
fs.createReadStream(file.filePath, {highWaterMark: BlockSize}), fs.createReadStream(file.filePath, { highWaterMark: BlockSize }),
file.fileSize, file.fileSize,
file.fileMd5, file.fileMd5,
ext ext
@ -549,10 +549,10 @@ export class PacketHighwaySession {
}, },
unknown200: 1, unknown200: 1,
unknown3: 0 unknown3: 0
}) });
await this.packetHighwayClient.upload( await this.packetHighwayClient.upload(
95, 95,
fs.createReadStream(file.filePath, {highWaterMark: BlockSize}), fs.createReadStream(file.filePath, { highWaterMark: BlockSize }),
file.fileSize, file.fileSize,
file.fileMd5, file.fileMd5,
ext ext

View File

@ -30,7 +30,7 @@ abstract class HighwayUploader {
reject(new Error(`[Highway] timeout after ${this.trans.timeout}s`)); reject(new Error(`[Highway] timeout after ${this.trans.timeout}s`));
}, (this.trans.timeout ?? Infinity) * 1000 }, (this.trans.timeout ?? Infinity) * 1000
); );
}) });
} }
buildPicUpHead(offset: number, bodyLength: number, bodyMd5: Uint8Array): Uint8Array { 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 upload = new Promise<void>((resolve, reject) => {
const highwayTransForm = new HighwayTcpUploaderTransform(this); const highwayTransForm = new HighwayTcpUploaderTransform(this);
const socket = net.connect(this.trans.port, this.trans.server, () => { 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 handleRspHeader = (header: Buffer) => {
const rsp = new NapProtoMsg(RespDataHighwayHead).decode(header); const rsp = new NapProtoMsg(RespDataHighwayHead).decode(header);
@ -159,7 +159,7 @@ export class HighwayHttpUploader extends HighwayUploader {
try { try {
await this.uploadBlock(block, offset); await this.uploadBlock(block, offset);
} catch (err) { } 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; offset += block.length;
} }

View File

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

View File

@ -308,7 +308,7 @@ export class PacketMsgVideoElement extends IPacketMsgElement<SendVideoElement> {
this.filePath = element.videoElement.filePath; this.filePath = element.videoElement.filePath;
this.thumbSize = element.videoElement.thumbSize; this.thumbSize = element.videoElement.thumbSize;
this.thumbPath = element.videoElement.thumbPath?.get(0); this.thumbPath = element.videoElement.thumbPath?.get(0);
this.fileMd5 = element.videoElement.videoMd5 this.fileMd5 = element.videoElement.videoMd5;
this.thumbMd5 = element.videoElement.thumbMd5; this.thumbMd5 = element.videoElement.thumbMd5;
this.thumbWidth = element.videoElement.thumbWidth; this.thumbWidth = element.videoElement.thumbWidth;
this.thumbHeight = element.videoElement.thumbHeight; this.thumbHeight = element.videoElement.thumbHeight;
@ -355,7 +355,7 @@ export class PacketMsgPttElement extends IPacketMsgElement<SendPttElement> {
} }
buildElement(): NapProtoEncodeStructType<typeof Elem>[] { buildElement(): NapProtoEncodeStructType<typeof Elem>[] {
return [] return [];
// if (!this.msgInfo) return []; // if (!this.msgInfo) return [];
// return [{ // return [{
// commonElem: { // commonElem: {
@ -382,7 +382,7 @@ export class PacketMsgFileElement extends IPacketMsgElement<SendFileElement> {
isGroupFile?: boolean; isGroupFile?: boolean;
_private_send_uid?: string; _private_send_uid?: string;
_private_recv_uid?: string; _private_recv_uid?: string;
_e37_800_rsp?: NapProtoEncodeStructType<typeof OidbSvcTrpcTcp0XE37_800Response> _e37_800_rsp?: NapProtoEncodeStructType<typeof OidbSvcTrpcTcp0XE37_800Response>;
constructor(element: SendFileElement) { constructor(element: SendFileElement) {
super(element); super(element);
@ -423,7 +423,7 @@ export class PacketMsgFileElement extends IPacketMsgElement<SendFileElement> {
destUid: this._private_recv_uid, destUid: this._private_recv_uid,
} }
} }
}) });
} }
buildElement(): NapProtoEncodeStructType<typeof Elem>[] { buildElement(): NapProtoEncodeStructType<typeof Elem>[] {
@ -443,7 +443,7 @@ export class PacketMsgFileElement extends IPacketMsgElement<SendFileElement> {
fileMd5: this.fileMd5, fileMd5: this.fileMd5,
} }
} }
}) });
lb.writeUInt16BE(transElemVal.length); lb.writeUInt16BE(transElemVal.length);
return [{ return [{
transElem: { transElem: {

View File

@ -61,7 +61,7 @@ export class PacketPacker {
return { return {
cmd: `OidbSvcTrpcTcp.0x${cmd.toString(16).toUpperCase()}_${subCmd}`, cmd: `OidbSvcTrpcTcp.0x${cmd.toString(16).toUpperCase()}_${subCmd}`,
data: this.packetPacket(data) data: this.packetPacket(data)
} };
} }
packPokePacket(peer: number, group?: number): OidbPacket { packPokePacket(peer: number, group?: number): OidbPacket {
@ -114,7 +114,7 @@ export class PacketPacker {
packStatusPacket(uin: number): OidbPacket { packStatusPacket(uin: number): OidbPacket {
const oidb_0xfe1_2 = new NapProtoMsg(OidbSvcTrpcTcp0XFE1_2).encode({ const oidb_0xfe1_2 = new NapProtoMsg(OidbSvcTrpcTcp0XFE1_2).encode({
uin: uin, uin: uin,
key: [{key: 27372}] key: [{ key: 27372 }]
}); });
return this.packOidbPacket(0xfe1, 2, oidb_0xfe1_2); return this.packOidbPacket(0xfe1, 2, oidb_0xfe1_2);
} }
@ -538,7 +538,7 @@ export class PacketPacker {
clientSeq: 0, clientSeq: 0,
noNeedCompatMsg: false noNeedCompatMsg: false
} }
}) });
return this.packOidbPacket(0x126E, 100, req, true, false); return this.packOidbPacket(0x126E, 100, req, true, false);
} }
@ -600,7 +600,7 @@ export class PacketPacker {
clientSeq: 0, clientSeq: 0,
noNeedCompatMsg: false noNeedCompatMsg: false
} }
}) });
return this.packOidbPacket(0x126D, 100, req, true, false); return this.packOidbPacket(0x126D, 100, req, true, false);
} }
@ -642,7 +642,7 @@ export class PacketPacker {
businessId: 3, businessId: 3,
clientType: 1, clientType: 1,
flagSupportMediaPlatform: 1 flagSupportMediaPlatform: 1
}) });
return this.packOidbPacket(0xE37, 1700, body, false, false); return this.packOidbPacket(0xE37, 1700, body, false, false);
} }

View File

@ -118,7 +118,7 @@ export const FileExtra = {
export const PrivateFileExtra = { export const PrivateFileExtra = {
field2: ProtoField(2, () => PrivateFileExtraField2), field2: ProtoField(2, () => PrivateFileExtraField2),
} };
export const PrivateFileExtraField2 = { export const PrivateFileExtraField2 = {
field1: ProtoField(1, ScalarType.UINT32), field1: ProtoField(1, ScalarType.UINT32),
@ -131,7 +131,7 @@ export const PrivateFileExtraField2 = {
fileHash: ProtoField(14, ScalarType.STRING), fileHash: ProtoField(14, ScalarType.STRING),
selfUid: ProtoField(15, ScalarType.STRING), selfUid: ProtoField(15, ScalarType.STRING),
destUid: ProtoField(16, ScalarType.STRING), destUid: ProtoField(16, ScalarType.STRING),
} };
export const GroupFileExtra = { export const GroupFileExtra = {
field1: ProtoField(1, ScalarType.UINT32), field1: ProtoField(1, ScalarType.UINT32),

View File

@ -1,6 +1,6 @@
import { ScalarType } from "@protobuf-ts/runtime"; import { ScalarType } from "@protobuf-ts/runtime";
import { ProtoField } from "../NapProto"; 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 = { export const OidbSvcTrpcTcp0XE37_800 = {
subCommand: ProtoField(1, ScalarType.UINT32), subCommand: ProtoField(1, ScalarType.UINT32),
@ -59,4 +59,4 @@ export const OidbSvcTrpcTcp0XE37_800Response = {
export const OidbSvcTrpcTcp0XE37_800ResponseBody = { export const OidbSvcTrpcTcp0XE37_800ResponseBody = {
field10: ProtoField(10, ScalarType.UINT32, true), field10: ProtoField(10, ScalarType.UINT32, true),
field30: ProtoField(30, () => OidbSvcTrpcTcp0XE37_800_1200Metadata, true), field30: ProtoField(30, () => OidbSvcTrpcTcp0XE37_800_1200Metadata, true),
} };

View File

@ -8,7 +8,7 @@ export const OidbSvcTrpcTcp0XE37_1700 = {
businessId: ProtoField(101, ScalarType.INT32, true), businessId: ProtoField(101, ScalarType.INT32, true),
clientType: ProtoField(102, ScalarType.INT32, true), clientType: ProtoField(102, ScalarType.INT32, true),
flagSupportMediaPlatform: ProtoField(200, ScalarType.INT32, true), flagSupportMediaPlatform: ProtoField(200, ScalarType.INT32, true),
} };
export const ApplyUploadReqV3 = { export const ApplyUploadReqV3 = {
senderUid: ProtoField(10, ScalarType.STRING, true), senderUid: ProtoField(10, ScalarType.STRING, true),
@ -20,4 +20,4 @@ export const ApplyUploadReqV3 = {
localPath: ProtoField(70, ScalarType.STRING, true), localPath: ProtoField(70, ScalarType.STRING, true),
md5CheckSum: ProtoField(110, ScalarType.BYTES, true), md5CheckSum: ProtoField(110, ScalarType.BYTES, true),
sha3CheckSum: ProtoField(120, ScalarType.BYTES, true), sha3CheckSum: ProtoField(120, ScalarType.BYTES, true),
} };

View File

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

View File

@ -2,7 +2,7 @@
import * as crypto from 'crypto'; import * as crypto from 'crypto';
import * as stream from 'stream'; import * as stream from 'stream';
import * as fs from 'fs'; 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) { function sha1Stream(readable: stream.Readable) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {

View File

@ -73,7 +73,7 @@ export class Sha1Stream {
this._count[1] = (this._count[1] + (dataLen >>> 29)) >>> 0; this._count[1] = (this._count[1] + (dataLen >>> 29)) >>> 0;
let partLen = (this.Sha1BlockSize - index) >>> 0; const partLen = (this.Sha1BlockSize - index) >>> 0;
let i = 0; let i = 0;
if (dataLen >= partLen) { if (dataLen >= partLen) {
@ -100,11 +100,11 @@ export class Sha1Stream {
public final(): Buffer { public final(): Buffer {
const digest = Buffer.allocUnsafe(this.Sha1DigestSize); 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[1], 0);
bits.writeUInt32BE(this._count[0], 4); 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; const padLen = ((index < 56) ? (56 - index) : (120 - index)) >>> 0;
this.update(this._padding, padLen); this.update(this._padding, padLen);
this.update(bits); this.update(bits);

View File

@ -1,5 +1,5 @@
import * as stream from "node:stream"; 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 { export class CalculateStreamBytesTransform extends stream.Transform {
private readonly blockSize = 1024 * 1024; private readonly blockSize = 1024 * 1024;