fix: 189cloud big file download (close #683)
This commit is contained in:
parent
678a982535
commit
c63e05983d
@ -88,12 +88,6 @@ func (driver Cloud189) FormatFile(file *Cloud189File) *model.File {
|
|||||||
// return nil, ErrPathNotFound
|
// return nil, ErrPathNotFound
|
||||||
//}
|
//}
|
||||||
|
|
||||||
type Cloud189Down struct {
|
|
||||||
ResCode int `json:"res_code"`
|
|
||||||
ResMessage string `json:"res_message"`
|
|
||||||
FileDownloadUrl string `json:"fileDownloadUrl"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type LoginResp struct {
|
type LoginResp struct {
|
||||||
Msg string `json:"msg"`
|
Msg string `json:"msg"`
|
||||||
Result int `json:"result"`
|
Result int `json:"result"`
|
||||||
|
@ -6,7 +6,9 @@ import (
|
|||||||
"github.com/Xhofe/alist/drivers/base"
|
"github.com/Xhofe/alist/drivers/base"
|
||||||
"github.com/Xhofe/alist/model"
|
"github.com/Xhofe/alist/model"
|
||||||
"github.com/Xhofe/alist/utils"
|
"github.com/Xhofe/alist/utils"
|
||||||
|
"github.com/go-resty/resty/v2"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
"net/http"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -152,14 +154,15 @@ func (driver Cloud189) Link(args base.Args, account *model.Account) (*base.Link,
|
|||||||
if file.Type == conf.FOLDER {
|
if file.Type == conf.FOLDER {
|
||||||
return nil, base.ErrNotFile
|
return nil, base.ErrNotFile
|
||||||
}
|
}
|
||||||
var resp Cloud189Down
|
var resp DownResp
|
||||||
u := "https://cloud.189.cn/api/open/file/getFileDownloadUrl.action"
|
u := "https://cloud.189.cn/api/portal/getFileInfo.action"
|
||||||
body, err := driver.Request(u, base.Get, map[string]string{
|
body, err := driver.Request(u, base.Get, map[string]string{
|
||||||
"fileId": file.Id,
|
"fileId": file.Id,
|
||||||
}, nil, nil, account)
|
}, nil, nil, account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
log.Debugln(string(body))
|
||||||
err = utils.Json.Unmarshal(body, &resp)
|
err = utils.Json.Unmarshal(body, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -167,10 +170,19 @@ func (driver Cloud189) Link(args base.Args, account *model.Account) (*base.Link,
|
|||||||
if resp.ResCode != 0 {
|
if resp.ResCode != 0 {
|
||||||
return nil, fmt.Errorf(resp.ResMessage)
|
return nil, fmt.Errorf(resp.ResMessage)
|
||||||
}
|
}
|
||||||
res, err := base.NoRedirectClient.R().Get(resp.FileDownloadUrl)
|
client, err := driver.getClient(account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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{
|
link := base.Link{
|
||||||
Headers: []base.Header{
|
Headers: []base.Header{
|
||||||
{Name: "User-Agent", Value: base.UserAgent},
|
{Name: "User-Agent", Value: base.UserAgent},
|
||||||
@ -179,6 +191,10 @@ func (driver Cloud189) Link(args base.Args, account *model.Account) (*base.Link,
|
|||||||
}
|
}
|
||||||
if res.StatusCode() == 302 {
|
if res.StatusCode() == 302 {
|
||||||
link.Url = res.Header().Get("location")
|
link.Url = res.Header().Get("location")
|
||||||
|
res, err = client.R().Get(link.Url)
|
||||||
|
if res.StatusCode() == 302 {
|
||||||
|
link.Url = res.Header().Get("location")
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
link.Url = resp.FileDownloadUrl
|
link.Url = resp.FileDownloadUrl
|
||||||
}
|
}
|
||||||
|
@ -53,3 +53,15 @@ type Rsa struct {
|
|||||||
PkId string `json:"pkId"`
|
PkId string `json:"pkId"`
|
||||||
PubKey string `json:"pubKey"`
|
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"`
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user