Skip to content

Commit

Permalink
fix(quqi): empty file link for non vip user (AlistGo#5926)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
2 people authored and EtherealAO committed Apr 12, 2024
1 parent 3c821a7 commit 474be4d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
27 changes: 26 additions & 1 deletion drivers/quqi/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
var getDocResp = &GetDocRes{}

// 优先从getDoc接口获取文件预览链接,速度比实际下载链接更快
if _, err := d.request("", "/api/doc/getDoc", resty.MethodPost, func(req *resty.Request) {
req.SetFormData(map[string]string{
"quqi_id": d.GroupID,
Expand All @@ -137,9 +138,33 @@ func (d *Quqi) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*
}, getDocResp); err != nil {
return nil, err
}
if getDocResp.Data.OriginPath != "" {
return &model.Link{
URL: getDocResp.Data.OriginPath,
Header: http.Header{
"Origin": []string{"https://quqi.com"},
"Cookie": []string{d.Cookie},
},
}, 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: getDocResp.Data.OriginPath,
URL: getDownloadResp.Data.Url,
Header: http.Header{
"Origin": []string{"https://quqi.com"},
"Cookie": []string{d.Cookie},
Expand Down
7 changes: 7 additions & 0 deletions drivers/quqi/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ type GetDocRes struct {
} `json:"data"`
}

type GetDownloadResp struct {
BaseRes
Data struct {
Url string `json:"url"`
} `json:"data"`
}

type MakeDirRes struct {
BaseRes
Data struct {
Expand Down
7 changes: 6 additions & 1 deletion drivers/quqi/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (d *Quqi) request(host string, path string, method string, callback base.Re
req.SetHeaders(map[string]string{
"Origin": "https://quqi.com",
"Cookie": d.Cookie,
}).SetResult(&result)
})

if d.GroupID != "" {
req.SetQueryParam("quqiid", d.GroupID)
Expand All @@ -46,6 +46,11 @@ func (d *Quqi) request(host string, path string, method string, callback base.Re
if err != nil {
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 {
return nil, errors.New(result.Message)
}
Expand Down

0 comments on commit 474be4d

Please sign in to comment.