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
9 changes: 5 additions & 4 deletions internal/model/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ type Sort struct {
}

type Proxy struct {
WebProxy bool `json:"web_proxy"`
WebdavPolicy string `json:"webdav_policy"`
ProxyRange bool `json:"proxy_range"`
DownProxyUrl string `json:"down_proxy_url"`
WebProxy bool `json:"web_proxy"`
WebdavPolicy string `json:"webdav_policy"`
ProxyRange bool `json:"proxy_range"`
DownProxyUrl string `json:"down_proxy_url"`
DownProxySign bool `json:"down_proxy_sign" gorm:"default:true"`
}

func (s *Storage) GetStorage() *Storage {
Expand Down
5 changes: 5 additions & 0 deletions internal/op/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ func getMainItems(config driver.Config) []driver.Item {
Name: "down_proxy_url",
Type: conf.TypeText,
})
items = append(items, driver.Item{
Name: "down_proxy_sign",
Type: conf.TypeBool,
Default: "true",
})
if config.LocalSort {
items = append(items, []driver.Item{{
Name: "order_by",
Expand Down
9 changes: 9 additions & 0 deletions server/common/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/internal/net"
"github.com/alist-org/alist/v3/internal/sign"
"github.com/alist-org/alist/v3/internal/stream"
"github.com/alist-org/alist/v3/pkg/http_range"
"github.com/alist-org/alist/v3/pkg/utils"
Expand Down Expand Up @@ -129,6 +130,14 @@ func ProxyRange(link *model.Link, size int64) {
}
}

func BuildDownProxyURL(downProxyURL, path string, useSign bool) string {
base := strings.Split(downProxyURL, "\n")[0]
if useSign {
return fmt.Sprintf("%s%s?sign=%s", base, utils.EncodePath(path, true), sign.Sign(path))
}
return fmt.Sprintf("%s%s", base, utils.EncodePath(path, true))
}

type InterceptResponseWriter struct {
http.ResponseWriter
io.Writer
Expand Down
7 changes: 1 addition & 6 deletions server/handles/down.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ import (
"io"
stdpath "path"
"strconv"
"strings"

"github.com/alist-org/alist/v3/internal/conf"
"github.com/alist-org/alist/v3/internal/driver"
"github.com/alist-org/alist/v3/internal/fs"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/internal/setting"
"github.com/alist-org/alist/v3/internal/sign"
"github.com/alist-org/alist/v3/pkg/utils"
"github.com/alist-org/alist/v3/server/common"
"github.com/gin-gonic/gin"
Expand Down Expand Up @@ -62,10 +60,7 @@ func Proxy(c *gin.Context) {
if downProxyUrl != "" {
_, ok := c.GetQuery("d")
if !ok {
URL := fmt.Sprintf("%s%s?sign=%s",
strings.Split(downProxyUrl, "\n")[0],
utils.EncodePath(rawPath, true),
sign.Sign(rawPath))
URL := common.BuildDownProxyURL(downProxyUrl, rawPath, storage.GetStorage().DownProxySign)
c.Redirect(302, URL)
return
}
Expand Down
9 changes: 5 additions & 4 deletions server/handles/fsread.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,11 @@ func FsGet(c *gin.Context) {
query = "?sign=" + sign.Sign(reqPath)
}
if storage.GetStorage().DownProxyUrl != "" {
rawURL = fmt.Sprintf("%s%s?sign=%s",
strings.Split(storage.GetStorage().DownProxyUrl, "\n")[0],
utils.EncodePath(reqPath, true),
sign.Sign(reqPath))
rawURL = common.BuildDownProxyURL(
storage.GetStorage().DownProxyUrl,
reqPath,
storage.GetStorage().DownProxySign,
)
} else {
rawURL = fmt.Sprintf("%s/p%s%s",
common.GetApiUrl(c.Request),
Expand Down
6 changes: 1 addition & 5 deletions server/webdav/webdav.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/alist-org/alist/v3/internal/errs"
"github.com/alist-org/alist/v3/internal/fs"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/internal/sign"
"github.com/alist-org/alist/v3/pkg/utils"
"github.com/alist-org/alist/v3/server/common"
)
Expand Down Expand Up @@ -253,10 +252,7 @@ func (h *Handler) handleGetHeadPost(w http.ResponseWriter, r *http.Request) (sta
return http.StatusInternalServerError, fmt.Errorf("webdav proxy error: %+v", err)
}
} else if storage.GetStorage().WebdavProxy() && downProxyUrl != "" {
u := fmt.Sprintf("%s%s?sign=%s",
strings.Split(downProxyUrl, "\n")[0],
utils.EncodePath(reqPath, true),
sign.Sign(reqPath))
u := common.BuildDownProxyURL(downProxyUrl, reqPath, storage.GetStorage().DownProxySign)
w.Header().Set("Cache-Control", "max-age=0, no-cache, no-store, must-revalidate")
http.Redirect(w, r, u, http.StatusFound)
} else {
Expand Down