diff --git a/README.md b/README.md index 61237af7cb7..6b8ca60e54c 100755 --- a/README.md +++ b/README.md @@ -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/) diff --git a/drivers/terabox/driver.go b/drivers/terabox/driver.go index b7c4546ece2..e87d3ad7053 100644 --- a/drivers/terabox/driver.go +++ b/drivers/terabox/driver.go @@ -11,7 +11,6 @@ import ( log "github.com/sirupsen/logrus" "io" "math" - "net/http" "os" stdpath "path" "strconv" @@ -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 } diff --git a/drivers/terabox/types.go b/drivers/terabox/types.go index e2015622cba..25bd99c698f 100644 --- a/drivers/terabox/types.go +++ b/drivers/terabox/types.go @@ -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 { @@ -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 { @@ -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"` } diff --git a/drivers/terabox/util.go b/drivers/terabox/util.go index bca7835c33f..d0b10e779a1 100644 --- a/drivers/terabox/util.go +++ b/drivers/terabox/util.go @@ -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") @@ -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) } @@ -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 }