mirror of https://github.com/Xhofe/alist
✨ webdav proxy
parent
4ff2756572
commit
ffdd88ec66
|
@ -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",
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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{
|
||||
{
|
||||
|
|
|
@ -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{
|
||||
{
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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{}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue