fix(ilanzou): add header X-Forwarded-For
to solve IP ban (#7977)
* fix: warning * feat: ip header * fix: ip header for fs link
This commit is contained in:
parent
ec3fc945a3
commit
f25be154c6
@ -6,7 +6,6 @@ import (
|
|||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/alist-org/alist/v3/internal/stream"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -14,6 +13,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/alist-org/alist/v3/internal/stream"
|
||||||
|
|
||||||
"github.com/alist-org/alist/v3/drivers/base"
|
"github.com/alist-org/alist/v3/drivers/base"
|
||||||
"github.com/alist-org/alist/v3/internal/driver"
|
"github.com/alist-org/alist/v3/internal/driver"
|
||||||
"github.com/alist-org/alist/v3/internal/errs"
|
"github.com/alist-org/alist/v3/internal/errs"
|
||||||
@ -121,7 +122,7 @@ func (d *ILanZou) Link(ctx context.Context, file model.Obj, args model.LinkArgs)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
ts, ts_str, err := getTimestamp(d.conf.secret)
|
ts, ts_str, _ := getTimestamp(d.conf.secret)
|
||||||
|
|
||||||
params := []string{
|
params := []string{
|
||||||
"uuid=" + url.QueryEscape(d.UUID),
|
"uuid=" + url.QueryEscape(d.UUID),
|
||||||
@ -150,11 +151,17 @@ func (d *ILanZou) Link(ctx context.Context, file model.Obj, args model.LinkArgs)
|
|||||||
u.RawQuery = strings.Join(params, "&")
|
u.RawQuery = strings.Join(params, "&")
|
||||||
realURL := u.String()
|
realURL := u.String()
|
||||||
// get the url after redirect
|
// get the url after redirect
|
||||||
res, err := base.NoRedirectClient.R().SetHeaders(map[string]string{
|
req := base.NoRedirectClient.R()
|
||||||
//"Origin": d.conf.site,
|
|
||||||
|
req.SetHeaders(map[string]string{
|
||||||
"Referer": d.conf.site + "/",
|
"Referer": d.conf.site + "/",
|
||||||
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0",
|
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0",
|
||||||
}).Get(realURL)
|
})
|
||||||
|
if d.Addition.Ip != "" {
|
||||||
|
req.SetHeader("X-Forwarded-For", d.Addition.Ip)
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := req.Get(realURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ type Addition struct {
|
|||||||
driver.RootID
|
driver.RootID
|
||||||
Username string `json:"username" type:"string" required:"true"`
|
Username string `json:"username" type:"string" required:"true"`
|
||||||
Password string `json:"password" type:"string" required:"true"`
|
Password string `json:"password" type:"string" required:"true"`
|
||||||
|
Ip string `json:"ip" type:"string"`
|
||||||
|
|
||||||
Token string
|
Token string
|
||||||
UUID string
|
UUID string
|
||||||
|
@ -76,6 +76,10 @@ func (d *ILanZou) request(pathname, method string, callback base.ReqCallback, pr
|
|||||||
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6,mt;q=0.5",
|
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6,mt;q=0.5",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if d.Addition.Ip != "" {
|
||||||
|
req.SetHeader("X-Forwarded-For", d.Addition.Ip)
|
||||||
|
}
|
||||||
|
|
||||||
if callback != nil {
|
if callback != nil {
|
||||||
callback(req)
|
callback(req)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user