From d88b54d98a9d20a96e06440c80194b4c093c9b05 Mon Sep 17 00:00:00 2001 From: Echo Response <32877980+EchoResponse@users.noreply.github.com> Date: Sun, 21 Jan 2024 15:28:52 +0800 Subject: [PATCH] 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 --- drivers/quqi/driver.go | 27 ++++++++++++++++++++++++++- drivers/quqi/types.go | 7 +++++++ drivers/quqi/util.go | 7 ++++++- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/drivers/quqi/driver.go b/drivers/quqi/driver.go index 98c184bd..43cdbf77 100644 --- a/drivers/quqi/driver.go +++ b/drivers/quqi/driver.go @@ -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, @@ -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}, diff --git a/drivers/quqi/types.go b/drivers/quqi/types.go index f64fb748..00ca0d98 100644 --- a/drivers/quqi/types.go +++ b/drivers/quqi/types.go @@ -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 { diff --git a/drivers/quqi/util.go b/drivers/quqi/util.go index 23a6a966..943891f5 100644 --- a/drivers/quqi/util.go +++ b/drivers/quqi/util.go @@ -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) @@ -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) }