mirror of
https://github.com/OpenListTeam/OpenList.git
synced 2026-05-06 23:31:59 +08:00
feat(drivers/webdav): add support for 302 redirects (#1952)
* Remove the `OnlyProxy` restriction and obtain the redirected link to support 302 * Add `driver.Config` `PreferProxy` to recommend user to enable the proxy by default --------- Signed-off-by: MadDogOwner <xiaoran@xrgzs.top>
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"github.com/OpenListTeam/OpenList/v4/internal/bootstrap/patch/v3_32_0"
|
||||
"github.com/OpenListTeam/OpenList/v4/internal/bootstrap/patch/v3_41_0"
|
||||
"github.com/OpenListTeam/OpenList/v4/internal/bootstrap/patch/v4_1_8"
|
||||
"github.com/OpenListTeam/OpenList/v4/internal/bootstrap/patch/v4_1_9"
|
||||
)
|
||||
|
||||
type VersionPatches struct {
|
||||
@@ -39,4 +40,10 @@ var UpgradePatches = []VersionPatches{
|
||||
v4_1_8.FixAliasConfig,
|
||||
},
|
||||
},
|
||||
{
|
||||
Version: "v4.1.9",
|
||||
Patches: []func(){
|
||||
v4_1_9.EnableWebDavProxy,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
30
internal/bootstrap/patch/v4_1_9/webdav.go
Normal file
30
internal/bootstrap/patch/v4_1_9/webdav.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package v4_1_9
|
||||
|
||||
import (
|
||||
"github.com/OpenListTeam/OpenList/v4/internal/db"
|
||||
"github.com/OpenListTeam/OpenList/v4/pkg/utils"
|
||||
)
|
||||
|
||||
// EnableWebDavProxy updates Webdav driver storages to enable proxy
|
||||
func EnableWebDavProxy() {
|
||||
storages, _, err := db.GetStorages(1, -1)
|
||||
if err != nil {
|
||||
utils.Log.Errorf("[EnableWebDavProxy] failed to get storages: %s", err.Error())
|
||||
return
|
||||
}
|
||||
for _, s := range storages {
|
||||
if s.Driver != "WebDav" {
|
||||
continue
|
||||
}
|
||||
if !s.WebProxy {
|
||||
s.WebProxy = true
|
||||
}
|
||||
if s.WebdavPolicy == "302_redirect" {
|
||||
s.WebdavPolicy = "native_proxy"
|
||||
}
|
||||
err = db.UpdateStorage(&s)
|
||||
if err != nil {
|
||||
utils.Log.Errorf("[EnableWebDavProxy] failed to update storage [%d]%s: %s", s.ID, s.MountPath, err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,8 @@ type Config struct {
|
||||
LinkCacheMode `json:"-"`
|
||||
// if the driver only store indices of files (e.g. UrlTree)
|
||||
OnlyIndices bool `json:"only_indices"`
|
||||
// prefer proxy download even if direct link is available
|
||||
PreferProxy bool `json:"prefer_proxy"`
|
||||
}
|
||||
type LinkCacheMode int8
|
||||
|
||||
@@ -40,3 +42,7 @@ const (
|
||||
func (c Config) MustProxy() bool {
|
||||
return c.OnlyProxy || c.NoLinkURL
|
||||
}
|
||||
|
||||
func (c Config) DefaultProxy() bool {
|
||||
return c.PreferProxy
|
||||
}
|
||||
|
||||
@@ -97,17 +97,32 @@ func getMainItems(config driver.Config) []driver.Item {
|
||||
Required: true,
|
||||
})
|
||||
} else {
|
||||
items = append(items, []driver.Item{{
|
||||
Name: "web_proxy",
|
||||
Type: conf.TypeBool,
|
||||
}, {
|
||||
Name: "webdav_policy",
|
||||
Type: conf.TypeSelect,
|
||||
Options: "302_redirect,use_proxy_url,native_proxy",
|
||||
Default: "302_redirect",
|
||||
Required: true,
|
||||
},
|
||||
}...)
|
||||
if config.DefaultProxy() {
|
||||
items = append(items, []driver.Item{{
|
||||
Name: "web_proxy",
|
||||
Type: conf.TypeBool,
|
||||
Default: "true",
|
||||
}, {
|
||||
Name: "webdav_policy",
|
||||
Type: conf.TypeSelect,
|
||||
Options: "302_redirect,use_proxy_url,native_proxy",
|
||||
Default: "native_proxy",
|
||||
Required: true,
|
||||
},
|
||||
}...)
|
||||
} else {
|
||||
items = append(items, []driver.Item{{
|
||||
Name: "web_proxy",
|
||||
Type: conf.TypeBool,
|
||||
}, {
|
||||
Name: "webdav_policy",
|
||||
Type: conf.TypeSelect,
|
||||
Options: "302_redirect,use_proxy_url,native_proxy",
|
||||
Default: "302_redirect",
|
||||
Required: true,
|
||||
},
|
||||
}...)
|
||||
}
|
||||
if config.ProxyRangeOption {
|
||||
item := driver.Item{
|
||||
Name: "proxy_range",
|
||||
|
||||
Reference in New Issue
Block a user