Merge pull request #9394 from okatu-loli/feat/proxy-sign-switch

feat(proxy): Added configurable signature for down proxy URLs
This commit is contained in:
JoaHuang 2025-12-22 11:29:04 +08:00 committed by GitHub
commit ced614c382
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 26 additions and 19 deletions

View File

@ -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 {

View File

@ -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",

View File

@ -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"
@ -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

View File

@ -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"
@ -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
}

View File

@ -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),

View File

@ -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"
)
@ -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 {