diff --git a/drivers/123pan/driver.go b/drivers/123pan/driver.go index bd5f05dd..062bad42 100644 --- a/drivers/123pan/driver.go +++ b/drivers/123pan/driver.go @@ -16,15 +16,14 @@ type Pan123 struct {} var driverName = "123Pan" +func (driver Pan123) Config() drivers.DriverConfig { + return drivers.DriverConfig{ + OnlyProxy: false, + } +} + func (driver Pan123) Items() []drivers.Item { return []drivers.Item{ - { - Name: "proxy", - Label: "proxy", - Type: "bool", - Required: true, - Description: "allow proxy", - }, { Name: "username", Label: "username", diff --git a/drivers/189cloud/driver.go b/drivers/189cloud/driver.go index 07681c27..7deda5c3 100644 --- a/drivers/189cloud/driver.go +++ b/drivers/189cloud/driver.go @@ -15,15 +15,14 @@ type Cloud189 struct {} var driverName = "189Cloud" +func (driver Cloud189) Config() drivers.DriverConfig { + return drivers.DriverConfig{ + OnlyProxy: false, + } +} + func (driver Cloud189) Items() []drivers.Item { return []drivers.Item{ - { - Name: "proxy", - Label: "proxy", - Type: "bool", - Required: true, - Description: "allow proxy", - }, { Name: "username", Label: "username", diff --git a/drivers/alidrive/driver.go b/drivers/alidrive/driver.go index 5fd55260..7b76c69f 100644 --- a/drivers/alidrive/driver.go +++ b/drivers/alidrive/driver.go @@ -16,15 +16,14 @@ type AliDrive struct{} var driverName = "AliDrive" +func (driver AliDrive) Config() drivers.DriverConfig { + return drivers.DriverConfig{ + OnlyProxy: false, + } +} + func (driver AliDrive) Items() []drivers.Item { return []drivers.Item{ - { - Name: "proxy", - Label: "proxy", - Type: "bool", - Required: true, - Description: "allow proxy", - }, { Name: "order_by", Label: "order_by", diff --git a/drivers/driver.go b/drivers/driver.go index 7a0893a2..384fed24 100644 --- a/drivers/driver.go +++ b/drivers/driver.go @@ -8,7 +8,12 @@ import ( "net/http" ) +type DriverConfig struct { + OnlyProxy bool +} + type Driver interface { + Config() DriverConfig Items() []Item Save(account *model.Account, old *model.Account) error File(path string, account *model.Account) (*model.File, error) @@ -54,7 +59,26 @@ func GetDriver(name string) (driver Driver, ok bool) { func GetDrivers() map[string][]Item { res := make(map[string][]Item, 0) for k, v := range driversMap { - res[k] = v.Items() + if v.Config().OnlyProxy { + res[k] = v.Items() + } else { + res[k] = append([]Item{ + { + Name: "proxy", + Label: "proxy", + Type: "bool", + Required: true, + Description: "allow proxy", + }, + { + Name: "webdav_proxy", + Label: "webdav proxy", + Type: "bool", + Required: true, + Description: "Transfer the WebDAV of this account through the server", + }, + }, v.Items()...) + } } return res } diff --git a/drivers/googledrive/driver.go b/drivers/googledrive/driver.go index 36f962d7..00ffd967 100644 --- a/drivers/googledrive/driver.go +++ b/drivers/googledrive/driver.go @@ -15,6 +15,12 @@ type GoogleDrive struct{} var driverName = "GoogleDrive" +func (driver GoogleDrive) Config() drivers.DriverConfig { + return drivers.DriverConfig{ + OnlyProxy: true, + } +} + func (driver GoogleDrive) Items() []drivers.Item { return []drivers.Item{ { diff --git a/drivers/native/driver.go b/drivers/native/driver.go index e0436f53..6f08057f 100644 --- a/drivers/native/driver.go +++ b/drivers/native/driver.go @@ -18,6 +18,12 @@ type Native struct{} var driverName = "Native" +func (driver Native) Config() drivers.DriverConfig { + return drivers.DriverConfig{ + OnlyProxy: true, + } +} + func (driver Native) Items() []drivers.Item { return []drivers.Item{ { diff --git a/drivers/onedrive/driver.go b/drivers/onedrive/driver.go index 15b249b6..27c6094b 100644 --- a/drivers/onedrive/driver.go +++ b/drivers/onedrive/driver.go @@ -16,15 +16,14 @@ type Onedrive struct{} var driverName = "Onedrive" +func (driver Onedrive) Config() drivers.DriverConfig { + return drivers.DriverConfig{ + OnlyProxy: false, + } +} + func (driver Onedrive) Items() []drivers.Item { return []drivers.Item{ - { - Name: "proxy", - Label: "proxy", - Type: "bool", - Required: true, - Description: "allow proxy", - }, { Name: "zone", Label: "zone", diff --git a/model/account.go b/model/account.go index 34b55826..0a5bc79a 100644 --- a/model/account.go +++ b/model/account.go @@ -32,6 +32,7 @@ type Account struct { SiteUrl string `json:"site_url"` SiteId string `json:"site_id"` OnedriveType string `json:"onedrive_type"` + WebdavProxy bool `json:"webdav_proxy"` } var accountsMap = map[string]Account{} diff --git a/server/webdav/file.go b/server/webdav/file.go index 3b304893..230b388f 100644 --- a/server/webdav/file.go +++ b/server/webdav/file.go @@ -101,8 +101,9 @@ func GetPW(path string) string { } } -func (fs *FileSystem) Link(host, rawPath string) (string, error) { +func (fs *FileSystem) Link(r *http.Request, rawPath string) (string, error) { rawPath = utils.ParsePath(rawPath) + log.Debugf("get link path: %s", rawPath) if model.AccountsCount() > 1 && rawPath == "/" { // error } @@ -110,16 +111,22 @@ func (fs *FileSystem) Link(host, rawPath string) (string, error) { if err != nil { return "", err } - if account.Type == "Native" || account.Type == "GoogleDrive" { - link := fmt.Sprintf("//%s/p%s", host, rawPath) + link := "" + protocol := "http" + if r.TLS != nil { + protocol = "https" + } + if driver.Config().OnlyProxy || account.WebdavProxy { + link = fmt.Sprintf("%s://%s/p%s", protocol, r.Host, rawPath) if conf.CheckDown { pw := GetPW(filepath.Dir(rawPath)) link += "?pw" + pw } - log.Debugf("proxy link: %s", link) - return link, nil + } else { + link, err = driver.Link(path_, account) } - return driver.Link(path_, account) + log.Debugf("webdav get link: %s", link) + return link, err } func (fs *FileSystem) CreateDirectory(ctx context.Context, reqPath string) (interface{}, error) { diff --git a/server/webdav/webdav.go b/server/webdav/webdav.go index e666fa4f..9536fe41 100644 --- a/server/webdav/webdav.go +++ b/server/webdav/webdav.go @@ -233,8 +233,7 @@ func (h *Handler) handleGetHeadPost(w http.ResponseWriter, r *http.Request, fs * } w.Header().Set("ETag", etag) log.Debugf("url: %+v", r.URL) - host := r.Host - link, err := fs.Link(host, reqPath) + link, err := fs.Link(r, reqPath) if err != nil { return http.StatusInternalServerError, err }