Skip to content

Commit

Permalink
perf(terabox): optimize prompt message (#3002)
Browse files Browse the repository at this point in the history
* perf(terabox):prompt login status when init the driver

* docs:add Terabox

* perf(terabox):prompt area is not available

* style(terabox): del else
Code2qing authored Jan 12, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 48e6f3b commit 1eca2b8
Showing 4 changed files with 37 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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/)
13 changes: 11 additions & 2 deletions drivers/terabox/driver.go
Original file line number Diff line number Diff line change
@@ -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
}

18 changes: 11 additions & 7 deletions drivers/terabox/types.go
Original file line number Diff line number Diff line change
@@ -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"`
}
20 changes: 14 additions & 6 deletions drivers/terabox/util.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 1eca2b8

Please sign in to comment.