mirror of https://github.com/Xhofe/alist
fix(quqi): empty file link for non vip user (#5926)
* fix(quqi): error returned when uploading a file that existed * fix empty download link for no vip user * fix cannot parse request result --------- Co-authored-by: Andy Hsu <i@nn.ci>pull/5938/head
parent
85a28d9822
commit
d88b54d98a
|
@ -127,6 +127,7 @@ func (d *Quqi) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([]
|
||||||
func (d *Quqi) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error) {
|
func (d *Quqi) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error) {
|
||||||
var getDocResp = &GetDocRes{}
|
var getDocResp = &GetDocRes{}
|
||||||
|
|
||||||
|
// 优先从getDoc接口获取文件预览链接,速度比实际下载链接更快
|
||||||
if _, err := d.request("", "/api/doc/getDoc", resty.MethodPost, func(req *resty.Request) {
|
if _, err := d.request("", "/api/doc/getDoc", resty.MethodPost, func(req *resty.Request) {
|
||||||
req.SetFormData(map[string]string{
|
req.SetFormData(map[string]string{
|
||||||
"quqi_id": d.GroupID,
|
"quqi_id": d.GroupID,
|
||||||
|
@ -137,7 +138,7 @@ func (d *Quqi) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*
|
||||||
}, getDocResp); err != nil {
|
}, getDocResp); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if getDocResp.Data.OriginPath != "" {
|
||||||
return &model.Link{
|
return &model.Link{
|
||||||
URL: getDocResp.Data.OriginPath,
|
URL: getDocResp.Data.OriginPath,
|
||||||
Header: http.Header{
|
Header: http.Header{
|
||||||
|
@ -145,6 +146,30 @@ func (d *Quqi) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*
|
||||||
"Cookie": []string{d.Cookie},
|
"Cookie": []string{d.Cookie},
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 对于非会员用户,无法从getDoc接口获取文件预览链接,只能获取下载链接
|
||||||
|
var getDownloadResp GetDownloadResp
|
||||||
|
if _, err := d.request("", "/api/doc/getDownload", resty.MethodGet, func(req *resty.Request) {
|
||||||
|
req.SetQueryParams(map[string]string{
|
||||||
|
"quqi_id": d.GroupID,
|
||||||
|
"tree_id": "1",
|
||||||
|
"node_id": file.GetID(),
|
||||||
|
"url_type": "undefined",
|
||||||
|
"entry_type": "undefined",
|
||||||
|
"client_id": d.ClientID,
|
||||||
|
"no_redirect": "1",
|
||||||
|
})
|
||||||
|
}, &getDownloadResp); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &model.Link{
|
||||||
|
URL: getDownloadResp.Data.Url,
|
||||||
|
Header: http.Header{
|
||||||
|
"Origin": []string{"https://quqi.com"},
|
||||||
|
"Cookie": []string{d.Cookie},
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Quqi) MakeDir(ctx context.Context, parentDir model.Obj, dirName string) (model.Obj, error) {
|
func (d *Quqi) MakeDir(ctx context.Context, parentDir model.Obj, dirName string) (model.Obj, error) {
|
||||||
|
|
|
@ -31,6 +31,13 @@ type GetDocRes struct {
|
||||||
} `json:"data"`
|
} `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GetDownloadResp struct {
|
||||||
|
BaseRes
|
||||||
|
Data struct {
|
||||||
|
Url string `json:"url"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
type MakeDirRes struct {
|
type MakeDirRes struct {
|
||||||
BaseRes
|
BaseRes
|
||||||
Data struct {
|
Data struct {
|
||||||
|
|
|
@ -32,7 +32,7 @@ func (d *Quqi) request(host string, path string, method string, callback base.Re
|
||||||
req.SetHeaders(map[string]string{
|
req.SetHeaders(map[string]string{
|
||||||
"Origin": "https://quqi.com",
|
"Origin": "https://quqi.com",
|
||||||
"Cookie": d.Cookie,
|
"Cookie": d.Cookie,
|
||||||
}).SetResult(&result)
|
})
|
||||||
|
|
||||||
if d.GroupID != "" {
|
if d.GroupID != "" {
|
||||||
req.SetQueryParam("quqiid", d.GroupID)
|
req.SetQueryParam("quqiid", d.GroupID)
|
||||||
|
@ -46,6 +46,11 @@ func (d *Quqi) request(host string, path string, method string, callback base.Re
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
// resty.Request.SetResult cannot parse result correctly sometimes
|
||||||
|
err = utils.Json.Unmarshal(res.Body(), &result)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
if result.Code != 0 {
|
if result.Code != 0 {
|
||||||
return nil, errors.New(result.Message)
|
return nil, errors.New(result.Message)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue