mirror of https://github.com/Xhofe/alist
fix(123): optimize error messages (#2415)
parent
a02d9c8463
commit
518487e3df
|
@ -70,7 +70,7 @@ func (d *Pan123) List(ctx context.Context, dir model.Obj, args model.ListArgs) (
|
||||||
|
|
||||||
func (d *Pan123) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error) {
|
func (d *Pan123) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error) {
|
||||||
if f, ok := file.(File); ok {
|
if f, ok := file.(File); ok {
|
||||||
var resp DownResp
|
//var resp DownResp
|
||||||
var headers map[string]string
|
var headers map[string]string
|
||||||
if !utils.IsLocalIPAddr(args.IP) {
|
if !utils.IsLocalIPAddr(args.IP) {
|
||||||
headers = map[string]string{
|
headers = map[string]string{
|
||||||
|
@ -87,13 +87,14 @@ func (d *Pan123) Link(ctx context.Context, file model.Obj, args model.LinkArgs)
|
||||||
"size": f.Size,
|
"size": f.Size,
|
||||||
"type": f.Type,
|
"type": f.Type,
|
||||||
}
|
}
|
||||||
_, err := d.request("https://www.123pan.com/api/file/download_info", http.MethodPost, func(req *resty.Request) {
|
resp, err := d.request("https://www.123pan.com/api/file/download_info", http.MethodPost, func(req *resty.Request) {
|
||||||
req.SetBody(data).SetHeaders(headers)
|
req.SetBody(data).SetHeaders(headers)
|
||||||
}, &resp)
|
}, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
u, err := url.Parse(resp.Data.DownloadUrl)
|
downloadUrl := utils.Json.Get(resp, "data", "DownloadUrl").ToString()
|
||||||
|
u, err := url.Parse(downloadUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -112,7 +113,7 @@ func (d *Pan123) Link(ctx context.Context, file model.Obj, args model.LinkArgs)
|
||||||
}
|
}
|
||||||
log.Debug(res.String())
|
log.Debug(res.String())
|
||||||
link := model.Link{
|
link := model.Link{
|
||||||
URL: resp.Data.DownloadUrl,
|
URL: downloadUrl,
|
||||||
}
|
}
|
||||||
log.Debugln("res code: ", res.StatusCode())
|
log.Debugln("res code: ", res.StatusCode())
|
||||||
if res.StatusCode() == 302 {
|
if res.StatusCode() == 302 {
|
||||||
|
|
|
@ -7,13 +7,13 @@ import (
|
||||||
"github.com/alist-org/alist/v3/internal/model"
|
"github.com/alist-org/alist/v3/internal/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BaseResp struct {
|
//type BaseResp struct {
|
||||||
Code int `json:"code"`
|
// Code interface{} `json:"code"`
|
||||||
Message string `json:"message"`
|
// Message string `json:"message"`
|
||||||
}
|
//}
|
||||||
|
|
||||||
type TokenResp struct {
|
type TokenResp struct {
|
||||||
BaseResp
|
//BaseResp
|
||||||
Data struct {
|
Data struct {
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
} `json:"data"`
|
} `json:"data"`
|
||||||
|
@ -62,22 +62,22 @@ var _ model.Obj = (*File)(nil)
|
||||||
//var _ model.Thumb = (*File)(nil)
|
//var _ model.Thumb = (*File)(nil)
|
||||||
|
|
||||||
type Files struct {
|
type Files struct {
|
||||||
BaseResp
|
//BaseResp
|
||||||
Data struct {
|
Data struct {
|
||||||
InfoList []File `json:"InfoList"`
|
InfoList []File `json:"InfoList"`
|
||||||
Next string `json:"Next"`
|
Next string `json:"Next"`
|
||||||
} `json:"data"`
|
} `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DownResp struct {
|
//type DownResp struct {
|
||||||
BaseResp
|
// //BaseResp
|
||||||
Data struct {
|
// Data struct {
|
||||||
DownloadUrl string `json:"DownloadUrl"`
|
// DownloadUrl string `json:"DownloadUrl"`
|
||||||
} `json:"data"`
|
// } `json:"data"`
|
||||||
}
|
//}
|
||||||
|
|
||||||
type UploadResp struct {
|
type UploadResp struct {
|
||||||
BaseResp
|
//BaseResp
|
||||||
Data struct {
|
Data struct {
|
||||||
AccessKeyId string `json:"AccessKeyId"`
|
AccessKeyId string `json:"AccessKeyId"`
|
||||||
Bucket string `json:"Bucket"`
|
Bucket string `json:"Bucket"`
|
||||||
|
|
|
@ -29,14 +29,14 @@ func (d *Pan123) login() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var resp TokenResp
|
var resp TokenResp
|
||||||
_, err := base.RestyClient.R().
|
res, err := base.RestyClient.R().
|
||||||
SetResult(&resp).
|
SetResult(&resp).
|
||||||
SetBody(body).Post(url)
|
SetBody(body).Post(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if resp.Code != 200 {
|
if utils.Json.Get(res.Body(), "code").ToInt() != 200 {
|
||||||
err = fmt.Errorf(resp.Message)
|
err = fmt.Errorf(utils.Json.Get(res.Body(), "message").ToString())
|
||||||
} else {
|
} else {
|
||||||
d.AccessToken = resp.Data.Token
|
d.AccessToken = resp.Data.Token
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ func (d *Pan123) request(url string, method string, callback base.ReqCallback, r
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
body := res.Body()
|
body := res.Body()
|
||||||
code := jsoniter.Get(body, "code").ToInt()
|
code := utils.Json.Get(body, "code").ToInt()
|
||||||
if code != 0 {
|
if code != 0 {
|
||||||
if code == 401 {
|
if code == 401 {
|
||||||
err := d.login()
|
err := d.login()
|
||||||
|
|
Loading…
Reference in New Issue