mirror of https://github.com/Xhofe/alist
🐛 fix 123pan 403
parent
d00f75c814
commit
731dbf6c3a
|
@ -112,7 +112,7 @@ func (driver Pan123) GetFiles(parentId string, account *model.Account) ([]Pan123
|
|||
"trashed": "false",
|
||||
}
|
||||
_, err := driver.Request("https://www.123pan.com/api/file/list",
|
||||
base.Get, query, nil, &resp, false, account)
|
||||
base.Get, nil, query, nil, &resp, false, account)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ func (driver Pan123) GetFiles(parentId string, account *model.Account) ([]Pan123
|
|||
return res, nil
|
||||
}
|
||||
|
||||
func (driver Pan123) Request(url string, method int, query map[string]string, data *base.Json, resp interface{}, proxy bool, account *model.Account) ([]byte, error) {
|
||||
func (driver Pan123) Request(url string, method int, headers, query map[string]string, data *base.Json, resp interface{}, proxy bool, account *model.Account) ([]byte, error) {
|
||||
rawUrl := url
|
||||
if account.APIProxyUrl != "" {
|
||||
url = fmt.Sprintf("%s/%s", account.APIProxyUrl, url)
|
||||
|
@ -130,6 +130,9 @@ func (driver Pan123) Request(url string, method int, query map[string]string, da
|
|||
log.Debugf("request: %s", url)
|
||||
req := base.RestyClient.R()
|
||||
req.SetHeader("Authorization", "Bearer "+account.AccessToken)
|
||||
if headers != nil {
|
||||
req.SetHeaders(headers)
|
||||
}
|
||||
if query != nil {
|
||||
req.SetQueryParams(query)
|
||||
}
|
||||
|
@ -161,7 +164,7 @@ func (driver Pan123) Request(url string, method int, query map[string]string, da
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return driver.Request(rawUrl, method, query, data, resp, proxy, account)
|
||||
return driver.Request(rawUrl, method, headers, query, data, resp, proxy, account)
|
||||
}
|
||||
return nil, errors.New(jsoniter.Get(body, "message").ToString())
|
||||
}
|
||||
|
|
|
@ -22,8 +22,8 @@ type Pan123 struct{}
|
|||
|
||||
func (driver Pan123) Config() base.DriverConfig {
|
||||
return base.DriverConfig{
|
||||
Name: "123Pan",
|
||||
OnlyProxy: false,
|
||||
Name: "123Pan",
|
||||
NeedSetLink: true,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -126,11 +126,19 @@ func (driver Pan123) Files(path string, account *model.Account) ([]model.File, e
|
|||
}
|
||||
|
||||
func (driver Pan123) Link(args base.Args, account *model.Account) (*base.Link, error) {
|
||||
log.Debugf("%+v", args)
|
||||
file, err := driver.GetFile(utils.ParsePath(args.Path), account)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var resp Pan123DownResp
|
||||
var headers map[string]string
|
||||
if args.IP != "" && args.IP != "::1" {
|
||||
headers = map[string]string{
|
||||
//"X-Real-IP": "1.1.1.1",
|
||||
"X-Forwarded-For": args.IP,
|
||||
}
|
||||
}
|
||||
data := base.Json{
|
||||
"driveId": 0,
|
||||
"etag": file.Etag,
|
||||
|
@ -141,7 +149,7 @@ func (driver Pan123) Link(args base.Args, account *model.Account) (*base.Link, e
|
|||
"type": file.Type,
|
||||
}
|
||||
_, err = driver.Request("https://www.123pan.com/api/file/download_info",
|
||||
base.Post, nil, &data, &resp, true, account)
|
||||
base.Post, headers, nil, &data, &resp, true, account)
|
||||
//_, err = pan123Client.R().SetResult(&resp).SetHeader("authorization", "Bearer "+account.AccessToken).
|
||||
// SetBody().Post("https://www.123pan.com/api/file/download_info")
|
||||
if err != nil {
|
||||
|
@ -174,11 +182,6 @@ func (driver Pan123) Path(path string, account *model.Account) (*model.File, []m
|
|||
return nil, nil, err
|
||||
}
|
||||
if !file.IsDir() {
|
||||
link, err := driver.Link(base.Args{Path: path}, account)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
file.Url = link.Url
|
||||
return file, nil, nil
|
||||
}
|
||||
files, err := driver.Files(path, account)
|
||||
|
@ -215,7 +218,7 @@ func (driver Pan123) MakeDir(path string, account *model.Account) error {
|
|||
"type": 1,
|
||||
}
|
||||
_, err = driver.Request("https://www.123pan.com/api/file/upload_request",
|
||||
base.Post, nil, &data, nil, false, account)
|
||||
base.Post, nil, nil, &data, nil, false, account)
|
||||
//_, err = driver.Post("https://www.123pan.com/api/file/upload_request", data, account)
|
||||
if err == nil {
|
||||
_ = base.DeleteCache(dir, account)
|
||||
|
@ -239,7 +242,7 @@ func (driver Pan123) Move(src string, dst string, account *model.Account) error
|
|||
"fileName": dstName,
|
||||
}
|
||||
_, err = driver.Request("https://www.123pan.com/api/file/rename",
|
||||
base.Post, nil, &data, nil, false, account)
|
||||
base.Post, nil, nil, &data, nil, false, account)
|
||||
//_, err = driver.Post("https://www.123pan.com/api/file/rename", data, account)
|
||||
} else {
|
||||
// move
|
||||
|
@ -253,7 +256,7 @@ func (driver Pan123) Move(src string, dst string, account *model.Account) error
|
|||
"parentFileId": parentFileId,
|
||||
}
|
||||
_, err = driver.Request("https://www.123pan.com/api/file/mod_pid",
|
||||
base.Post, nil, &data, nil, false, account)
|
||||
base.Post, nil, nil, &data, nil, false, account)
|
||||
//_, err = driver.Post("https://www.123pan.com/api/file/mod_pid", data, account)
|
||||
}
|
||||
if err != nil {
|
||||
|
@ -278,7 +281,7 @@ func (driver Pan123) Delete(path string, account *model.Account) error {
|
|||
"fileTrashInfoList": file,
|
||||
}
|
||||
_, err = driver.Request("https://www.123pan.com/api/file/trash",
|
||||
base.Post, nil, &data, nil, false, account)
|
||||
base.Post, nil, nil, &data, nil, false, account)
|
||||
//_, err = driver.Post("https://www.123pan.com/api/file/trash", data, account)
|
||||
if err == nil {
|
||||
_ = base.DeleteCache(utils.Dir(path), account)
|
||||
|
@ -313,7 +316,7 @@ func (driver Pan123) Upload(file *model.FileStream, account *model.Account) erro
|
|||
"type": 0,
|
||||
}
|
||||
res, err := driver.Request("https://www.123pan.com/api/file/upload_request",
|
||||
base.Post, nil, &data, nil, false, account)
|
||||
base.Post, nil, nil, &data, nil, false, account)
|
||||
//res, err := driver.Post("https://www.123pan.com/api/file/upload_request", data, account)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -26,8 +26,8 @@ type Cloud189 struct{}
|
|||
|
||||
func (driver Cloud189) Config() base.DriverConfig {
|
||||
return base.DriverConfig{
|
||||
Name: "189Cloud",
|
||||
OnlyProxy: false,
|
||||
Name: "189Cloud",
|
||||
NeedSetLink: true,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -194,11 +194,6 @@ func (driver Cloud189) Path(path string, account *model.Account) (*model.File, [
|
|||
return nil, nil, err
|
||||
}
|
||||
if !file.IsDir() {
|
||||
link, err := driver.Link(base.Args{Path: path}, account)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
file.Url = link.Url
|
||||
return file, nil, nil
|
||||
}
|
||||
files, err := driver.Files(path, account)
|
||||
|
|
|
@ -21,8 +21,8 @@ type AliDrive struct{}
|
|||
|
||||
func (driver AliDrive) Config() base.DriverConfig {
|
||||
return base.DriverConfig{
|
||||
Name: "AliDrive",
|
||||
OnlyProxy: false,
|
||||
Name: "AliDrive",
|
||||
NeedSetLink: true,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -201,11 +201,6 @@ func (driver AliDrive) Path(path string, account *model.Account) (*model.File, [
|
|||
return nil, nil, err
|
||||
}
|
||||
if !file.IsDir() {
|
||||
link, err := driver.Link(base.Args{Path: path}, account)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
file.Url = link.Url
|
||||
return file, nil, nil
|
||||
}
|
||||
files, err := driver.Files(path, account)
|
||||
|
|
|
@ -9,10 +9,11 @@ import (
|
|||
)
|
||||
|
||||
type DriverConfig struct {
|
||||
Name string
|
||||
OnlyProxy bool
|
||||
NoLink bool // 必须本机返回的
|
||||
ApiProxy bool // 使用API中转的
|
||||
Name string
|
||||
OnlyProxy bool
|
||||
NoLink bool // 必须本机返回的
|
||||
ApiProxy bool // 使用API中转的
|
||||
NeedSetLink bool // 需要设置链接的
|
||||
}
|
||||
|
||||
type Args struct {
|
||||
|
|
|
@ -159,8 +159,7 @@ func (driver GoogleDrive) Path(path string, account *model.Account) (*model.File
|
|||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if file.Type != conf.FOLDER {
|
||||
//file.Url, _ = driver.Link(path, account)
|
||||
if !file.IsDir() {
|
||||
return file, nil, nil
|
||||
}
|
||||
files, err := driver.Files(path, account)
|
||||
|
|
|
@ -14,8 +14,8 @@ type Lanzou struct{}
|
|||
|
||||
func (driver Lanzou) Config() base.DriverConfig {
|
||||
return base.DriverConfig{
|
||||
Name: "Lanzou",
|
||||
OnlyProxy: false,
|
||||
Name: "Lanzou",
|
||||
NeedSetLink: true,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -145,11 +145,6 @@ func (driver Lanzou) Path(path string, account *model.Account) (*model.File, []m
|
|||
return nil, nil, err
|
||||
}
|
||||
if !file.IsDir() {
|
||||
link, err := driver.Link(base.Args{Path: path}, account)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
file.Url = link.Url
|
||||
return file, nil, nil
|
||||
}
|
||||
files, err := driver.Files(path, account)
|
||||
|
|
|
@ -16,8 +16,7 @@ type Onedrive struct{}
|
|||
|
||||
func (driver Onedrive) Config() base.DriverConfig {
|
||||
return base.DriverConfig{
|
||||
Name: "Onedrive",
|
||||
OnlyProxy: false,
|
||||
Name: "Onedrive",
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -193,7 +192,6 @@ func (driver Onedrive) Path(path string, account *model.Account) (*model.File, [
|
|||
return nil, nil, err
|
||||
}
|
||||
if !file.IsDir() {
|
||||
//file.Url, _ = driver.Link(path, account)
|
||||
return file, nil, nil
|
||||
}
|
||||
files, err := driver.Files(path, account)
|
||||
|
|
|
@ -15,7 +15,8 @@ type PikPak struct{}
|
|||
|
||||
func (driver PikPak) Config() base.DriverConfig {
|
||||
return base.DriverConfig{
|
||||
Name: "PikPak",
|
||||
Name: "PikPak",
|
||||
NeedSetLink: true,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -123,11 +124,6 @@ func (driver PikPak) Path(path string, account *model.Account) (*model.File, []m
|
|||
return nil, nil, err
|
||||
}
|
||||
if !file.IsDir() {
|
||||
link, err := driver.Link(base.Args{Path: path}, account)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
file.Url = link.Url
|
||||
return file, nil, nil
|
||||
}
|
||||
files, err := driver.Files(path, account)
|
||||
|
|
|
@ -30,7 +30,7 @@ func Down(c *gin.Context) {
|
|||
Proxy(c)
|
||||
return
|
||||
}
|
||||
link, err := driver.Link(base.Args{Path: path}, account)
|
||||
link, err := driver.Link(base.Args{Path: path, IP: c.ClientIP()}, account)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 500)
|
||||
return
|
||||
|
@ -71,6 +71,7 @@ func Proxy(c *gin.Context) {
|
|||
c.Redirect(302, link)
|
||||
return
|
||||
}
|
||||
// 对于中转,不需要重设IP
|
||||
link, err := driver.Link(base.Args{Path: path}, account)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 500)
|
||||
|
|
|
@ -46,6 +46,13 @@ func Path(c *gin.Context) {
|
|||
} else {
|
||||
file.Url = fmt.Sprintf("//%s/d%s", c.Request.Host, req.Path)
|
||||
}
|
||||
} else if driver.Config().NeedSetLink {
|
||||
link, err := driver.Link(base.Args{Path: path, IP: c.ClientIP()}, account)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 500)
|
||||
return
|
||||
}
|
||||
file.Url = link.Url
|
||||
}
|
||||
c.JSON(200, common.Resp{
|
||||
Code: 200,
|
||||
|
@ -94,7 +101,7 @@ func Link(c *gin.Context) {
|
|||
})
|
||||
return
|
||||
}
|
||||
link, err := driver.Link(base.Args{Path: path}, account)
|
||||
link, err := driver.Link(base.Args{Path: path, IP: c.ClientIP()}, account)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 500)
|
||||
return
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
"github.com/Xhofe/alist/model"
|
||||
"github.com/Xhofe/alist/utils"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"net"
|
||||
"net/http"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
@ -101,6 +102,25 @@ func (fs *FileSystem) Files(rawPath string) ([]model.File, error) {
|
|||
// }
|
||||
//}
|
||||
|
||||
func ClientIP(r *http.Request) string {
|
||||
xForwardedFor := r.Header.Get("X-Forwarded-For")
|
||||
ip := strings.TrimSpace(strings.Split(xForwardedFor, ",")[0])
|
||||
if ip != "" {
|
||||
return ip
|
||||
}
|
||||
|
||||
ip = strings.TrimSpace(r.Header.Get("X-Real-Ip"))
|
||||
if ip != "" {
|
||||
return ip
|
||||
}
|
||||
|
||||
if ip, _, err := net.SplitHostPort(strings.TrimSpace(r.RemoteAddr)); err == nil {
|
||||
return ip
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
func (fs *FileSystem) Link(r *http.Request, rawPath string) (string, error) {
|
||||
rawPath = utils.ParsePath(rawPath)
|
||||
log.Debugf("get link path: %s", rawPath)
|
||||
|
@ -123,7 +143,7 @@ func (fs *FileSystem) Link(r *http.Request, rawPath string) (string, error) {
|
|||
link += "?sign" + sign
|
||||
}
|
||||
} else {
|
||||
link_, err := driver.Link(base.Args{Path: path_}, account)
|
||||
link_, err := driver.Link(base.Args{Path: path_, IP: ClientIP(r)}, account)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue