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

perf(terabox):Optimize prompt message #3002

Merged
merged 4 commits into from
Jan 12, 2023
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ English | [中文](./README_cn.md) | [Contributing](./CONTRIBUTING.md) | [CODE_O
- [x] [139yun](https://yun.139.com/) (Personal, Family)
- [x] [YandexDisk](https://disk.yandex.com/)
- [x] [BaiduNetdisk](http://pan.baidu.com/)
- [x] [Terabox](https://www.terabox.com/main)
- [x] [Quark](https://pan.quark.cn)
- [x] [Thunder](https://pan.xunlei.com)
- [x] [Lanzou](https://www.lanzou.com/)
Expand Down
13 changes: 11 additions & 2 deletions drivers/terabox/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
log "github.com/sirupsen/logrus"
"io"
"math"
"net/http"
"os"
stdpath "path"
"strconv"
Expand All @@ -35,7 +34,17 @@ func (d *Terabox) GetAddition() driver.Additional {
}

func (d *Terabox) Init(ctx context.Context) error {
_, err := d.request("https://www.terabox.com/api/check/login", http.MethodGet, nil, nil)
var resp CheckLoginResp
_, err := d.get("/api/check/login", nil, &resp)
if err != nil {
return err
}
if resp.Errno != 0 {
if resp.Errno == 9000 {
return fmt.Errorf("terabox is not yet available in this area")
}
return fmt.Errorf("failed to check login status according to cookie")
}
return err
}

Expand Down
18 changes: 11 additions & 7 deletions drivers/terabox/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ type File struct {
}

type ListResp struct {
Errno int `json:"errno"`
GuidInfo string `json:"guid_info"`
List []File `json:"list"`
RequestId int64 `json:"request_id"`
Guid int `json:"guid"`
Errno int `json:"errno"`
GuidInfo string `json:"guid_info"`
List []File `json:"list"`
//RequestId int64 `json:"request_id"` 接口返回有时是int有时是string
Guid int `json:"guid"`
}

func fileToObj(f File) *model.ObjThumb {
Expand Down Expand Up @@ -70,7 +70,7 @@ type DownloadResp2 struct {
Info []struct {
Dlink string `json:"dlink"`
} `json:"info"`
RequestID int64 `json:"request_id"`
//RequestID int64 `json:"request_id"`
}

type HomeInfoResp struct {
Expand All @@ -88,5 +88,9 @@ type PrecreateResp struct {
ReturnType int `json:"return_type"`
BlockList []int `json:"block_list"`
Errno int `json:"errno"`
RequestId int64 `json:"request_id"`
//RequestId int64 `json:"request_id"`
}

type CheckLoginResp struct {
Errno int `json:"errno"`
}
20 changes: 14 additions & 6 deletions drivers/terabox/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ import (
func (d *Terabox) request(furl string, method string, callback base.ReqCallback, resp interface{}) ([]byte, error) {
req := base.RestyClient.R()
req.SetHeaders(map[string]string{
"Cookie": d.Cookie,
"Accept": "application/json, text/plain, */*",
"Referer": "https://www.terabox.com/",
"User-Agent": base.UserAgent,
"Cookie": d.Cookie,
"Accept": "application/json, text/plain, */*",
"Referer": "https://www.terabox.com/",
"User-Agent": base.UserAgent,
"X-Requested-With": "XMLHttpRequest",
})
req.SetQueryParam("app_id", "250528")
req.SetQueryParam("web", "1")
Expand All @@ -41,13 +42,17 @@ func (d *Terabox) request(furl string, method string, callback base.ReqCallback,

func (d *Terabox) get(pathname string, params map[string]string, resp interface{}) ([]byte, error) {
return d.request("https://www.terabox.com"+pathname, http.MethodGet, func(req *resty.Request) {
req.SetQueryParams(params)
if params != nil {
req.SetQueryParams(params)
}
}, resp)
}

func (d *Terabox) post(pathname string, params map[string]string, data interface{}, resp interface{}) ([]byte, error) {
return d.request("https://www.terabox.com"+pathname, http.MethodPost, func(req *resty.Request) {
req.SetQueryParams(params)
if params != nil {
req.SetQueryParams(params)
}
req.SetBody(data)
}, resp)
}
Expand All @@ -73,6 +78,9 @@ func (d *Terabox) getFiles(dir string) ([]File, error) {
if err != nil {
return nil, err
}
if resp.Errno == 9000 {
return nil, fmt.Errorf("terabox is not yet available in this area")
}
if len(resp.List) == 0 {
break
}
Expand Down