Skip to content

Commit

Permalink
client: add FileResource
Browse files Browse the repository at this point in the history
  • Loading branch information
wdvxdr1123 committed Jun 19, 2022
1 parent c92096e commit 2a1fd32
Show file tree
Hide file tree
Showing 9 changed files with 307 additions and 124 deletions.
136 changes: 65 additions & 71 deletions client/group_file.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package client

import (
"crypto/sha1"
"encoding/hex"
"fmt"
"io"
"math/rand"
"os"
"runtime/debug"
Expand Down Expand Up @@ -171,75 +169,71 @@ func (fs *GroupFileSystem) UploadFile(p, name, folderId string) error {
return errors.Wrap(err, "open file error")
}
defer func() { _ = file.Close() }()
md5Hash, size := utils.ComputeMd5AndLength(file)
_, _ = file.Seek(0, io.SeekStart)
sha1H := sha1.New()
_, _ = io.Copy(sha1H, file)
sha1Hash := sha1H.Sum(nil)
_, _ = file.Seek(0, io.SeekStart)
i, err := fs.client.sendAndWait(fs.client.buildGroupFileUploadReqPacket(folderId, name, fs.GroupCode, size, md5Hash, sha1Hash))
f := &FileResource{
FileName: name,
Body: file,
}
f.init()
i, err := fs.client.sendAndWait(fs.client.buildGroupFileUploadReqPacket(folderId, fs.GroupCode, f))
if err != nil {
return errors.Wrap(err, "query upload failed")
}
rsp := i.(*oidb.UploadFileRspBody)
if rsp.BoolFileExist.Unwrap() {
_, pkt := fs.client.buildGroupFileFeedsRequest(fs.GroupCode, rsp.FileId.Unwrap(), rsp.BusId.Unwrap(), rand.Int31())
return fs.client.sendPacket(pkt)
}
if len(rsp.UploadIpLanV4) == 0 {
return errors.New("server requires unsupported ftn upload")
}
ext, _ := proto.Marshal(&exciting.GroupFileUploadExt{
Unknown1: proto.Int32(100),
Unknown2: proto.Int32(1),
Entry: &exciting.GroupFileUploadEntry{
BusiBuff: &exciting.ExcitingBusiInfo{
BusId: rsp.BusId,
SenderUin: proto.Some(fs.client.Uin),
ReceiverUin: proto.Some(fs.GroupCode),
GroupCode: proto.Some(fs.GroupCode),
},
FileEntry: &exciting.ExcitingFileEntry{
FileSize: proto.Some(size),
Md5: md5Hash,
Sha1: sha1Hash,
FileId: []byte(rsp.FileId.Unwrap()),
UploadKey: rsp.CheckKey,
},
ClientInfo: &exciting.ExcitingClientInfo{
ClientType: proto.Int32(2),
AppId: proto.String(fmt.Sprint(fs.client.version.AppId)),
TerminalType: proto.Int32(2),
ClientVer: proto.String("9e9c09dc"),
Unknown: proto.Int32(4),
},
FileNameInfo: &exciting.ExcitingFileNameInfo{FileName: proto.Some(name)},
Host: &exciting.ExcitingHostConfig{Hosts: []*exciting.ExcitingHostInfo{
{
Url: &exciting.ExcitingUrlInfo{
Unknown: proto.Int32(1),
Host: proto.Some(rsp.UploadIpLanV4[0]),
},
Port: rsp.UploadPort,
if !rsp.BoolFileExist.Unwrap() {
if len(rsp.UploadIpLanV4) == 0 {
return errors.New("server requires unsupported ftn upload")
}
ext, _ := proto.Marshal(&exciting.FileUploadExt{
Unknown1: proto.Int32(100),
Unknown2: proto.Int32(1),
Entry: &exciting.FileUploadEntry{
BusiBuff: &exciting.ExcitingBusiInfo{
BusId: rsp.BusId,
SenderUin: proto.Some(fs.client.Uin),
ReceiverUin: proto.Some(fs.GroupCode),
GroupCode: proto.Some(fs.GroupCode),
},
}},
},
Unknown3: proto.Int32(0),
})
client := fs.client
input := highway.Transaction{
CommandID: 71,
Body: file,
Size: size,
Sum: md5Hash,
Ticket: fs.client.highwaySession.SigSession,
Ext: ext,
}
if _, err = fs.client.highwaySession.UploadExciting(input); err != nil {
return errors.Wrap(err, "upload failed")
FileEntry: &exciting.ExcitingFileEntry{
FileSize: proto.Some(f.size),
Md5: f.md5,
Sha1: f.sha1,
FileId: []byte(rsp.FileId.Unwrap()),
UploadKey: rsp.CheckKey,
},
ClientInfo: &exciting.ExcitingClientInfo{
ClientType: proto.Int32(2),
AppId: proto.String(fmt.Sprint(fs.client.version.AppId)),
TerminalType: proto.Int32(2),
ClientVer: proto.String("9e9c09dc"),
Unknown: proto.Int32(4),
},
FileNameInfo: &exciting.ExcitingFileNameInfo{FileName: proto.Some(name)},
Host: &exciting.ExcitingHostConfig{Hosts: []*exciting.ExcitingHostInfo{
{
Url: &exciting.ExcitingUrlInfo{
Unknown: proto.Int32(1),
Host: proto.Some(rsp.UploadIpLanV4[0]),
},
Port: rsp.UploadPort,
},
}},
},
Unknown3: proto.Int32(0),
})
input := highway.Transaction{
CommandID: 71,
Body: file,
Size: f.size,
Sum: f.md5,
Ticket: fs.client.highwaySession.SigSession,
Ext: ext,
}
if _, err = fs.client.highwaySession.UploadExciting(input); err != nil {
return errors.Wrap(err, "upload failed")
}
}
_, pkt := client.buildGroupFileFeedsRequest(fs.GroupCode, rsp.FileId.Unwrap(), rsp.BusId.Unwrap(), rand.Int31())
return client.sendPacket(pkt)
_, pkt := fs.client.buildGroupFileFeedsRequest(fs.GroupCode, rsp.FileId.Unwrap(), rsp.BusId.Unwrap(), rand.Int31())
return fs.client.sendPacket(pkt)
}

func (fs *GroupFileSystem) GetDownloadUrl(file *GroupFile) string {
Expand Down Expand Up @@ -277,18 +271,18 @@ func (fs *GroupFileSystem) DeleteFile(parentFolderID, fileId string, busId int32
return i.(string)
}

func (c *QQClient) buildGroupFileUploadReqPacket(parentFolderID, fileName string, groupCode, fileSize int64, md5, sha1 []byte) (uint16, []byte) {
func (c *QQClient) buildGroupFileUploadReqPacket(parentFolderID string, groupCode int64, file *FileResource) (uint16, []byte) {
body := &oidb.D6D6ReqBody{UploadFileReq: &oidb.UploadFileReqBody{
GroupCode: proto.Some(groupCode),
AppId: proto.Int32(3),
BusId: proto.Int32(102),
Entrance: proto.Int32(5),
ParentFolderId: proto.Some(parentFolderID),
FileName: proto.Some(fileName),
LocalPath: proto.String("/storage/emulated/0/Pictures/files/s/" + fileName),
Int64FileSize: proto.Some(fileSize),
Sha: sha1,
Md5: md5,
FileName: proto.Some(file.FileName),
LocalPath: proto.String("/storage/emulated/0/Pictures/files/s/" + file.FileName),
Int64FileSize: proto.Some(file.size),
Sha: file.sha1,
Md5: file.md5,
SupportMultiUpload: proto.Bool(true),
}}
payload := c.packOIDBPackageProto(1750, 0, body)
Expand Down
3 changes: 1 addition & 2 deletions client/internal/highway/highway.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,8 @@ func (s *Session) UploadExciting(trans Transaction) ([]byte, error) {
r := binary.NewReader(body)
r.ReadByte()
hl := r.ReadInt32()
a2 := r.ReadInt32()
_ = r.ReadInt32()
h := r.ReadBytes(int(hl))
r.ReadBytes(int(a2))
rspHead := new(pb.RspDataHighwayHead)
if err = proto.Unmarshal(h, rspHead); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal protobuf message")
Expand Down
86 changes: 45 additions & 41 deletions client/pb/cmd0x346/cmd0x346.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions client/pb/cmd0x346/cmd0x346.proto
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ message ApplyUploadReqV3 {
string localFilepath = 70;
int32 dangerLevel = 80;
int64 totalSpace = 90;
bytes md5 = 110;
bytes _3Sha = 120;
}
message ApplyUploadRsp {
int32 retCode = 10;
Expand Down Expand Up @@ -248,6 +250,7 @@ message ApplyUploadRspV3 {
string uploadHttpsDomain = 150;
string uploadDns = 160;
string uploadLanip = 170;
bytes mediaPlateformUploadKey = 220;
}
message DelMessageReq {
int64 uinSender = 1;
Expand Down Expand Up @@ -382,6 +385,7 @@ message C346ReqBody {
ApplyUploadHitReqV3 applyUploadHitReqV3 = 21;
int32 businessId = 101;
int32 clientType = 102;
uint32 flagSupportMediaplatform = 200;
ApplyCopyToReq applyCopyToReq = 90000;
//ApplyCleanTrafficReq applyCleanTrafficReq = 90001; empty message
ApplyGetTrafficReq applyGetTrafficReq = 90002;
Expand Down
13 changes: 7 additions & 6 deletions client/pb/exciting/group.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions client/pb/exciting/group.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ syntax = "proto2";

option go_package = "github.com/Mrs4s/MiraiGo/client/pb/exciting";

message GroupFileUploadExt {
message FileUploadExt {
optional int32 unknown1 = 1;
optional int32 unknown2 = 2;
optional GroupFileUploadEntry entry = 100;
optional int32 unknown3 = 3;
optional FileUploadEntry entry = 100;
optional int32 unknown200 = 200;
}

message GroupFileUploadEntry {
message FileUploadEntry {
optional ExcitingBusiInfo busiBuff = 100;
optional ExcitingFileEntry fileEntry = 200;
optional ExcitingClientInfo clientInfo = 300;
Expand Down
2 changes: 1 addition & 1 deletion client/pb/oidb/oidb0xeb7.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2a1fd32

Please sign in to comment.