Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(thunder_browser): fix fix space parameter not handled correctly in some cases & update some parameters #6952

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
198 changes: 31 additions & 167 deletions drivers/thunder_browser/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3/s3manager"
"github.com/go-resty/resty/v2"
"io"
"net/http"
"regexp"
"strings"
)

Expand Down Expand Up @@ -309,25 +309,18 @@ type XunLeiBrowserCommon struct {
}

func (xc *XunLeiBrowserCommon) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([]model.Obj, error) {
return xc.getFiles(ctx, dir.GetID(), args.ReqPath)
return xc.getFiles(ctx, dir, args.ReqPath)
}

func (xc *XunLeiBrowserCommon) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error) {
var lFile Files

params := map[string]string{
"_magic": "2021",
"space": "SPACE_BROWSER",
"space": file.(*Files).GetSpace(),
"thumbnail_size": "SIZE_LARGE",
"with": "url",
}
// 对 "迅雷云盘" 内的文件 特殊处理
if file.GetPath() == ThunderDriveFileID {
params = map[string]string{}
} else if file.GetPath() == ThunderBrowserDriveSafeFileID {
// 对 "超级保险箱" 内的文件 特殊处理
params["space"] = "SPACE_BROWSER_SAFE"
}

_, err := xc.Request(FILE_API_URL+"/{fileID}", http.MethodGet, func(r *resty.Request) {
r.SetContext(ctx)
Expand Down Expand Up @@ -361,22 +354,9 @@ func (xc *XunLeiBrowserCommon) MakeDir(ctx context.Context, parentDir model.Obj,
"kind": FOLDER,
"name": dirName,
"parent_id": parentDir.GetID(),
"space": "SPACE_BROWSER",
}
if parentDir.GetPath() == ThunderDriveFileID {
js = base.Json{
"kind": FOLDER,
"name": dirName,
"parent_id": parentDir.GetID(),
}
} else if parentDir.GetPath() == ThunderBrowserDriveSafeFileID {
js = base.Json{
"kind": FOLDER,
"name": dirName,
"parent_id": parentDir.GetID(),
"space": "SPACE_BROWSER_SAFE",
}
"space": parentDir.(*Files).GetSpace(),
}

_, err := xc.Request(FILE_API_URL, http.MethodPost, func(r *resty.Request) {
r.SetContext(ctx)
r.SetBody(&js)
Expand All @@ -386,33 +366,14 @@ func (xc *XunLeiBrowserCommon) MakeDir(ctx context.Context, parentDir model.Obj,

func (xc *XunLeiBrowserCommon) Move(ctx context.Context, srcObj, dstDir model.Obj) error {

srcSpace := "SPACE_BROWSER"
dstSpace := "SPACE_BROWSER"

// 对 "超级保险箱" 内的文件 特殊处理
if srcObj.GetPath() == ThunderBrowserDriveSafeFileID {
srcSpace = "SPACE_BROWSER_SAFE"
}
if dstDir.GetPath() == ThunderBrowserDriveSafeFileID {
dstSpace = "SPACE_BROWSER_SAFE"
}

params := map[string]string{
"_from": dstSpace,
"_from": srcObj.(*Files).GetSpace(),
}
js := base.Json{
"to": base.Json{"parent_id": dstDir.GetID(), "space": dstSpace},
"space": srcSpace,
"to": base.Json{"parent_id": dstDir.GetID(), "space": dstDir.(*Files).GetSpace()},
"space": srcObj.(*Files).GetSpace(),
"ids": []string{srcObj.GetID()},
}
// 对 "迅雷云盘" 内的文件 特殊处理
if srcObj.GetPath() == ThunderDriveFileID {
params = map[string]string{}
js = base.Json{
"to": base.Json{"parent_id": dstDir.GetID()},
"ids": []string{srcObj.GetID()},
}
}

_, err := xc.Request(FILE_API_URL+":batchMove", http.MethodPost, func(r *resty.Request) {
r.SetContext(ctx)
Expand All @@ -425,16 +386,7 @@ func (xc *XunLeiBrowserCommon) Move(ctx context.Context, srcObj, dstDir model.Ob
func (xc *XunLeiBrowserCommon) Rename(ctx context.Context, srcObj model.Obj, newName string) error {

params := map[string]string{
"space": "SPACE_BROWSER",
}
// 对 "迅雷云盘" 内的文件 特殊处理
if srcObj.GetPath() == ThunderDriveFileID {
params = map[string]string{}
} else if srcObj.GetPath() == ThunderBrowserDriveSafeFileID {
// 对 "超级保险箱" 内的文件 特殊处理
params = map[string]string{
"space": "SPACE_BROWSER_SAFE",
}
"space": srcObj.(*Files).GetSpace(),
}

_, err := xc.Request(FILE_API_URL+"/{fileID}", http.MethodPatch, func(r *resty.Request) {
Expand All @@ -448,33 +400,14 @@ func (xc *XunLeiBrowserCommon) Rename(ctx context.Context, srcObj model.Obj, new

func (xc *XunLeiBrowserCommon) Copy(ctx context.Context, srcObj, dstDir model.Obj) error {

srcSpace := "SPACE_BROWSER"
dstSpace := "SPACE_BROWSER"

// 对 "超级保险箱" 内的文件 特殊处理
if srcObj.GetPath() == ThunderBrowserDriveSafeFileID {
srcSpace = "SPACE_BROWSER_SAFE"
}
if dstDir.GetPath() == ThunderBrowserDriveSafeFileID {
dstSpace = "SPACE_BROWSER_SAFE"
}

params := map[string]string{
"_from": dstSpace,
"_from": srcObj.(*Files).GetSpace(),
}
js := base.Json{
"to": base.Json{"parent_id": dstDir.GetID(), "space": dstSpace},
"space": srcSpace,
"to": base.Json{"parent_id": dstDir.GetID(), "space": dstDir.(*Files).GetSpace()},
"space": srcObj.(*Files).GetSpace(),
"ids": []string{srcObj.GetID()},
}
// 对 "迅雷云盘" 内的文件 特殊处理
if srcObj.GetPath() == ThunderDriveFileID {
params = map[string]string{}
js = base.Json{
"to": base.Json{"parent_id": dstDir.GetID()},
"ids": []string{srcObj.GetID()},
}
}

_, err := xc.Request(FILE_API_URL+":batchCopy", http.MethodPost, func(r *resty.Request) {
r.SetContext(ctx)
Expand All @@ -488,30 +421,17 @@ func (xc *XunLeiBrowserCommon) Remove(ctx context.Context, obj model.Obj) error

js := base.Json{
"ids": []string{obj.GetID()},
"space": "SPACE_BROWSER",
"space": obj.(*Files).GetSpace(),
}
// 对 "迅雷云盘" 内的文件 特殊处理
if obj.GetPath() == ThunderDriveFileID {
js = base.Json{
"ids": []string{obj.GetID()},
}
} else if obj.GetPath() == ThunderBrowserDriveSafeFileID {
// 对 "超级保险箱" 内的文件 特殊处理
js = base.Json{
"ids": []string{obj.GetID()},
"space": "SPACE_BROWSER_SAFE",
}
}

// 先判断是否是特殊情况
if obj.GetPath() == ThunderDriveFileID {
if obj.(*Files).GetSpace() == ThunderDriveSpace {
_, err := xc.Request(FILE_API_URL+"/{fileID}/trash", http.MethodPatch, func(r *resty.Request) {
r.SetContext(ctx)
r.SetPathParam("fileID", obj.GetID())
r.SetBody("{}")
}, nil)
return err
} else if obj.GetPath() == ThunderBrowserDriveSafeFileID {
} else if obj.(*Files).GetSpace() == ThunderBrowserDriveSafeSpace || obj.(*Files).GetSpace() == ThunderDriveSafeSpace {
_, err := xc.Request(FILE_API_URL+":batchDelete", http.MethodPost, func(r *resty.Request) {
r.SetContext(ctx)
r.SetBody(&js)
Expand Down Expand Up @@ -557,29 +477,7 @@ func (xc *XunLeiBrowserCommon) Put(ctx context.Context, dstDir model.Obj, stream
"size": stream.GetSize(),
"hash": gcid,
"upload_type": UPLOAD_TYPE_RESUMABLE,
"space": "SPACE_BROWSER",
}
// 对 "迅雷云盘" 内的文件 特殊处理
if dstDir.GetPath() == ThunderDriveFileID {
js = base.Json{
"kind": FILE,
"parent_id": dstDir.GetID(),
"name": stream.GetName(),
"size": stream.GetSize(),
"hash": gcid,
"upload_type": UPLOAD_TYPE_RESUMABLE,
}
} else if dstDir.GetPath() == ThunderBrowserDriveSafeFileID {
// 对 "超级保险箱" 内的文件 特殊处理
js = base.Json{
"kind": FILE,
"parent_id": dstDir.GetID(),
"name": stream.GetName(),
"size": stream.GetSize(),
"hash": gcid,
"upload_type": UPLOAD_TYPE_RESUMABLE,
"space": "SPACE_BROWSER_SAFE",
}
"space": dstDir.(*Files).GetSpace(),
}

var resp UploadTaskResponse
Expand Down Expand Up @@ -610,58 +508,35 @@ func (xc *XunLeiBrowserCommon) Put(ctx context.Context, dstDir model.Obj, stream
Bucket: aws.String(param.Bucket),
Key: aws.String(param.Key),
Expires: aws.Time(param.Expiration),
Body: stream,
Body: io.TeeReader(stream, driver.NewProgress(stream.GetSize(), up)),
})
return err
}
return nil
}

func (xc *XunLeiBrowserCommon) getFiles(ctx context.Context, folderId string, path string) ([]model.Obj, error) {
func (xc *XunLeiBrowserCommon) getFiles(ctx context.Context, dir model.Obj, path string) ([]model.Obj, error) {
files := make([]model.Obj, 0)
var pageToken string
for {
var fileList FileList
folderSpace := "SPACE_BROWSER"
folderSpace := ""
switch dirF := dir.(type) {
case *Files:
folderSpace = dirF.GetSpace()
default:
// 处理 根目录的情况
folderSpace = ThunderBrowserDriveSpace
}
params := map[string]string{
"parent_id": folderId,
"parent_id": dir.GetID(),
"page_token": pageToken,
"space": folderSpace,
"filters": `{"trashed":{"eq":false}}`,
"with": "url",
"with_audit": "true",
"thumbnail_size": "SIZE_LARGE",
}
var fileType int8
// 处理特殊目录 “迅雷云盘” 设置特殊的 params 以便正常访问
pattern1 := fmt.Sprintf(`^/.*/%s(/.*)?$`, ThunderDriveFolderName)
thunderDriveMatch, _ := regexp.MatchString(pattern1, path)
// 处理特殊目录 “超级保险箱” 设置特殊的 params 以便正常访问
pattern2 := fmt.Sprintf(`^/.*/%s(/.*)?$`, ThunderBrowserDriveSafeFolderName)
thunderBrowserDriveSafeMatch, _ := regexp.MatchString(pattern2, path)

// 如果是 "迅雷云盘" 内的
if folderId == ThunderDriveFileID || thunderDriveMatch {
params = map[string]string{
"space": "",
"__type": "drive",
"refresh": "true",
"__sync": "true",
"parent_id": folderId,
"page_token": pageToken,
"with_audit": "true",
"limit": "100",
"filters": `{"phase":{"eq":"PHASE_TYPE_COMPLETE"},"trashed":{"eq":false}}`,
}
// 如果不是 "迅雷云盘"的"根目录"
if folderId == ThunderDriveFileID {
params["parent_id"] = ""
}
fileType = ThunderDriveType
} else if thunderBrowserDriveSafeMatch {
// 如果是 "超级保险箱" 内的
fileType = ThunderBrowserDriveSafeType
params["space"] = "SPACE_BROWSER_SAFE"
}

_, err := xc.Request(FILE_API_URL, http.MethodGet, func(r *resty.Request) {
r.SetContext(ctx)
Expand All @@ -670,24 +545,13 @@ func (xc *XunLeiBrowserCommon) getFiles(ctx context.Context, folderId string, pa
if err != nil {
return nil, err
}
// 对文件夹也进行处理
fileList.FolderType = fileType

for i := 0; i < len(fileList.Files); i++ {
file := &fileList.Files[i]
// 标记 文件夹内的文件
file.FileType = fileList.FolderType
for i := range fileList.Files {
// 解决 "迅雷云盘" 重复出现问题————迅雷后端发送错误
if file.Name == ThunderDriveFolderName && file.ID == "" && file.FolderType == ThunderDriveFolderType && folderId != "" {
if fileList.Files[i].FolderType == ThunderDriveFolderType && fileList.Files[i].ID == "" && fileList.Files[i].Space == "" && dir.GetID() != "" {
continue
}
// 处理特殊目录 “迅雷云盘” 设置特殊的文件夹ID
if file.Name == ThunderDriveFolderName && file.ID == "" && file.FolderType == ThunderDriveFolderType {
file.ID = ThunderDriveFileID
} else if file.Name == ThunderBrowserDriveSafeFolderName && file.FolderType == ThunderBrowserDriveSafeFolderType {
file.FileType = ThunderBrowserDriveSafeType
}
files = append(files, file)
files = append(files, &fileList.Files[i])
}

if fileList.NextPageToken == "" {
Expand Down
4 changes: 2 additions & 2 deletions drivers/thunder_browser/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type ExpertAddition struct {
SafePassword string `json:"safe_password" required:"true" help:"super safe password"` // 超级保险箱密码

// 签名方法1
Algorithms string `json:"algorithms" required:"true" help:"sign type is algorithms,this is required" default:"p+ExqPV,LwdwKlprzv7cQBQmxN5,vc08P1NwUBnbGsl58LzTW,VVNeXaXmZ8HH1SJEnp6YpVFSFU,pNAOJ,CNChvyDehAmUR1TDodfOusBAx,MS98NnX4Np8nxvEh6Ulv+SMMKMzKvD34C7lGWbb,9MpFF21GnVOYku0NM9Y/hzsK471UCUZ2o+,EY1QfeA06fXlw9wZNoZaXEED5zZPvNWI,,sciE,FIPqgQDUUW1e0GkiBFd5w7mCQ,zW,75XFdEO0Gi"`
Algorithms string `json:"algorithms" required:"true" help:"sign type is algorithms,this is required" default:"uWRwO7gPfdPB/0NfPtfQO+71,F93x+qPluYy6jdgNpq+lwdH1ap6WOM+nfz8/V,0HbpxvpXFsBK5CoTKam,dQhzbhzFRcawnsZqRETT9AuPAJ+wTQso82mRv,SAH98AmLZLRa6DB2u68sGhyiDh15guJpXhBzI,unqfo7Z64Rie9RNHMOB,7yxUdFADp3DOBvXdz0DPuKNVT35wqa5z0DEyEvf,RBG,ThTWPG5eC0UBqlbQ+04nZAptqGCdpv9o55A"`
// 签名方法2
CaptchaSign string `json:"captcha_sign" required:"true" help:"sign type is captcha_sign,this is required"`
Timestamp string `json:"timestamp" required:"true" help:"sign type is captcha_sign,this is required"`
Expand All @@ -37,7 +37,7 @@ type ExpertAddition struct {
DeviceID string `json:"device_id" required:"false" default:""`
ClientID string `json:"client_id" required:"true" default:"ZUBzD9J_XPXfn7f7"`
ClientSecret string `json:"client_secret" required:"true" default:"yESVmHecEe6F0aou69vl-g"`
ClientVersion string `json:"client_version" required:"true" default:"1.0.8.2215"`
ClientVersion string `json:"client_version" required:"true" default:"1.10.0.2633"`
PackageName string `json:"package_name" required:"true" default:"com.xunlei.browser"`

// 不影响登录,影响下载速度
Expand Down
33 changes: 23 additions & 10 deletions drivers/thunder_browser/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ type Files struct {
ModifiedTime CustomTime `json:"modified_time"`
IconLink string `json:"icon_link"`
ThumbnailLink string `json:"thumbnail_link"`
// Md5Checksum string `json:"md5_checksum"`
Hash string `json:"hash"`
Md5Checksum string `json:"md5_checksum"`
Hash string `json:"hash"`
// Links map[string]Link `json:"links"`
// Phase string `json:"phase"`
// Audit struct {
Expand Down Expand Up @@ -153,12 +153,22 @@ type Files struct {
OriginalURL string `json:"original_url"`
//Params struct{} `json:"params"`
//OriginalFileIndex int `json:"original_file_index"`
//Space string `json:"space"`
Space string `json:"space"`
//Apps []interface{} `json:"apps"`
//Writable bool `json:"writable"`
FolderType string `json:"folder_type"`
//Collection interface{} `json:"collection"`
FileType int8
SortName string `json:"sort_name"`
UserModifiedTime CustomTime `json:"user_modified_time"`
//SpellName []interface{} `json:"spell_name"`
//FileCategory string `json:"file_category"`
//Tags []interface{} `json:"tags"`
//ReferenceEvents []interface{} `json:"reference_events"`
//ReferenceResource interface{} `json:"reference_resource"`
//Params0 struct {
// PlatformIcon string `json:"platform_icon"`
// SmallThumbnail string `json:"small_thumbnail"`
//} `json:"params,omitempty"`
}

func (c *Files) GetHash() utils.HashInfo {
Expand All @@ -172,16 +182,19 @@ func (c *Files) ModTime() time.Time { return c.ModifiedTime.Time }
func (c *Files) IsDir() bool { return c.Kind == FOLDER }
func (c *Files) GetID() string { return c.ID }
func (c *Files) GetPath() string {
// 对特殊文件进行特殊处理
if c.FileType == ThunderDriveType {
return ThunderDriveFileID
} else if c.FileType == ThunderBrowserDriveSafeType {
return ThunderBrowserDriveSafeFileID
}
return ""
}
func (c *Files) Thumb() string { return c.ThumbnailLink }

func (c *Files) GetSpace() string {
if c.Space != "" {
return c.Space
} else {
// "迅雷云盘" 文件夹内 Space 为空
return ""
}
}

/*
* 上传
**/
Expand Down
Loading
Loading