mirror of
https://github.com/AlistGo/alist.git
synced 2025-04-22 21:04:07 +08:00
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] [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/)
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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"`
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user