diff --git a/drivers/123/driver.go b/drivers/123/driver.go index 9c63b6675..6fdcce339 100644 --- a/drivers/123/driver.go +++ b/drivers/123/driver.go @@ -15,7 +15,6 @@ import ( log "github.com/sirupsen/logrus" "io" "io/ioutil" - "net/http" "net/url" "os" "path/filepath" @@ -197,9 +196,9 @@ func (driver Pan123) Path(path string, account *model.Account) (*model.File, []m return nil, files, nil } -func (driver Pan123) Proxy(r *http.Request, account *model.Account) { - r.Header.Del("origin") -} +//func (driver Pan123) Proxy(r *http.Request, account *model.Account) { +// r.Header.Del("origin") +//} func (driver Pan123) Preview(path string, account *model.Account) (interface{}, error) { return nil, base.ErrNotSupport diff --git a/drivers/139/driver.go b/drivers/139/driver.go index 8b7a33491..25aa27b9d 100644 --- a/drivers/139/driver.go +++ b/drivers/139/driver.go @@ -162,9 +162,9 @@ func (driver Cloud139) Path(path string, account *model.Account) (*model.File, [ return nil, files, nil } -func (driver Cloud139) Proxy(r *http.Request, account *model.Account) { - -} +//func (driver Cloud139) Proxy(r *http.Request, account *model.Account) { +// +//} func (driver Cloud139) Preview(path string, account *model.Account) (interface{}, error) { return nil, base.ErrNotSupport diff --git a/drivers/189/driver.go b/drivers/189/driver.go index 22ca79268..e8b263a55 100644 --- a/drivers/189/driver.go +++ b/drivers/189/driver.go @@ -7,7 +7,6 @@ import ( "github.com/Xhofe/alist/model" "github.com/Xhofe/alist/utils" log "github.com/sirupsen/logrus" - "net/http" "path/filepath" ) @@ -198,9 +197,9 @@ func (driver Cloud189) Path(path string, account *model.Account) (*model.File, [ return nil, files, nil } -func (driver Cloud189) Proxy(r *http.Request, account *model.Account) { - r.Header.Del("Origin") -} +//func (driver Cloud189) Proxy(r *http.Request, account *model.Account) { +// r.Header.Del("Origin") +//} func (driver Cloud189) Preview(path string, account *model.Account) (interface{}, error) { return nil, base.ErrNotSupport diff --git a/drivers/alidrive/driver.go b/drivers/alidrive/driver.go index 5ab4f3be7..c8ca7f2ad 100644 --- a/drivers/alidrive/driver.go +++ b/drivers/alidrive/driver.go @@ -190,6 +190,12 @@ func (driver AliDrive) Link(args base.Args, account *model.Account) (*base.Link, return nil, fmt.Errorf("%s", e.Message) } return &base.Link{ + Headers: []base.Header{ + { + Name: "Referer", + Value: "https://www.aliyundrive.com/", + }, + }, Url: resp["url"].(string), }, nil } @@ -211,10 +217,10 @@ func (driver AliDrive) Path(path string, account *model.Account) (*model.File, [ return nil, files, nil } -func (driver AliDrive) Proxy(r *http.Request, account *model.Account) { - r.Header.Del("Origin") - r.Header.Set("Referer", "https://www.aliyundrive.com/") -} +//func (driver AliDrive) Proxy(r *http.Request, account *model.Account) { +// r.Header.Del("Origin") +// r.Header.Set("Referer", "https://www.aliyundrive.com/") +//} func (driver AliDrive) Preview(path string, account *model.Account) (interface{}, error) { file, err := driver.GetFile(path, account) diff --git a/drivers/alist/driver.go b/drivers/alist/driver.go index c7972a4dc..3919ff5a7 100644 --- a/drivers/alist/driver.go +++ b/drivers/alist/driver.go @@ -7,7 +7,6 @@ import ( "github.com/Xhofe/alist/drivers/base" "github.com/Xhofe/alist/model" "github.com/Xhofe/alist/utils" - "net/http" "path/filepath" "strings" "time" @@ -148,7 +147,7 @@ func (driver Alist) Path(path string, account *model.Account) (*model.File, []mo return nil, resp.Data.Files, nil } -func (driver Alist) Proxy(r *http.Request, account *model.Account) {} +//func (driver Alist) Proxy(r *http.Request, account *model.Account) {} func (driver Alist) Preview(path string, account *model.Account) (interface{}, error) { var resp PathResp diff --git a/drivers/baidu/driver.go b/drivers/baidu/driver.go index 2e57b0adc..1d322bff8 100644 --- a/drivers/baidu/driver.go +++ b/drivers/baidu/driver.go @@ -13,7 +13,6 @@ import ( "io" "io/ioutil" "math" - "net/http" "os" "path/filepath" "strconv" @@ -170,9 +169,9 @@ func (driver Baidu) Path(path string, account *model.Account) (*model.File, []mo return nil, files, nil } -func (driver Baidu) Proxy(r *http.Request, account *model.Account) { - r.Header.Set("User-Agent", "pan.baidu.com") -} +//func (driver Baidu) Proxy(r *http.Request, account *model.Account) { +// r.Header.Set("User-Agent", "pan.baidu.com") +//} func (driver Baidu) Preview(path string, account *model.Account) (interface{}, error) { return nil, base.ErrNotSupport diff --git a/drivers/base/driver.go b/drivers/base/driver.go index 4f075c121..1be5480ca 100644 --- a/drivers/base/driver.go +++ b/drivers/base/driver.go @@ -37,8 +37,8 @@ type Driver interface { Link(args Args, account *model.Account) (*Link, error) // Path 取路径(文件或文件夹) Path(path string, account *model.Account) (*model.File, []model.File, error) - // Proxy 代理处理 - Proxy(r *http.Request, account *model.Account) + // Deprecated Proxy 代理处理 + //Proxy(r *http.Request, account *model.Account) // Preview 预览 Preview(path string, account *model.Account) (interface{}, error) // MakeDir 创建文件夹 diff --git a/drivers/ftp/driver.go b/drivers/ftp/driver.go index 9d4c57f6b..d5915a958 100644 --- a/drivers/ftp/driver.go +++ b/drivers/ftp/driver.go @@ -7,7 +7,6 @@ import ( "github.com/Xhofe/alist/utils" "github.com/jlaffaye/ftp" log "github.com/sirupsen/logrus" - "net/http" "path/filepath" ) @@ -186,9 +185,9 @@ func (driver FTP) Path(path string, account *model.Account) (*model.File, []mode return nil, files, nil } -func (driver FTP) Proxy(r *http.Request, account *model.Account) { - -} +//func (driver FTP) Proxy(r *http.Request, account *model.Account) { +// +//} func (driver FTP) Preview(path string, account *model.Account) (interface{}, error) { return nil, base.ErrNotSupport diff --git a/drivers/google/driver.go b/drivers/google/driver.go index 8a9eb60e8..eda794b5f 100644 --- a/drivers/google/driver.go +++ b/drivers/google/driver.go @@ -8,7 +8,6 @@ import ( "github.com/Xhofe/alist/utils" log "github.com/sirupsen/logrus" "io/ioutil" - "net/http" "path/filepath" ) @@ -178,9 +177,9 @@ func (driver GoogleDrive) Path(path string, account *model.Account) (*model.File return nil, files, nil } -func (driver GoogleDrive) Proxy(r *http.Request, account *model.Account) { - r.Header.Add("Authorization", "Bearer "+account.AccessToken) -} +//func (driver GoogleDrive) Proxy(r *http.Request, account *model.Account) { +// r.Header.Add("Authorization", "Bearer "+account.AccessToken) +//} func (driver GoogleDrive) Preview(path string, account *model.Account) (interface{}, error) { return nil, base.ErrNotSupport diff --git a/drivers/lanzou/driver.go b/drivers/lanzou/driver.go index 2cb7440ea..3626d5e93 100644 --- a/drivers/lanzou/driver.go +++ b/drivers/lanzou/driver.go @@ -6,7 +6,6 @@ import ( "github.com/Xhofe/alist/model" "github.com/Xhofe/alist/utils" log "github.com/sirupsen/logrus" - "net/http" "path/filepath" ) @@ -159,9 +158,9 @@ func (driver Lanzou) Path(path string, account *model.Account) (*model.File, []m return nil, files, nil } -func (driver Lanzou) Proxy(r *http.Request, account *model.Account) { - r.Header.Del("Origin") -} +//func (driver Lanzou) Proxy(r *http.Request, account *model.Account) { +// r.Header.Del("Origin") +//} func (driver Lanzou) Preview(path string, account *model.Account) (interface{}, error) { return nil, base.ErrNotSupport diff --git a/drivers/mediatrack/driver.go b/drivers/mediatrack/driver.go index 8f37a11e5..befd5e5be 100644 --- a/drivers/mediatrack/driver.go +++ b/drivers/mediatrack/driver.go @@ -17,7 +17,6 @@ import ( log "github.com/sirupsen/logrus" "io" "io/ioutil" - "net/http" "os" "path/filepath" ) @@ -148,9 +147,9 @@ func (driver MediaTrack) Path(path string, account *model.Account) (*model.File, return nil, files, nil } -func (driver MediaTrack) Proxy(r *http.Request, account *model.Account) { - -} +//func (driver MediaTrack) Proxy(r *http.Request, account *model.Account) { +// +//} func (driver MediaTrack) Preview(path string, account *model.Account) (interface{}, error) { return nil, base.ErrNotImplement diff --git a/drivers/native/driver.go b/drivers/native/driver.go index 7b1590a30..9d03d2ff6 100644 --- a/drivers/native/driver.go +++ b/drivers/native/driver.go @@ -9,7 +9,6 @@ import ( log "github.com/sirupsen/logrus" "io" "io/ioutil" - "net/http" "os" "path/filepath" "strings" @@ -156,9 +155,9 @@ func (driver Native) Path(path string, account *model.Account) (*model.File, []m return nil, files, nil } -func (driver Native) Proxy(r *http.Request, account *model.Account) { - // unnecessary -} +//func (driver Native) Proxy(r *http.Request, account *model.Account) { +// // unnecessary +//} func (driver Native) Preview(path string, account *model.Account) (interface{}, error) { return nil, base.ErrNotSupport diff --git a/drivers/onedrive/driver.go b/drivers/onedrive/driver.go index 353e03e2f..e9e3e84c5 100644 --- a/drivers/onedrive/driver.go +++ b/drivers/onedrive/driver.go @@ -7,7 +7,6 @@ import ( "github.com/Xhofe/alist/model" "github.com/Xhofe/alist/utils" log "github.com/sirupsen/logrus" - "net/http" "path/filepath" ) @@ -201,9 +200,9 @@ func (driver Onedrive) Path(path string, account *model.Account) (*model.File, [ return nil, files, nil } -func (driver Onedrive) Proxy(r *http.Request, account *model.Account) { - r.Header.Del("Origin") -} +//func (driver Onedrive) Proxy(r *http.Request, account *model.Account) { +// r.Header.Del("Origin") +//} func (driver Onedrive) Preview(path string, account *model.Account) (interface{}, error) { return nil, base.ErrNotSupport diff --git a/drivers/pikpak/driver.go b/drivers/pikpak/driver.go index 078835c91..46ddaed36 100644 --- a/drivers/pikpak/driver.go +++ b/drivers/pikpak/driver.go @@ -12,7 +12,6 @@ import ( "github.com/aws/aws-sdk-go/service/s3/s3manager" jsoniter "github.com/json-iterator/go" log "github.com/sirupsen/logrus" - "net/http" "path/filepath" "strings" ) @@ -142,9 +141,9 @@ func (driver PikPak) Path(path string, account *model.Account) (*model.File, []m return nil, files, nil } -func (driver PikPak) Proxy(r *http.Request, account *model.Account) { - -} +//func (driver PikPak) Proxy(r *http.Request, account *model.Account) { +// +//} func (driver PikPak) Preview(path string, account *model.Account) (interface{}, error) { return nil, base.ErrNotSupport diff --git a/drivers/s3/driver.go b/drivers/s3/driver.go index 4305b3e95..ef17fb98d 100644 --- a/drivers/s3/driver.go +++ b/drivers/s3/driver.go @@ -9,7 +9,6 @@ import ( "github.com/aws/aws-sdk-go/service/s3" "github.com/aws/aws-sdk-go/service/s3/s3manager" log "github.com/sirupsen/logrus" - "net/http" "net/url" "path/filepath" "time" @@ -189,9 +188,9 @@ func (driver S3) Path(path string, account *model.Account) (*model.File, []model return nil, files, nil } -func (driver S3) Proxy(r *http.Request, account *model.Account) { - -} +//func (driver S3) Proxy(r *http.Request, account *model.Account) { +// +//} func (driver S3) Preview(path string, account *model.Account) (interface{}, error) { return nil, base.ErrNotSupport diff --git a/drivers/shandian/driver.go b/drivers/shandian/driver.go index 9a1f9af3e..506819a03 100644 --- a/drivers/shandian/driver.go +++ b/drivers/shandian/driver.go @@ -7,7 +7,6 @@ import ( "github.com/Xhofe/alist/model" "github.com/Xhofe/alist/utils" log "github.com/sirupsen/logrus" - "net/http" "path/filepath" "strconv" ) @@ -154,9 +153,9 @@ func (driver Shandian) Path(path string, account *model.Account) (*model.File, [ return nil, files, nil } -func (driver Shandian) Proxy(r *http.Request, account *model.Account) { - -} +//func (driver Shandian) Proxy(r *http.Request, account *model.Account) { +// +//} func (driver Shandian) Preview(path string, account *model.Account) (interface{}, error) { return nil, base.ErrNotSupport diff --git a/drivers/teambition/driver.go b/drivers/teambition/driver.go index 297817ed7..4d027cc6d 100644 --- a/drivers/teambition/driver.go +++ b/drivers/teambition/driver.go @@ -6,7 +6,6 @@ import ( "github.com/Xhofe/alist/model" "github.com/Xhofe/alist/utils" log "github.com/sirupsen/logrus" - "net/http" "path/filepath" ) @@ -149,9 +148,9 @@ func (driver Teambition) Path(path string, account *model.Account) (*model.File, return nil, files, nil } -func (driver Teambition) Proxy(r *http.Request, account *model.Account) { - -} +//func (driver Teambition) Proxy(r *http.Request, account *model.Account) { +// +//} func (driver Teambition) Preview(path string, account *model.Account) (interface{}, error) { return nil, base.ErrNotSupport diff --git a/drivers/webdav/driver.go b/drivers/webdav/driver.go index 0977858b4..ee11c1ef1 100644 --- a/drivers/webdav/driver.go +++ b/drivers/webdav/driver.go @@ -5,7 +5,6 @@ import ( "github.com/Xhofe/alist/drivers/base" "github.com/Xhofe/alist/model" "github.com/Xhofe/alist/utils" - "net/http" "path/filepath" ) @@ -137,9 +136,9 @@ func (driver WebDav) Path(path string, account *model.Account) (*model.File, []m return nil, files, nil } -func (driver WebDav) Proxy(r *http.Request, account *model.Account) { - -} +//func (driver WebDav) Proxy(r *http.Request, account *model.Account) { +// +//} func (driver WebDav) Preview(path string, account *model.Account) (interface{}, error) { return nil, base.ErrNotSupport diff --git a/drivers/yandex/driver.go b/drivers/yandex/driver.go index 4b1a15921..3957fec94 100644 --- a/drivers/yandex/driver.go +++ b/drivers/yandex/driver.go @@ -144,9 +144,9 @@ func (driver Yandex) Path(path string, account *model.Account) (*model.File, []m return nil, files, nil } -func (driver Yandex) Proxy(r *http.Request, account *model.Account) { - -} +//func (driver Yandex) Proxy(r *http.Request, account *model.Account) { +// +//} func (driver Yandex) Preview(path string, account *model.Account) (interface{}, error) { return nil, base.ErrNotSupport diff --git a/server/controllers/proxy.go b/server/controllers/proxy.go index e793e3573..0ffd8ac87 100644 --- a/server/controllers/proxy.go +++ b/server/controllers/proxy.go @@ -120,7 +120,9 @@ func Proxy(c *gin.Context) { for h, val := range r.Header { req.Header[h] = val } - driver.Proxy(req, account) + for _, header := range link.Headers { + req.Header.Set(header.Name, header.Value) + } res, err := HttpClient.Do(req) if err != nil { common.ErrorResp(c, err, 500)