Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(quqi): empty file link for no vip user #5926

Merged
merged 4 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading