🐛 fix 123pan webdav can't get

pull/548/head
微凉 2021-11-29 16:06:49 +08:00
parent d955038ebc
commit 4ff2756572
2 changed files with 15 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import (
"github.com/Xhofe/alist/utils"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
url "net/url"
"path/filepath"
)
@ -149,6 +150,19 @@ func (driver Pan123) Link(path string, account *model.Account) (string, error) {
}
return "", fmt.Errorf(resp.Message)
}
u,err := url.Parse(resp.Data.DownloadUrl)
if err != nil {
return "", err
}
u_ := fmt.Sprintf("https://%s%s",u.Host,u.Path)
res, err := drivers.NoRedirectClient.R().SetQueryParamsFromValues(u.Query()).Get(u_)
if err != nil {
return "", err
}
log.Debug(res.String())
if res.StatusCode() == 302 {
return res.Header().Get("location"), nil
}
return resp.Data.DownloadUrl, nil
}

View File

@ -69,4 +69,5 @@ func init() {
return http.ErrUseLastResponse
}),
)
NoRedirectClient.SetHeader("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36")
}