perf(terabox): optimize prompt message (#3002)
* perf(terabox):prompt login status when init the driver * docs:add Terabox * perf(terabox):prompt area is not available * style(terabox): del else
This commit is contained in:
parent
48e6f3bb23
commit
1eca2b83ed
@ -61,6 +61,7 @@ English | [中文](./README_cn.md) | [Contributing](./CONTRIBUTING.md) | [CODE_O
|
|||||||
- [x] [139yun](https://yun.139.com/) (Personal, Family)
|
- [x] [139yun](https://yun.139.com/) (Personal, Family)
|
||||||
- [x] [YandexDisk](https://disk.yandex.com/)
|
- [x] [YandexDisk](https://disk.yandex.com/)
|
||||||
- [x] [BaiduNetdisk](http://pan.baidu.com/)
|
- [x] [BaiduNetdisk](http://pan.baidu.com/)
|
||||||
|
- [x] [Terabox](https://www.terabox.com/main)
|
||||||
- [x] [Quark](https://pan.quark.cn)
|
- [x] [Quark](https://pan.quark.cn)
|
||||||
- [x] [Thunder](https://pan.xunlei.com)
|
- [x] [Thunder](https://pan.xunlei.com)
|
||||||
- [x] [Lanzou](https://www.lanzou.com/)
|
- [x] [Lanzou](https://www.lanzou.com/)
|
||||||
|
@ -11,7 +11,6 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"io"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
"net/http"
|
|
||||||
"os"
|
"os"
|
||||||
stdpath "path"
|
stdpath "path"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -35,7 +34,17 @@ func (d *Terabox) GetAddition() driver.Additional {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Terabox) Init(ctx context.Context) error {
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,11 +38,11 @@ type File struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ListResp struct {
|
type ListResp struct {
|
||||||
Errno int `json:"errno"`
|
Errno int `json:"errno"`
|
||||||
GuidInfo string `json:"guid_info"`
|
GuidInfo string `json:"guid_info"`
|
||||||
List []File `json:"list"`
|
List []File `json:"list"`
|
||||||
RequestId int64 `json:"request_id"`
|
//RequestId int64 `json:"request_id"` 接口返回有时是int有时是string
|
||||||
Guid int `json:"guid"`
|
Guid int `json:"guid"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func fileToObj(f File) *model.ObjThumb {
|
func fileToObj(f File) *model.ObjThumb {
|
||||||
@ -70,7 +70,7 @@ type DownloadResp2 struct {
|
|||||||
Info []struct {
|
Info []struct {
|
||||||
Dlink string `json:"dlink"`
|
Dlink string `json:"dlink"`
|
||||||
} `json:"info"`
|
} `json:"info"`
|
||||||
RequestID int64 `json:"request_id"`
|
//RequestID int64 `json:"request_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type HomeInfoResp struct {
|
type HomeInfoResp struct {
|
||||||
@ -88,5 +88,9 @@ type PrecreateResp struct {
|
|||||||
ReturnType int `json:"return_type"`
|
ReturnType int `json:"return_type"`
|
||||||
BlockList []int `json:"block_list"`
|
BlockList []int `json:"block_list"`
|
||||||
Errno int `json:"errno"`
|
Errno int `json:"errno"`
|
||||||
RequestId int64 `json:"request_id"`
|
//RequestId int64 `json:"request_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CheckLoginResp struct {
|
||||||
|
Errno int `json:"errno"`
|
||||||
}
|
}
|
||||||
|
@ -17,10 +17,11 @@ import (
|
|||||||
func (d *Terabox) request(furl string, method string, callback base.ReqCallback, resp interface{}) ([]byte, error) {
|
func (d *Terabox) request(furl string, method string, callback base.ReqCallback, resp interface{}) ([]byte, error) {
|
||||||
req := base.RestyClient.R()
|
req := base.RestyClient.R()
|
||||||
req.SetHeaders(map[string]string{
|
req.SetHeaders(map[string]string{
|
||||||
"Cookie": d.Cookie,
|
"Cookie": d.Cookie,
|
||||||
"Accept": "application/json, text/plain, */*",
|
"Accept": "application/json, text/plain, */*",
|
||||||
"Referer": "https://www.terabox.com/",
|
"Referer": "https://www.terabox.com/",
|
||||||
"User-Agent": base.UserAgent,
|
"User-Agent": base.UserAgent,
|
||||||
|
"X-Requested-With": "XMLHttpRequest",
|
||||||
})
|
})
|
||||||
req.SetQueryParam("app_id", "250528")
|
req.SetQueryParam("app_id", "250528")
|
||||||
req.SetQueryParam("web", "1")
|
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) {
|
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) {
|
return d.request("https://www.terabox.com"+pathname, http.MethodGet, func(req *resty.Request) {
|
||||||
req.SetQueryParams(params)
|
if params != nil {
|
||||||
|
req.SetQueryParams(params)
|
||||||
|
}
|
||||||
}, resp)
|
}, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Terabox) post(pathname string, params map[string]string, data interface{}, resp interface{}) ([]byte, error) {
|
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) {
|
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)
|
req.SetBody(data)
|
||||||
}, resp)
|
}, resp)
|
||||||
}
|
}
|
||||||
@ -73,6 +78,9 @@ func (d *Terabox) getFiles(dir string) ([]File, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if resp.Errno == 9000 {
|
||||||
|
return nil, fmt.Errorf("terabox is not yet available in this area")
|
||||||
|
}
|
||||||
if len(resp.List) == 0 {
|
if len(resp.List) == 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user