Skip to content

Commit

Permalink
feat: add ignore direct link params (close #5434)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Oct 26, 2023
1 parent 4fc0a77 commit c0f9c8e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions internal/bootstrap/data/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func InitialSettings() []model.SettingItem {
{Key: conf.OcrApi, Value: "https://api.nn.ci/ocr/file/json", Type: conf.TypeString, Group: model.GLOBAL},
{Key: conf.FilenameCharMapping, Value: `{"/": "|"}`, Type: conf.TypeText, Group: model.GLOBAL},
{Key: conf.ForwardDirectLinkParams, Value: "false", Type: conf.TypeBool, Group: model.GLOBAL},
{Key: conf.IgnoreDirectLinkParams, Value: "sign,alist_ts", Type: conf.TypeString, Group: model.GLOBAL},
{Key: conf.WebauthnLoginEnabled, Value: "false", Type: conf.TypeBool, Group: model.GLOBAL, Flag: model.PUBLIC},

// aria2 settings
Expand Down
1 change: 1 addition & 0 deletions internal/conf/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const (
OcrApi = "ocr_api"
FilenameCharMapping = "filename_char_mapping"
ForwardDirectLinkParams = "forward_direct_link_params"
IgnoreDirectLinkParams = "ignore_direct_link_params"
WebauthnLoginEnabled = "webauthn_login_enabled"

// index
Expand Down
4 changes: 4 additions & 0 deletions internal/op/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ var settingItemHooks = map[string]SettingItemHook{
log.Debugf("filename char mapping: %+v", conf.FilenameCharMap)
return nil
},
conf.IgnoreDirectLinkParams: func(item *model.SettingItem) error {
conf.SlicesMap[conf.IgnoreDirectLinkParams] = strings.Split(item.Value, ",")
return nil
},
}

func RegisterSettingItemHook(key string, hook SettingItemHook) {
Expand Down
8 changes: 6 additions & 2 deletions server/handles/down.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ func Down(c *gin.Context) {
c.Header("Cache-Control", "max-age=0, no-cache, no-store, must-revalidate")
if setting.GetBool(conf.ForwardDirectLinkParams) {
query := c.Request.URL.Query()
query.Del("sign")
for _, v := range conf.SlicesMap[conf.IgnoreDirectLinkParams] {
query.Del(v)
}
link.URL, err = utils.InjectQuery(link.URL, query)
if err != nil {
common.ErrorResp(c, err, 500)
Expand Down Expand Up @@ -95,7 +97,9 @@ func Proxy(c *gin.Context) {
}
if link.URL != "" && setting.GetBool(conf.ForwardDirectLinkParams) {
query := c.Request.URL.Query()
query.Del("sign")
for _, v := range conf.SlicesMap[conf.IgnoreDirectLinkParams] {
query.Del(v)
}
link.URL, err = utils.InjectQuery(link.URL, query)
if err != nil {
common.ErrorResp(c, err, 500)
Expand Down

0 comments on commit c0f9c8e

Please sign in to comment.