mirror of
https://github.com/OpenListTeam/OpenList.git
synced 2025-09-19 12:16:24 +08:00
feat(proxy): add disable proxy sign (#764)
* feat(proxy): add disable proxy sign * Update driver.go * GenerateDownProxyUrl * . * Update internal/op/driver.go Signed-off-by: j2rong4cn <36783515+j2rong4cn@users.noreply.github.com> * . --------- Signed-off-by: j2rong4cn <36783515+j2rong4cn@users.noreply.github.com> Co-authored-by: j2rong4cn <j2rong@qq.com> Co-authored-by: j2rong4cn <36783515+j2rong4cn@users.noreply.github.com>
This commit is contained in:
@ -39,7 +39,7 @@ func (d *QuarkOrUC) Init(ctx context.Context) error {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
if d.AdditionVersion != 2 {
|
if d.AdditionVersion != 2 {
|
||||||
d.AdditionVersion = 2
|
d.AdditionVersion = 2
|
||||||
if !d.UseTransCodingAddress && len(d.DownProxyUrl) == 0 {
|
if !d.UseTransCodingAddress && len(d.DownProxyURL) == 0 {
|
||||||
d.WebProxy = true
|
d.WebProxy = true
|
||||||
d.WebdavPolicy = "native_proxy"
|
d.WebdavPolicy = "native_proxy"
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,9 @@ type Proxy struct {
|
|||||||
WebProxy bool `json:"web_proxy"`
|
WebProxy bool `json:"web_proxy"`
|
||||||
WebdavPolicy string `json:"webdav_policy"`
|
WebdavPolicy string `json:"webdav_policy"`
|
||||||
ProxyRange bool `json:"proxy_range"`
|
ProxyRange bool `json:"proxy_range"`
|
||||||
DownProxyUrl string `json:"down_proxy_url"`
|
DownProxyURL string `json:"down_proxy_url"`
|
||||||
|
//Disable sign for DownProxyURL
|
||||||
|
DisableProxySign bool `json:"disable_proxy_sign"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) GetStorage() *Storage {
|
func (s *Storage) GetStorage() *Storage {
|
||||||
@ -50,10 +52,6 @@ func (p Proxy) Webdav302() bool {
|
|||||||
return p.WebdavPolicy == "302_redirect"
|
return p.WebdavPolicy == "302_redirect"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p Proxy) WebdavProxy() bool {
|
func (p Proxy) WebdavProxyURL() bool {
|
||||||
return p.WebdavPolicy == "use_proxy_url"
|
return p.WebdavPolicy == "use_proxy_url"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p Proxy) WebdavNative() bool {
|
|
||||||
return !p.Webdav302() && !p.WebdavProxy()
|
|
||||||
}
|
|
||||||
|
@ -117,6 +117,12 @@ func getMainItems(config driver.Config) []driver.Item {
|
|||||||
Name: "down_proxy_url",
|
Name: "down_proxy_url",
|
||||||
Type: conf.TypeText,
|
Type: conf.TypeText,
|
||||||
})
|
})
|
||||||
|
items = append(items, driver.Item{
|
||||||
|
Name: "disable_proxy_sign",
|
||||||
|
Type: conf.TypeBool,
|
||||||
|
Default: "false",
|
||||||
|
Help: "Disable sign for Download proxy URL",
|
||||||
|
})
|
||||||
if config.LocalSort {
|
if config.LocalSort {
|
||||||
items = append(items, []driver.Item{{
|
items = append(items, []driver.Item{{
|
||||||
Name: "order_by",
|
Name: "order_by",
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/OpenListTeam/OpenList/v4/internal/conf"
|
"github.com/OpenListTeam/OpenList/v4/internal/conf"
|
||||||
"github.com/OpenListTeam/OpenList/v4/internal/model"
|
"github.com/OpenListTeam/OpenList/v4/internal/model"
|
||||||
"github.com/OpenListTeam/OpenList/v4/internal/net"
|
"github.com/OpenListTeam/OpenList/v4/internal/net"
|
||||||
|
"github.com/OpenListTeam/OpenList/v4/internal/sign"
|
||||||
"github.com/OpenListTeam/OpenList/v4/internal/stream"
|
"github.com/OpenListTeam/OpenList/v4/internal/stream"
|
||||||
"github.com/OpenListTeam/OpenList/v4/pkg/utils"
|
"github.com/OpenListTeam/OpenList/v4/pkg/utils"
|
||||||
)
|
)
|
||||||
@ -140,3 +141,18 @@ func (ww *WrittenResponseWriter) Write(p []byte) (int, error) {
|
|||||||
func (ww *WrittenResponseWriter) IsWritten() bool {
|
func (ww *WrittenResponseWriter) IsWritten() bool {
|
||||||
return ww.written
|
return ww.written
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GenerateDownProxyURL(storage *model.Storage, reqPath string) string {
|
||||||
|
if storage.DownProxyURL == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
query := ""
|
||||||
|
if !storage.DisableProxySign {
|
||||||
|
query = "?sign=" + sign.Sign(reqPath)
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%s%s%s",
|
||||||
|
strings.Split(storage.DownProxyURL, "\n")[0],
|
||||||
|
utils.EncodePath(reqPath, true),
|
||||||
|
query,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
@ -6,7 +6,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
stdpath "path"
|
stdpath "path"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/OpenListTeam/OpenList/v4/internal/conf"
|
"github.com/OpenListTeam/OpenList/v4/internal/conf"
|
||||||
"github.com/OpenListTeam/OpenList/v4/internal/driver"
|
"github.com/OpenListTeam/OpenList/v4/internal/driver"
|
||||||
@ -14,7 +13,6 @@ import (
|
|||||||
"github.com/OpenListTeam/OpenList/v4/internal/model"
|
"github.com/OpenListTeam/OpenList/v4/internal/model"
|
||||||
"github.com/OpenListTeam/OpenList/v4/internal/net"
|
"github.com/OpenListTeam/OpenList/v4/internal/net"
|
||||||
"github.com/OpenListTeam/OpenList/v4/internal/setting"
|
"github.com/OpenListTeam/OpenList/v4/internal/setting"
|
||||||
"github.com/OpenListTeam/OpenList/v4/internal/sign"
|
|
||||||
"github.com/OpenListTeam/OpenList/v4/pkg/utils"
|
"github.com/OpenListTeam/OpenList/v4/pkg/utils"
|
||||||
"github.com/OpenListTeam/OpenList/v4/server/common"
|
"github.com/OpenListTeam/OpenList/v4/server/common"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@ -58,15 +56,9 @@ func Proxy(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if canProxy(storage, filename) {
|
if canProxy(storage, filename) {
|
||||||
downProxyUrl := storage.GetStorage().DownProxyUrl
|
if _, ok := c.GetQuery("d"); !ok {
|
||||||
if downProxyUrl != "" {
|
if url := common.GenerateDownProxyURL(storage.GetStorage(), rawPath); url != "" {
|
||||||
_, ok := c.GetQuery("d")
|
c.Redirect(302, url)
|
||||||
if !ok {
|
|
||||||
URL := fmt.Sprintf("%s%s?sign=%s",
|
|
||||||
strings.Split(downProxyUrl, "\n")[0],
|
|
||||||
utils.EncodePath(rawPath, true),
|
|
||||||
sign.Sign(rawPath))
|
|
||||||
c.Redirect(302, URL)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -172,7 +164,7 @@ func proxy(c *gin.Context, link *model.Link, file model.Obj, proxyRange bool) {
|
|||||||
// 4. proxy_types
|
// 4. proxy_types
|
||||||
// solution: text_file + shouldProxy()
|
// solution: text_file + shouldProxy()
|
||||||
func canProxy(storage driver.Driver, filename string) bool {
|
func canProxy(storage driver.Driver, filename string) bool {
|
||||||
if storage.Config().MustProxy() || storage.GetStorage().WebProxy || storage.GetStorage().WebdavProxy() {
|
if storage.Config().MustProxy() || storage.GetStorage().WebProxy || storage.GetStorage().WebdavProxyURL() {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if utils.SliceContains(conf.SlicesMap[conf.ProxyTypes], utils.Ext(filename)) {
|
if utils.SliceContains(conf.SlicesMap[conf.ProxyTypes], utils.Ext(filename)) {
|
||||||
|
@ -285,16 +285,12 @@ func FsGet(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if storage.Config().MustProxy() || storage.GetStorage().WebProxy {
|
if storage.Config().MustProxy() || storage.GetStorage().WebProxy {
|
||||||
query := ""
|
rawURL = common.GenerateDownProxyURL(storage.GetStorage(), reqPath)
|
||||||
if isEncrypt(meta, reqPath) || setting.GetBool(conf.SignAll) {
|
if rawURL == "" {
|
||||||
query = "?sign=" + sign.Sign(reqPath)
|
query := ""
|
||||||
}
|
if isEncrypt(meta, reqPath) || setting.GetBool(conf.SignAll) {
|
||||||
if storage.GetStorage().DownProxyUrl != "" {
|
query = "?sign=" + sign.Sign(reqPath)
|
||||||
rawURL = fmt.Sprintf("%s%s?sign=%s",
|
}
|
||||||
strings.Split(storage.GetStorage().DownProxyUrl, "\n")[0],
|
|
||||||
utils.EncodePath(reqPath, true),
|
|
||||||
sign.Sign(reqPath))
|
|
||||||
} else {
|
|
||||||
rawURL = fmt.Sprintf("%s/p%s%s",
|
rawURL = fmt.Sprintf("%s/p%s%s",
|
||||||
common.GetApiUrl(c),
|
common.GetApiUrl(c),
|
||||||
utils.EncodePath(reqPath, true),
|
utils.EncodePath(reqPath, true),
|
||||||
|
@ -24,7 +24,6 @@ import (
|
|||||||
"github.com/OpenListTeam/OpenList/v4/internal/errs"
|
"github.com/OpenListTeam/OpenList/v4/internal/errs"
|
||||||
"github.com/OpenListTeam/OpenList/v4/internal/fs"
|
"github.com/OpenListTeam/OpenList/v4/internal/fs"
|
||||||
"github.com/OpenListTeam/OpenList/v4/internal/model"
|
"github.com/OpenListTeam/OpenList/v4/internal/model"
|
||||||
"github.com/OpenListTeam/OpenList/v4/internal/sign"
|
|
||||||
"github.com/OpenListTeam/OpenList/v4/pkg/utils"
|
"github.com/OpenListTeam/OpenList/v4/pkg/utils"
|
||||||
"github.com/OpenListTeam/OpenList/v4/server/common"
|
"github.com/OpenListTeam/OpenList/v4/server/common"
|
||||||
)
|
)
|
||||||
@ -238,37 +237,39 @@ func (h *Handler) handleGetHeadPost(w http.ResponseWriter, r *http.Request) (sta
|
|||||||
}
|
}
|
||||||
// Let ServeContent determine the Content-Type header.
|
// Let ServeContent determine the Content-Type header.
|
||||||
storage, _ := fs.GetStorage(reqPath, &fs.GetStoragesArgs{})
|
storage, _ := fs.GetStorage(reqPath, &fs.GetStoragesArgs{})
|
||||||
downProxyUrl := storage.GetStorage().DownProxyUrl
|
if storage.GetStorage().Webdav302() {
|
||||||
if storage.GetStorage().WebdavNative() || (storage.GetStorage().WebdavProxy() && downProxyUrl == "") {
|
|
||||||
link, _, err := fs.Link(ctx, reqPath, model.LinkArgs{Header: r.Header})
|
|
||||||
if err != nil {
|
|
||||||
return http.StatusInternalServerError, err
|
|
||||||
}
|
|
||||||
defer link.Close()
|
|
||||||
if storage.GetStorage().ProxyRange {
|
|
||||||
link = common.ProxyRange(ctx, link, fi.GetSize())
|
|
||||||
}
|
|
||||||
err = common.Proxy(w, r, link, fi)
|
|
||||||
if err != nil {
|
|
||||||
if statusCode, ok := errors.Unwrap(err).(net.ErrorHttpStatusCode); ok {
|
|
||||||
return int(statusCode), err
|
|
||||||
}
|
|
||||||
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))
|
|
||||||
w.Header().Set("Cache-Control", "max-age=0, no-cache, no-store, must-revalidate")
|
|
||||||
http.Redirect(w, r, u, http.StatusFound)
|
|
||||||
} else {
|
|
||||||
link, _, err := fs.Link(ctx, reqPath, model.LinkArgs{IP: utils.ClientIP(r), Header: r.Header, Redirect: true})
|
link, _, err := fs.Link(ctx, reqPath, model.LinkArgs{IP: utils.ClientIP(r), Header: r.Header, Redirect: true})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return http.StatusInternalServerError, err
|
return http.StatusInternalServerError, err
|
||||||
}
|
}
|
||||||
defer link.Close()
|
defer link.Close()
|
||||||
http.Redirect(w, r, link.URL, http.StatusFound)
|
http.Redirect(w, r, link.URL, http.StatusFound)
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if storage.GetStorage().WebdavProxyURL() {
|
||||||
|
if url := common.GenerateDownProxyURL(storage.GetStorage(), reqPath); url != "" {
|
||||||
|
w.Header().Set("Cache-Control", "max-age=0, no-cache, no-store, must-revalidate")
|
||||||
|
http.Redirect(w, r, url, http.StatusFound)
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
link, _, err := fs.Link(ctx, reqPath, model.LinkArgs{Header: r.Header})
|
||||||
|
if err != nil {
|
||||||
|
return http.StatusInternalServerError, err
|
||||||
|
}
|
||||||
|
defer link.Close()
|
||||||
|
|
||||||
|
if storage.GetStorage().ProxyRange {
|
||||||
|
link = common.ProxyRange(ctx, link, fi.GetSize())
|
||||||
|
}
|
||||||
|
err = common.Proxy(w, r, link, fi)
|
||||||
|
if err != nil {
|
||||||
|
if statusCode, ok := errors.Unwrap(err).(net.ErrorHttpStatusCode); ok {
|
||||||
|
return int(statusCode), err
|
||||||
|
}
|
||||||
|
return http.StatusInternalServerError, fmt.Errorf("webdav proxy error: %+v", err)
|
||||||
}
|
}
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user