Skip to content

Commit

Permalink
fix: 189cloud big file download (close #683)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Mar 7, 2022
1 parent 678a982 commit c63e059
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
6 changes: 0 additions & 6 deletions drivers/189/189.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,6 @@ func (driver Cloud189) FormatFile(file *Cloud189File) *model.File {
// return nil, ErrPathNotFound
//}

type Cloud189Down struct {
ResCode int `json:"res_code"`
ResMessage string `json:"res_message"`
FileDownloadUrl string `json:"fileDownloadUrl"`
}

type LoginResp struct {
Msg string `json:"msg"`
Result int `json:"result"`
Expand Down
22 changes: 19 additions & 3 deletions drivers/189/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"github.com/Xhofe/alist/drivers/base"
"github.com/Xhofe/alist/model"
"github.com/Xhofe/alist/utils"
"github.com/go-resty/resty/v2"
log "github.com/sirupsen/logrus"
"net/http"
"path/filepath"
)

Expand Down Expand Up @@ -152,25 +154,35 @@ func (driver Cloud189) Link(args base.Args, account *model.Account) (*base.Link,
if file.Type == conf.FOLDER {
return nil, base.ErrNotFile
}
var resp Cloud189Down
u := "https://cloud.189.cn/api/open/file/getFileDownloadUrl.action"
var resp DownResp
u := "https://cloud.189.cn/api/portal/getFileInfo.action"
body, err := driver.Request(u, base.Get, map[string]string{
"fileId": file.Id,
}, nil, nil, account)
if err != nil {
return nil, err
}
log.Debugln(string(body))
err = utils.Json.Unmarshal(body, &resp)
if err != nil {
return nil, err
}
if resp.ResCode != 0 {
return nil, fmt.Errorf(resp.ResMessage)
}
res, err := base.NoRedirectClient.R().Get(resp.FileDownloadUrl)
client, err := driver.getClient(account)
if err != nil {
return nil, err
}
client = resty.NewWithClient(client.GetClient()).SetRedirectPolicy(
resty.RedirectPolicyFunc(func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
}))
res, err := client.R().Get("https:" + resp.FileDownloadUrl)
if err != nil {
return nil, err
}
log.Debugln(res.Status())
link := base.Link{
Headers: []base.Header{
{Name: "User-Agent", Value: base.UserAgent},
Expand All @@ -179,6 +191,10 @@ func (driver Cloud189) Link(args base.Args, account *model.Account) (*base.Link,
}
if res.StatusCode() == 302 {
link.Url = res.Header().Get("location")
res, err = client.R().Get(link.Url)
if res.StatusCode() == 302 {
link.Url = res.Header().Get("location")
}
} else {
link.Url = resp.FileDownloadUrl
}
Expand Down
12 changes: 12 additions & 0 deletions drivers/189/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,15 @@ type Rsa struct {
PkId string `json:"pkId"`
PubKey string `json:"pubKey"`
}

type Cloud189Down struct {
ResCode int `json:"res_code"`
ResMessage string `json:"res_message"`
FileDownloadUrl string `json:"fileDownloadUrl"`
}

type DownResp struct {
ResCode int `json:"res_code"`
ResMessage string `json:"res_message"`
FileDownloadUrl string `json:"downloadUrl"`
}

0 comments on commit c63e059

Please sign in to comment.