mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
refactor: outer calculation
This commit is contained in:
parent
aa67a2b71c
commit
aa9d96718c
@ -137,6 +137,7 @@ export class PacketHighwaySession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async uploadGroupImageReq(groupUin: number, img: PacketMsgPicElement): Promise<void> {
|
private async uploadGroupImageReq(groupUin: number, img: PacketMsgPicElement): Promise<void> {
|
||||||
|
img.sha1 = Buffer.from(await calculateSha1(img.path)).toString('hex');
|
||||||
const preReq = await this.packer.packUploadGroupImgReq(groupUin, img);
|
const preReq = await this.packer.packUploadGroupImgReq(groupUin, img);
|
||||||
const preRespRaw = await this.packetClient.sendPacket('OidbSvcTrpcTcp.0x11c4_100', preReq, true);
|
const preRespRaw = await this.packetClient.sendPacket('OidbSvcTrpcTcp.0x11c4_100', preReq, true);
|
||||||
const preResp = new NapProtoMsg(OidbSvcTrpcTcpBaseRsp).decode(
|
const preResp = new NapProtoMsg(OidbSvcTrpcTcpBaseRsp).decode(
|
||||||
@ -176,6 +177,7 @@ export class PacketHighwaySession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async uploadC2CImageReq(peerUid: string, img: PacketMsgPicElement): Promise<void> {
|
private async uploadC2CImageReq(peerUid: string, img: PacketMsgPicElement): Promise<void> {
|
||||||
|
img.sha1 = Buffer.from(await calculateSha1(img.path)).toString('hex');
|
||||||
const preReq = await this.packer.packUploadC2CImgReq(peerUid, img);
|
const preReq = await this.packer.packUploadC2CImgReq(peerUid, img);
|
||||||
const preRespRaw = await this.packetClient.sendPacket('OidbSvcTrpcTcp.0x11c5_100', preReq, true);
|
const preRespRaw = await this.packetClient.sendPacket('OidbSvcTrpcTcp.0x11c5_100', preReq, true);
|
||||||
const preResp = new NapProtoMsg(OidbSvcTrpcTcpBaseRsp).decode(
|
const preResp = new NapProtoMsg(OidbSvcTrpcTcpBaseRsp).decode(
|
||||||
@ -214,6 +216,9 @@ export class PacketHighwaySession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async uploadGroupVideoReq(groupUin: number, video: PacketMsgVideoElement): Promise<void> {
|
private async uploadGroupVideoReq(groupUin: number, video: PacketMsgVideoElement): Promise<void> {
|
||||||
|
if (!video.filePath || !video.thumbPath) throw new Error("video.filePath or video.thumbPath is empty");
|
||||||
|
video.fileSha1 = Buffer.from(await calculateSha1(video.filePath)).toString('hex');
|
||||||
|
video.thumbSha1 = Buffer.from(await calculateSha1(video.thumbPath)).toString('hex');
|
||||||
const preReq = await this.packer.packUploadGroupVideoReq(groupUin, video);
|
const preReq = await this.packer.packUploadGroupVideoReq(groupUin, video);
|
||||||
const preRespRaw = await this.packetClient.sendPacket('OidbSvcTrpcTcp.0x11ea_100', preReq, true);
|
const preRespRaw = await this.packetClient.sendPacket('OidbSvcTrpcTcp.0x11ea_100', preReq, true);
|
||||||
const preResp = new NapProtoMsg(OidbSvcTrpcTcpBaseRsp).decode(
|
const preResp = new NapProtoMsg(OidbSvcTrpcTcpBaseRsp).decode(
|
||||||
@ -279,6 +284,9 @@ export class PacketHighwaySession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async uploadC2CVideoReq(peerUid: string, video: PacketMsgVideoElement): Promise<void> {
|
private async uploadC2CVideoReq(peerUid: string, video: PacketMsgVideoElement): Promise<void> {
|
||||||
|
if (!video.filePath || !video.thumbPath) throw new Error("video.filePath or video.thumbPath is empty");
|
||||||
|
video.fileSha1 = Buffer.from(await calculateSha1(video.filePath)).toString('hex');
|
||||||
|
video.thumbSha1 = Buffer.from(await calculateSha1(video.thumbPath)).toString('hex');
|
||||||
const preReq = await this.packer.packUploadC2CVideoReq(peerUid, video);
|
const preReq = await this.packer.packUploadC2CVideoReq(peerUid, video);
|
||||||
const preRespRaw = await this.packetClient.sendPacket('OidbSvcTrpcTcp.0x11e9_100', preReq, true);
|
const preRespRaw = await this.packetClient.sendPacket('OidbSvcTrpcTcp.0x11e9_100', preReq, true);
|
||||||
const preResp = new NapProtoMsg(OidbSvcTrpcTcpBaseRsp).decode(
|
const preResp = new NapProtoMsg(OidbSvcTrpcTcpBaseRsp).decode(
|
||||||
@ -344,6 +352,7 @@ export class PacketHighwaySession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async uploadGroupPttReq(groupUin: number, ptt: PacketMsgPttElement): Promise<void> {
|
private async uploadGroupPttReq(groupUin: number, ptt: PacketMsgPttElement): Promise<void> {
|
||||||
|
ptt.fileSha1 = Buffer.from(await calculateSha1(ptt.filePath)).toString('hex');
|
||||||
const preReq = await this.packer.packUploadGroupPttReq(groupUin, ptt);
|
const preReq = await this.packer.packUploadGroupPttReq(groupUin, ptt);
|
||||||
const preRespRaw = await this.packetClient.sendPacket('OidbSvcTrpcTcp.0x126e_100', preReq, true);
|
const preRespRaw = await this.packetClient.sendPacket('OidbSvcTrpcTcp.0x126e_100', preReq, true);
|
||||||
const preResp = new NapProtoMsg(OidbSvcTrpcTcpBaseRsp).decode(
|
const preResp = new NapProtoMsg(OidbSvcTrpcTcpBaseRsp).decode(
|
||||||
@ -382,6 +391,7 @@ export class PacketHighwaySession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async uploadC2CPttReq(peerUid: string, ptt: PacketMsgPttElement): Promise<void> {
|
private async uploadC2CPttReq(peerUid: string, ptt: PacketMsgPttElement): Promise<void> {
|
||||||
|
ptt.fileSha1 = Buffer.from(await calculateSha1(ptt.filePath)).toString('hex');
|
||||||
const preReq = await this.packer.packUploadC2CPttReq(peerUid, ptt);
|
const preReq = await this.packer.packUploadC2CPttReq(peerUid, ptt);
|
||||||
const preRespRaw = await this.packetClient.sendPacket('OidbSvcTrpcTcp.0x126d_100', preReq, true);
|
const preRespRaw = await this.packetClient.sendPacket('OidbSvcTrpcTcp.0x126d_100', preReq, true);
|
||||||
const preResp = new NapProtoMsg(OidbSvcTrpcTcpBaseRsp).decode(
|
const preResp = new NapProtoMsg(OidbSvcTrpcTcpBaseRsp).decode(
|
||||||
|
@ -288,7 +288,9 @@ export class PacketMsgVideoElement extends IPacketMsgElement<SendVideoElement> {
|
|||||||
thumbSize?: number;
|
thumbSize?: number;
|
||||||
thumbPath?: string;
|
thumbPath?: string;
|
||||||
fileMd5?: string;
|
fileMd5?: string;
|
||||||
|
fileSha1?: string;
|
||||||
thumbMd5?: string;
|
thumbMd5?: string;
|
||||||
|
thumbSha1?: string;
|
||||||
thumbWidth?: number;
|
thumbWidth?: number;
|
||||||
thumbHeight?: number;
|
thumbHeight?: number;
|
||||||
msgInfo: NapProtoEncodeStructType<typeof MsgInfo> | null = null;
|
msgInfo: NapProtoEncodeStructType<typeof MsgInfo> | null = null;
|
||||||
@ -325,6 +327,7 @@ export class PacketMsgPttElement extends IPacketMsgElement<SendPttElement> {
|
|||||||
filePath: string;
|
filePath: string;
|
||||||
fileSize: number;
|
fileSize: number;
|
||||||
fileMd5: string;
|
fileMd5: string;
|
||||||
|
fileSha1?: string;
|
||||||
fileDuration: number;
|
fileDuration: number;
|
||||||
msgInfo: NapProtoEncodeStructType<typeof MsgInfo> | null = null;
|
msgInfo: NapProtoEncodeStructType<typeof MsgInfo> | null = null;
|
||||||
|
|
||||||
|
@ -188,7 +188,7 @@ export class PacketPacker {
|
|||||||
fileInfo: {
|
fileInfo: {
|
||||||
fileSize: +img.size,
|
fileSize: +img.size,
|
||||||
fileHash: img.md5,
|
fileHash: img.md5,
|
||||||
fileSha1: this.toHexStr(await calculateSha1(img.path)),
|
fileSha1: img.sha1!,
|
||||||
fileName: img.name,
|
fileName: img.name,
|
||||||
type: {
|
type: {
|
||||||
type: 1,
|
type: 1,
|
||||||
@ -256,7 +256,7 @@ export class PacketPacker {
|
|||||||
fileInfo: {
|
fileInfo: {
|
||||||
fileSize: +img.size,
|
fileSize: +img.size,
|
||||||
fileHash: img.md5,
|
fileHash: img.md5,
|
||||||
fileSha1: this.toHexStr(await calculateSha1(img.path)),
|
fileSha1: img.sha1!,
|
||||||
fileName: img.name,
|
fileName: img.name,
|
||||||
type: {
|
type: {
|
||||||
type: 1,
|
type: 1,
|
||||||
@ -299,10 +299,7 @@ export class PacketPacker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async packUploadGroupVideoReq(groupUin: number, video: PacketMsgVideoElement): Promise<PacketHexStr> {
|
async packUploadGroupVideoReq(groupUin: number, video: PacketMsgVideoElement): Promise<PacketHexStr> {
|
||||||
if (!video.filePath || !video.thumbPath) throw new Error("video.filePath or video.thumbPath is empty");
|
|
||||||
if (!video.fileSize || !video.thumbSize) throw new Error("video.fileSize or video.thumbSize is empty");
|
if (!video.fileSize || !video.thumbSize) throw new Error("video.fileSize or video.thumbSize is empty");
|
||||||
const videoSha1 = await calculateSha1(video.filePath ?? "");
|
|
||||||
const videoThumbSha1 = await calculateSha1(video.thumbPath ?? "");
|
|
||||||
const req = new NapProtoMsg(NTV2RichMediaReq).encode({
|
const req = new NapProtoMsg(NTV2RichMediaReq).encode({
|
||||||
reqHead: {
|
reqHead: {
|
||||||
common: {
|
common: {
|
||||||
@ -327,7 +324,7 @@ export class PacketPacker {
|
|||||||
fileInfo: {
|
fileInfo: {
|
||||||
fileSize: +video.fileSize,
|
fileSize: +video.fileSize,
|
||||||
fileHash: video.fileMd5,
|
fileHash: video.fileMd5,
|
||||||
fileSha1: this.toHexStr(videoSha1),
|
fileSha1: video.fileSha1,
|
||||||
fileName: "nya.mp4",
|
fileName: "nya.mp4",
|
||||||
type: {
|
type: {
|
||||||
type: 2,
|
type: 2,
|
||||||
@ -345,7 +342,7 @@ export class PacketPacker {
|
|||||||
fileInfo: {
|
fileInfo: {
|
||||||
fileSize: +video.thumbSize,
|
fileSize: +video.thumbSize,
|
||||||
fileHash: video.thumbMd5,
|
fileHash: video.thumbMd5,
|
||||||
fileSha1: this.toHexStr(videoThumbSha1),
|
fileSha1: video.thumbSha1,
|
||||||
fileName: "nya.jpg",
|
fileName: "nya.jpg",
|
||||||
type: {
|
type: {
|
||||||
type: 1,
|
type: 1,
|
||||||
@ -387,10 +384,7 @@ export class PacketPacker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async packUploadC2CVideoReq(peerUin: string, video: PacketMsgVideoElement): Promise<PacketHexStr> {
|
async packUploadC2CVideoReq(peerUin: string, video: PacketMsgVideoElement): Promise<PacketHexStr> {
|
||||||
if (!video.filePath || !video.thumbPath) throw new Error("video.filePath or video.thumbPath is empty");
|
|
||||||
if (!video.fileSize || !video.thumbSize) throw new Error("video.fileSize or video.thumbSize is empty");
|
if (!video.fileSize || !video.thumbSize) throw new Error("video.fileSize or video.thumbSize is empty");
|
||||||
const videoSha1 = await calculateSha1(video.filePath ?? "");
|
|
||||||
const videoThumbSha1 = await calculateSha1(video.thumbPath ?? "");
|
|
||||||
const req = new NapProtoMsg(NTV2RichMediaReq).encode({
|
const req = new NapProtoMsg(NTV2RichMediaReq).encode({
|
||||||
reqHead: {
|
reqHead: {
|
||||||
common: {
|
common: {
|
||||||
@ -416,7 +410,7 @@ export class PacketPacker {
|
|||||||
fileInfo: {
|
fileInfo: {
|
||||||
fileSize: +video.fileSize,
|
fileSize: +video.fileSize,
|
||||||
fileHash: video.fileMd5,
|
fileHash: video.fileMd5,
|
||||||
fileSha1: this.toHexStr(videoSha1),
|
fileSha1: video.fileSha1,
|
||||||
fileName: "nya.mp4",
|
fileName: "nya.mp4",
|
||||||
type: {
|
type: {
|
||||||
type: 2,
|
type: 2,
|
||||||
@ -434,7 +428,7 @@ export class PacketPacker {
|
|||||||
fileInfo: {
|
fileInfo: {
|
||||||
fileSize: +video.thumbSize,
|
fileSize: +video.thumbSize,
|
||||||
fileHash: video.thumbMd5,
|
fileHash: video.thumbMd5,
|
||||||
fileSha1: this.toHexStr(videoThumbSha1),
|
fileSha1: video.thumbSha1,
|
||||||
fileName: "nya.jpg",
|
fileName: "nya.jpg",
|
||||||
type: {
|
type: {
|
||||||
type: 1,
|
type: 1,
|
||||||
@ -476,7 +470,6 @@ export class PacketPacker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async packUploadGroupPttReq(groupUin: number, ptt: PacketMsgPttElement): Promise<PacketHexStr> {
|
async packUploadGroupPttReq(groupUin: number, ptt: PacketMsgPttElement): Promise<PacketHexStr> {
|
||||||
const pttSha1 = await calculateSha1(ptt.filePath);
|
|
||||||
const req = new NapProtoMsg(NTV2RichMediaReq).encode({
|
const req = new NapProtoMsg(NTV2RichMediaReq).encode({
|
||||||
reqHead: {
|
reqHead: {
|
||||||
common: {
|
common: {
|
||||||
@ -501,7 +494,7 @@ export class PacketPacker {
|
|||||||
fileInfo: {
|
fileInfo: {
|
||||||
fileSize: ptt.fileSize,
|
fileSize: ptt.fileSize,
|
||||||
fileHash: ptt.fileMd5,
|
fileHash: ptt.fileMd5,
|
||||||
fileSha1: this.toHexStr(pttSha1),
|
fileSha1: ptt.fileSha1,
|
||||||
fileName: `${ptt.fileMd5}.amr`,
|
fileName: `${ptt.fileMd5}.amr`,
|
||||||
type: {
|
type: {
|
||||||
type: 3,
|
type: 3,
|
||||||
@ -542,7 +535,6 @@ export class PacketPacker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async packUploadC2CPttReq(peerUin: string, ptt: PacketMsgPttElement): Promise<PacketHexStr> {
|
async packUploadC2CPttReq(peerUin: string, ptt: PacketMsgPttElement): Promise<PacketHexStr> {
|
||||||
const pttSha1 = await calculateSha1(ptt.filePath);
|
|
||||||
const req = new NapProtoMsg(NTV2RichMediaReq).encode({
|
const req = new NapProtoMsg(NTV2RichMediaReq).encode({
|
||||||
reqHead: {
|
reqHead: {
|
||||||
common: {
|
common: {
|
||||||
@ -568,7 +560,7 @@ export class PacketPacker {
|
|||||||
fileInfo: {
|
fileInfo: {
|
||||||
fileSize: ptt.fileSize,
|
fileSize: ptt.fileSize,
|
||||||
fileHash: ptt.fileMd5,
|
fileHash: ptt.fileMd5,
|
||||||
fileSha1: this.toHexStr(pttSha1),
|
fileSha1: ptt.fileSha1,
|
||||||
fileName: `${ptt.fileMd5}.amr`,
|
fileName: `${ptt.fileMd5}.amr`,
|
||||||
type: {
|
type: {
|
||||||
type: 3,
|
type: 3,
|
||||||
@ -616,7 +608,7 @@ export class PacketPacker {
|
|||||||
localDirectory: `/${file.fileName}`,
|
localDirectory: `/${file.fileName}`,
|
||||||
fileSize: BigInt(file.fileSize),
|
fileSize: BigInt(file.fileSize),
|
||||||
fileMd5: file.fileMd5,
|
fileMd5: file.fileMd5,
|
||||||
fileSha1: await calculateSha1(file.filePath),
|
fileSha1: file.fileSha1,
|
||||||
fileSha3: Buffer.alloc(0),
|
fileSha3: Buffer.alloc(0),
|
||||||
field15: true
|
field15: true
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user