Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion drivers/123/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var config = driver.Config{
Name: "123Pan",
DefaultRoot: "0",
LocalSort: true,
PreferProxy: true,
}

func init() {
Expand All @@ -28,7 +29,7 @@ func init() {
return &Pan123{
Addition: Addition{
UploadThread: 3,
Platform: "web",
Platform: "web",
},
}
})
Expand Down
1 change: 1 addition & 0 deletions drivers/123_open/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var config = driver.Config{
Name: "123 Open",
DefaultRoot: "0",
LocalSort: true,
PreferProxy: true,
}

func init() {
Expand Down
1 change: 1 addition & 0 deletions drivers/123_share/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var config = driver.Config{
LocalSort: true,
NoUpload: true,
DefaultRoot: "0",
PreferProxy: true,
}

func init() {
Expand Down
4 changes: 3 additions & 1 deletion drivers/baidu_netdisk/meta.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package baidu_netdisk

import (
"time"

"github.com/OpenListTeam/OpenList/v4/internal/driver"
"github.com/OpenListTeam/OpenList/v4/internal/op"
"time"
)

type Addition struct {
Expand Down Expand Up @@ -39,6 +40,7 @@ const (
var config = driver.Config{
Name: "BaiduNetdisk",
DefaultRoot: "/",
PreferProxy: true,
}

func init() {
Expand Down
18 changes: 18 additions & 0 deletions drivers/webdav/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package webdav

import (
"context"
"fmt"
"net/http"
"os"
"path"
"time"

"github.com/OpenListTeam/OpenList/v4/drivers/base"
"github.com/OpenListTeam/OpenList/v4/internal/driver"
"github.com/OpenListTeam/OpenList/v4/internal/model"
"github.com/OpenListTeam/OpenList/v4/pkg/cron"
Expand Down Expand Up @@ -68,6 +70,22 @@ func (d *WebDav) Link(ctx context.Context, file model.Obj, args model.LinkArgs)
if err != nil {
return nil, err
}
if args.Redirect {
// get the url after redirect
req := base.NoRedirectClient.R()
req.Header = header
req.SetDoNotParseResponse(true)
res, err := req.Get(url)
if err != nil {
return nil, err
}
_ = res.RawResponse.Body.Close()
if (res.StatusCode() == 302 || res.StatusCode() == 307 || res.StatusCode() == 308) && res.Header().Get("location") != "" {
url = res.Header().Get("location")
} else {
return nil, fmt.Errorf("redirect failed, status: %d", res.StatusCode())
}
}
return &model.Link{
URL: url,
Header: header,
Expand Down
2 changes: 1 addition & 1 deletion drivers/webdav/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ type Addition struct {
var config = driver.Config{
Name: "WebDav",
LocalSort: true,
OnlyProxy: true,
DefaultRoot: "/",
PreferProxy: true,
}

func init() {
Expand Down
7 changes: 7 additions & 0 deletions internal/bootstrap/patch/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -39,4 +40,10 @@ var UpgradePatches = []VersionPatches{
v4_1_8.FixAliasConfig,
},
},
{
Version: "v4.1.9",
Patches: []func(){
v4_1_9.EnableWebDavProxy,
},
},
}
30 changes: 30 additions & 0 deletions internal/bootstrap/patch/v4_1_9/webdav.go
Original file line number Diff line number Diff line change
@@ -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())
}
}
}
6 changes: 6 additions & 0 deletions internal/driver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -40,3 +42,7 @@ const (
func (c Config) MustProxy() bool {
return c.OnlyProxy || c.NoLinkURL
}

func (c Config) DefaultProxy() bool {
return c.PreferProxy
}
37 changes: 26 additions & 11 deletions internal/op/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down