refactor: outer calculation

This commit is contained in:
pk5ls20 2024-10-25 05:54:46 +08:00
parent aa67a2b71c
commit aa9d96718c
No known key found for this signature in database
GPG Key ID: 6370ED7A169F493A
3 changed files with 22 additions and 17 deletions

View File

@ -137,6 +137,7 @@ export class PacketHighwaySession {
}
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 preRespRaw = await this.packetClient.sendPacket('OidbSvcTrpcTcp.0x11c4_100', preReq, true);
const preResp = new NapProtoMsg(OidbSvcTrpcTcpBaseRsp).decode(
@ -176,6 +177,7 @@ export class PacketHighwaySession {
}
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 preRespRaw = await this.packetClient.sendPacket('OidbSvcTrpcTcp.0x11c5_100', preReq, true);
const preResp = new NapProtoMsg(OidbSvcTrpcTcpBaseRsp).decode(
@ -214,6 +216,9 @@ export class PacketHighwaySession {
}
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 preRespRaw = await this.packetClient.sendPacket('OidbSvcTrpcTcp.0x11ea_100', preReq, true);
const preResp = new NapProtoMsg(OidbSvcTrpcTcpBaseRsp).decode(
@ -279,6 +284,9 @@ export class PacketHighwaySession {
}
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 preRespRaw = await this.packetClient.sendPacket('OidbSvcTrpcTcp.0x11e9_100', preReq, true);
const preResp = new NapProtoMsg(OidbSvcTrpcTcpBaseRsp).decode(
@ -344,6 +352,7 @@ export class PacketHighwaySession {
}
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 preRespRaw = await this.packetClient.sendPacket('OidbSvcTrpcTcp.0x126e_100', preReq, true);
const preResp = new NapProtoMsg(OidbSvcTrpcTcpBaseRsp).decode(
@ -382,6 +391,7 @@ export class PacketHighwaySession {
}
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 preRespRaw = await this.packetClient.sendPacket('OidbSvcTrpcTcp.0x126d_100', preReq, true);
const preResp = new NapProtoMsg(OidbSvcTrpcTcpBaseRsp).decode(

View File

@ -288,7 +288,9 @@ export class PacketMsgVideoElement extends IPacketMsgElement<SendVideoElement> {
thumbSize?: number;
thumbPath?: string;
fileMd5?: string;
fileSha1?: string;
thumbMd5?: string;
thumbSha1?: string;
thumbWidth?: number;
thumbHeight?: number;
msgInfo: NapProtoEncodeStructType<typeof MsgInfo> | null = null;
@ -325,6 +327,7 @@ export class PacketMsgPttElement extends IPacketMsgElement<SendPttElement> {
filePath: string;
fileSize: number;
fileMd5: string;
fileSha1?: string;
fileDuration: number;
msgInfo: NapProtoEncodeStructType<typeof MsgInfo> | null = null;

View File

@ -188,7 +188,7 @@ export class PacketPacker {
fileInfo: {
fileSize: +img.size,
fileHash: img.md5,
fileSha1: this.toHexStr(await calculateSha1(img.path)),
fileSha1: img.sha1!,
fileName: img.name,
type: {
type: 1,
@ -256,7 +256,7 @@ export class PacketPacker {
fileInfo: {
fileSize: +img.size,
fileHash: img.md5,
fileSha1: this.toHexStr(await calculateSha1(img.path)),
fileSha1: img.sha1!,
fileName: img.name,
type: {
type: 1,
@ -299,10 +299,7 @@ export class PacketPacker {
}
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");
const videoSha1 = await calculateSha1(video.filePath ?? "");
const videoThumbSha1 = await calculateSha1(video.thumbPath ?? "");
const req = new NapProtoMsg(NTV2RichMediaReq).encode({
reqHead: {
common: {
@ -327,7 +324,7 @@ export class PacketPacker {
fileInfo: {
fileSize: +video.fileSize,
fileHash: video.fileMd5,
fileSha1: this.toHexStr(videoSha1),
fileSha1: video.fileSha1,
fileName: "nya.mp4",
type: {
type: 2,
@ -345,7 +342,7 @@ export class PacketPacker {
fileInfo: {
fileSize: +video.thumbSize,
fileHash: video.thumbMd5,
fileSha1: this.toHexStr(videoThumbSha1),
fileSha1: video.thumbSha1,
fileName: "nya.jpg",
type: {
type: 1,
@ -387,10 +384,7 @@ export class PacketPacker {
}
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");
const videoSha1 = await calculateSha1(video.filePath ?? "");
const videoThumbSha1 = await calculateSha1(video.thumbPath ?? "");
const req = new NapProtoMsg(NTV2RichMediaReq).encode({
reqHead: {
common: {
@ -416,7 +410,7 @@ export class PacketPacker {
fileInfo: {
fileSize: +video.fileSize,
fileHash: video.fileMd5,
fileSha1: this.toHexStr(videoSha1),
fileSha1: video.fileSha1,
fileName: "nya.mp4",
type: {
type: 2,
@ -434,7 +428,7 @@ export class PacketPacker {
fileInfo: {
fileSize: +video.thumbSize,
fileHash: video.thumbMd5,
fileSha1: this.toHexStr(videoThumbSha1),
fileSha1: video.thumbSha1,
fileName: "nya.jpg",
type: {
type: 1,
@ -476,7 +470,6 @@ export class PacketPacker {
}
async packUploadGroupPttReq(groupUin: number, ptt: PacketMsgPttElement): Promise<PacketHexStr> {
const pttSha1 = await calculateSha1(ptt.filePath);
const req = new NapProtoMsg(NTV2RichMediaReq).encode({
reqHead: {
common: {
@ -501,7 +494,7 @@ export class PacketPacker {
fileInfo: {
fileSize: ptt.fileSize,
fileHash: ptt.fileMd5,
fileSha1: this.toHexStr(pttSha1),
fileSha1: ptt.fileSha1,
fileName: `${ptt.fileMd5}.amr`,
type: {
type: 3,
@ -542,7 +535,6 @@ export class PacketPacker {
}
async packUploadC2CPttReq(peerUin: string, ptt: PacketMsgPttElement): Promise<PacketHexStr> {
const pttSha1 = await calculateSha1(ptt.filePath);
const req = new NapProtoMsg(NTV2RichMediaReq).encode({
reqHead: {
common: {
@ -568,7 +560,7 @@ export class PacketPacker {
fileInfo: {
fileSize: ptt.fileSize,
fileHash: ptt.fileMd5,
fileSha1: this.toHexStr(pttSha1),
fileSha1: ptt.fileSha1,
fileName: `${ptt.fileMd5}.amr`,
type: {
type: 3,
@ -616,7 +608,7 @@ export class PacketPacker {
localDirectory: `/${file.fileName}`,
fileSize: BigInt(file.fileSize),
fileMd5: file.fileMd5,
fileSha1: await calculateSha1(file.filePath),
fileSha1: file.fileSha1,
fileSha3: Buffer.alloc(0),
field15: true
}