diff --git a/src/core/packet/highway/session.ts b/src/core/packet/highway/session.ts index d66df215..b8cf7f33 100644 --- a/src/core/packet/highway/session.ts +++ b/src/core/packet/highway/session.ts @@ -137,6 +137,7 @@ export class PacketHighwaySession { } private async uploadGroupImageReq(groupUin: number, img: PacketMsgPicElement): Promise { + 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 { + 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 { + 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 { + 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 { + 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 { + 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( diff --git a/src/core/packet/msg/element.ts b/src/core/packet/msg/element.ts index e036c7f8..1fa9e064 100644 --- a/src/core/packet/msg/element.ts +++ b/src/core/packet/msg/element.ts @@ -288,7 +288,9 @@ export class PacketMsgVideoElement extends IPacketMsgElement { thumbSize?: number; thumbPath?: string; fileMd5?: string; + fileSha1?: string; thumbMd5?: string; + thumbSha1?: string; thumbWidth?: number; thumbHeight?: number; msgInfo: NapProtoEncodeStructType | null = null; @@ -325,6 +327,7 @@ export class PacketMsgPttElement extends IPacketMsgElement { filePath: string; fileSize: number; fileMd5: string; + fileSha1?: string; fileDuration: number; msgInfo: NapProtoEncodeStructType | null = null; diff --git a/src/core/packet/packer.ts b/src/core/packet/packer.ts index 6f99efa9..67a1b86d 100644 --- a/src/core/packet/packer.ts +++ b/src/core/packet/packer.ts @@ -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 { - 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 { - 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 { - 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 { - 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 }