🎨 change proxy interface

pull/548/head
微凉 2022-02-01 14:28:21 +08:00
parent 1b6ec94f33
commit cb2a3c2b42
20 changed files with 44 additions and 45 deletions

View File

@ -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) {

View File

@ -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) {
}

View File

@ -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) {

View File

@ -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) {

View File

@ -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

View File

@ -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"`

View File

@ -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 (

View File

@ -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) {
}

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {
}

View File

@ -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
}

View File

@ -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) {

View File

@ -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

View File

@ -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) {
}

View File

@ -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) {
}

View File

@ -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) {
}

View File

@ -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) {
}

View File

@ -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) {
}

View File

@ -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)