diff --git a/drivers/123/driver.go b/drivers/123/driver.go index dc6646a0..9c63b667 100644 --- a/drivers/123/driver.go +++ b/drivers/123/driver.go @@ -12,10 +12,10 @@ import ( "github.com/aws/aws-sdk-go/aws/credentials" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/s3/s3manager" - "github.com/gin-gonic/gin" log "github.com/sirupsen/logrus" "io" "io/ioutil" + "net/http" "net/url" "os" "path/filepath" @@ -197,8 +197,8 @@ func (driver Pan123) Path(path string, account *model.Account) (*model.File, []m return nil, files, nil } -func (driver Pan123) Proxy(c *gin.Context, account *model.Account) { - c.Request.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) { diff --git a/drivers/139/driver.go b/drivers/139/driver.go index 27b4ca02..8b7a3349 100644 --- a/drivers/139/driver.go +++ b/drivers/139/driver.go @@ -7,7 +7,6 @@ import ( "github.com/Xhofe/alist/drivers/base" "github.com/Xhofe/alist/model" "github.com/Xhofe/alist/utils" - "github.com/gin-gonic/gin" log "github.com/sirupsen/logrus" "io" "math" @@ -163,7 +162,7 @@ func (driver Cloud139) Path(path string, account *model.Account) (*model.File, [ return nil, files, nil } -func (driver Cloud139) Proxy(c *gin.Context, account *model.Account) { +func (driver Cloud139) Proxy(r *http.Request, account *model.Account) { } diff --git a/drivers/189/driver.go b/drivers/189/driver.go index 296f2bbc..22ca7926 100644 --- a/drivers/189/driver.go +++ b/drivers/189/driver.go @@ -6,8 +6,8 @@ import ( "github.com/Xhofe/alist/drivers/base" "github.com/Xhofe/alist/model" "github.com/Xhofe/alist/utils" - "github.com/gin-gonic/gin" log "github.com/sirupsen/logrus" + "net/http" "path/filepath" ) @@ -198,8 +198,8 @@ func (driver Cloud189) Path(path string, account *model.Account) (*model.File, [ return nil, files, nil } -func (driver Cloud189) Proxy(ctx *gin.Context, account *model.Account) { - ctx.Request.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) { diff --git a/drivers/alidrive/driver.go b/drivers/alidrive/driver.go index 85d80d7e..5ab4f3be 100644 --- a/drivers/alidrive/driver.go +++ b/drivers/alidrive/driver.go @@ -8,7 +8,6 @@ import ( "github.com/Xhofe/alist/drivers/base" "github.com/Xhofe/alist/model" "github.com/Xhofe/alist/utils" - "github.com/gin-gonic/gin" "github.com/robfig/cron/v3" log "github.com/sirupsen/logrus" "io" @@ -212,9 +211,9 @@ func (driver AliDrive) Path(path string, account *model.Account) (*model.File, [ return nil, files, nil } -func (driver AliDrive) Proxy(c *gin.Context, account *model.Account) { - c.Request.Header.Del("Origin") - c.Request.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) { diff --git a/drivers/alist/driver.go b/drivers/alist/driver.go index 044cba70..c7972a4d 100644 --- a/drivers/alist/driver.go +++ b/drivers/alist/driver.go @@ -7,7 +7,7 @@ import ( "github.com/Xhofe/alist/drivers/base" "github.com/Xhofe/alist/model" "github.com/Xhofe/alist/utils" - "github.com/gin-gonic/gin" + "net/http" "path/filepath" "strings" "time" @@ -148,7 +148,7 @@ func (driver Alist) Path(path string, account *model.Account) (*model.File, []mo return nil, resp.Data.Files, nil } -func (driver Alist) Proxy(c *gin.Context, 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/base/driver.go b/drivers/base/driver.go index 0c5c7ad1..4f075c12 100644 --- a/drivers/base/driver.go +++ b/drivers/base/driver.go @@ -2,7 +2,6 @@ package base import ( "github.com/Xhofe/alist/model" - "github.com/gin-gonic/gin" "github.com/go-resty/resty/v2" log "github.com/sirupsen/logrus" "net/http" @@ -39,7 +38,7 @@ type Driver interface { // Path 取路径(文件或文件夹) Path(path string, account *model.Account) (*model.File, []model.File, error) // Proxy 代理处理 - Proxy(c *gin.Context, account *model.Account) + Proxy(r *http.Request, account *model.Account) // Preview 预览 Preview(path string, account *model.Account) (interface{}, error) // MakeDir 创建文件夹 @@ -62,6 +61,7 @@ type Item struct { Name string `json:"name"` Label string `json:"label"` Type string `json:"type"` + Default string `json:"default"` Values string `json:"values"` Required bool `json:"required"` Description string `json:"description"` diff --git a/drivers/base/types.go b/drivers/base/types.go index 23348262..5cd2c8c4 100644 --- a/drivers/base/types.go +++ b/drivers/base/types.go @@ -13,6 +13,7 @@ var ( ErrNotFolder = errors.New("not a folder") ErrEmptyFile = errors.New("empty file") ErrRelativePath = errors.New("access using relative path is not allowed") + ErrEmptyToken = errors.New("empty token") ) const ( diff --git a/drivers/ftp/driver.go b/drivers/ftp/driver.go index 6132c8a4..9d4c57f6 100644 --- a/drivers/ftp/driver.go +++ b/drivers/ftp/driver.go @@ -5,9 +5,9 @@ import ( "github.com/Xhofe/alist/drivers/base" "github.com/Xhofe/alist/model" "github.com/Xhofe/alist/utils" - "github.com/gin-gonic/gin" "github.com/jlaffaye/ftp" log "github.com/sirupsen/logrus" + "net/http" "path/filepath" ) @@ -186,7 +186,7 @@ func (driver FTP) Path(path string, account *model.Account) (*model.File, []mode return nil, files, nil } -func (driver FTP) Proxy(c *gin.Context, account *model.Account) { +func (driver FTP) Proxy(r *http.Request, account *model.Account) { } diff --git a/drivers/google/driver.go b/drivers/google/driver.go index af64ebb8..8a9eb60e 100644 --- a/drivers/google/driver.go +++ b/drivers/google/driver.go @@ -6,9 +6,9 @@ import ( "github.com/Xhofe/alist/drivers/base" "github.com/Xhofe/alist/model" "github.com/Xhofe/alist/utils" - "github.com/gin-gonic/gin" log "github.com/sirupsen/logrus" "io/ioutil" + "net/http" "path/filepath" ) @@ -178,8 +178,8 @@ func (driver GoogleDrive) Path(path string, account *model.Account) (*model.File return nil, files, nil } -func (driver GoogleDrive) Proxy(c *gin.Context, account *model.Account) { - c.Request.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) { diff --git a/drivers/lanzou/driver.go b/drivers/lanzou/driver.go index 16363244..2cb7440e 100644 --- a/drivers/lanzou/driver.go +++ b/drivers/lanzou/driver.go @@ -5,8 +5,8 @@ import ( "github.com/Xhofe/alist/drivers/base" "github.com/Xhofe/alist/model" "github.com/Xhofe/alist/utils" - "github.com/gin-gonic/gin" log "github.com/sirupsen/logrus" + "net/http" "path/filepath" ) @@ -159,8 +159,8 @@ func (driver Lanzou) Path(path string, account *model.Account) (*model.File, []m return nil, files, nil } -func (driver Lanzou) Proxy(c *gin.Context, account *model.Account) { - c.Request.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) { diff --git a/drivers/mediatrack/driver.go b/drivers/mediatrack/driver.go index 8f3245db..8f37a11e 100644 --- a/drivers/mediatrack/driver.go +++ b/drivers/mediatrack/driver.go @@ -12,12 +12,12 @@ import ( "github.com/aws/aws-sdk-go/aws/credentials" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/s3/s3manager" - "github.com/gin-gonic/gin" "github.com/google/uuid" jsoniter "github.com/json-iterator/go" log "github.com/sirupsen/logrus" "io" "io/ioutil" + "net/http" "os" "path/filepath" ) @@ -148,7 +148,7 @@ func (driver MediaTrack) Path(path string, account *model.Account) (*model.File, return nil, files, nil } -func (driver MediaTrack) Proxy(c *gin.Context, account *model.Account) { +func (driver MediaTrack) Proxy(r *http.Request, account *model.Account) { } diff --git a/drivers/native/driver.go b/drivers/native/driver.go index 572bbbf9..7b1590a3 100644 --- a/drivers/native/driver.go +++ b/drivers/native/driver.go @@ -6,10 +6,10 @@ import ( "github.com/Xhofe/alist/drivers/base" "github.com/Xhofe/alist/model" "github.com/Xhofe/alist/utils" - "github.com/gin-gonic/gin" log "github.com/sirupsen/logrus" "io" "io/ioutil" + "net/http" "os" "path/filepath" "strings" @@ -156,7 +156,7 @@ func (driver Native) Path(path string, account *model.Account) (*model.File, []m return nil, files, nil } -func (driver Native) Proxy(c *gin.Context, account *model.Account) { +func (driver Native) Proxy(r *http.Request, account *model.Account) { // unnecessary } diff --git a/drivers/onedrive/driver.go b/drivers/onedrive/driver.go index 6355c493..e0b80a8a 100644 --- a/drivers/onedrive/driver.go +++ b/drivers/onedrive/driver.go @@ -6,9 +6,9 @@ import ( "github.com/Xhofe/alist/drivers/base" "github.com/Xhofe/alist/model" "github.com/Xhofe/alist/utils" - "github.com/gin-gonic/gin" "github.com/robfig/cron/v3" log "github.com/sirupsen/logrus" + "net/http" "path/filepath" ) @@ -205,8 +205,8 @@ func (driver Onedrive) Path(path string, account *model.Account) (*model.File, [ return nil, files, nil } -func (driver Onedrive) Proxy(c *gin.Context, account *model.Account) { - c.Request.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) { diff --git a/drivers/onedrive/onedrive.go b/drivers/onedrive/onedrive.go index 9967b950..df46c5cc 100644 --- a/drivers/onedrive/onedrive.go +++ b/drivers/onedrive/onedrive.go @@ -81,7 +81,7 @@ type OneTokenErr struct { func (driver Onedrive) RefreshToken(account *model.Account) error { err := driver.refreshToken(account) - if err != nil && err.Error() == "empty refresh_token" { + if err != nil && err == base.ErrEmptyToken { return driver.refreshToken(account) } return err @@ -109,8 +109,8 @@ func (driver Onedrive) refreshToken(account *model.Account) error { account.Status = "work" } if resp.RefreshToken == "" { - account.Status = "empty refresh_token" - return errors.New("empty refresh_token") + account.Status = base.ErrEmptyToken.Error() + return base.ErrEmptyToken } account.RefreshToken, account.AccessToken = resp.RefreshToken, resp.AccessToken return nil diff --git a/drivers/pikpak/driver.go b/drivers/pikpak/driver.go index 73cb118a..078835c9 100644 --- a/drivers/pikpak/driver.go +++ b/drivers/pikpak/driver.go @@ -10,9 +10,9 @@ import ( "github.com/aws/aws-sdk-go/aws/credentials" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/s3/s3manager" - "github.com/gin-gonic/gin" jsoniter "github.com/json-iterator/go" log "github.com/sirupsen/logrus" + "net/http" "path/filepath" "strings" ) @@ -142,7 +142,7 @@ func (driver PikPak) Path(path string, account *model.Account) (*model.File, []m return nil, files, nil } -func (driver PikPak) Proxy(c *gin.Context, account *model.Account) { +func (driver PikPak) Proxy(r *http.Request, account *model.Account) { } diff --git a/drivers/s3/driver.go b/drivers/s3/driver.go index ea103577..4305b3e9 100644 --- a/drivers/s3/driver.go +++ b/drivers/s3/driver.go @@ -8,8 +8,8 @@ import ( "github.com/Xhofe/alist/utils" "github.com/aws/aws-sdk-go/service/s3" "github.com/aws/aws-sdk-go/service/s3/s3manager" - "github.com/gin-gonic/gin" log "github.com/sirupsen/logrus" + "net/http" "net/url" "path/filepath" "time" @@ -189,7 +189,7 @@ func (driver S3) Path(path string, account *model.Account) (*model.File, []model return nil, files, nil } -func (driver S3) Proxy(c *gin.Context, account *model.Account) { +func (driver S3) Proxy(r *http.Request, account *model.Account) { } diff --git a/drivers/shandian/driver.go b/drivers/shandian/driver.go index d3b66094..9a1f9af3 100644 --- a/drivers/shandian/driver.go +++ b/drivers/shandian/driver.go @@ -6,8 +6,8 @@ import ( "github.com/Xhofe/alist/drivers/base" "github.com/Xhofe/alist/model" "github.com/Xhofe/alist/utils" - "github.com/gin-gonic/gin" log "github.com/sirupsen/logrus" + "net/http" "path/filepath" "strconv" ) @@ -154,7 +154,7 @@ func (driver Shandian) Path(path string, account *model.Account) (*model.File, [ return nil, files, nil } -func (driver Shandian) Proxy(c *gin.Context, account *model.Account) { +func (driver Shandian) Proxy(r *http.Request, account *model.Account) { } diff --git a/drivers/teambition/driver.go b/drivers/teambition/driver.go index a2189d24..297817ed 100644 --- a/drivers/teambition/driver.go +++ b/drivers/teambition/driver.go @@ -5,8 +5,8 @@ import ( "github.com/Xhofe/alist/drivers/base" "github.com/Xhofe/alist/model" "github.com/Xhofe/alist/utils" - "github.com/gin-gonic/gin" log "github.com/sirupsen/logrus" + "net/http" "path/filepath" ) @@ -149,7 +149,7 @@ func (driver Teambition) Path(path string, account *model.Account) (*model.File, return nil, files, nil } -func (driver Teambition) Proxy(c *gin.Context, account *model.Account) { +func (driver Teambition) Proxy(r *http.Request, account *model.Account) { } diff --git a/drivers/webdav/driver.go b/drivers/webdav/driver.go index 0385f223..0977858b 100644 --- a/drivers/webdav/driver.go +++ b/drivers/webdav/driver.go @@ -5,7 +5,7 @@ import ( "github.com/Xhofe/alist/drivers/base" "github.com/Xhofe/alist/model" "github.com/Xhofe/alist/utils" - "github.com/gin-gonic/gin" + "net/http" "path/filepath" ) @@ -137,7 +137,7 @@ func (driver WebDav) Path(path string, account *model.Account) (*model.File, []m return nil, files, nil } -func (driver WebDav) Proxy(c *gin.Context, account *model.Account) { +func (driver WebDav) Proxy(r *http.Request, account *model.Account) { } diff --git a/server/controllers/proxy.go b/server/controllers/proxy.go index 7a29908a..e793e357 100644 --- a/server/controllers/proxy.go +++ b/server/controllers/proxy.go @@ -105,7 +105,6 @@ func Proxy(c *gin.Context) { // Text(c, link) // return //} - driver.Proxy(c, account) r := c.Request w := c.Writer //target, err := url.Parse(link.Url) @@ -121,6 +120,7 @@ func Proxy(c *gin.Context) { for h, val := range r.Header { req.Header[h] = val } + driver.Proxy(req, account) res, err := HttpClient.Do(req) if err != nil { common.ErrorResp(c, err, 500)