mirror of
https://github.com/AlistGo/alist.git
synced 2025-12-19 02:50:06 +08:00
feat(client): Implement configurable user agent
* Introduce a configurable `UserAgent` field in the client's settings. * Add a `userAgent()` method to retrieve the user agent, prioritizing the custom setting or using a predefined default. * Apply the determined user agent to all outbound HTTP requests made by the `BitQiu` client.
This commit is contained in:
parent
7a4d4568f9
commit
30a3a09f3b
@ -8,6 +8,7 @@ import (
|
||||
"net/http/cookiejar"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/alist-org/alist/v3/drivers/base"
|
||||
@ -48,6 +49,8 @@ const (
|
||||
chunkSize = int64(1 << 20)
|
||||
)
|
||||
|
||||
const defaultUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36"
|
||||
|
||||
type BitQiu struct {
|
||||
model.Storage
|
||||
Addition
|
||||
@ -79,6 +82,7 @@ func (d *BitQiu) Init(ctx context.Context) error {
|
||||
d.client.SetBaseURL(baseURL)
|
||||
d.client.SetCookieJar(jar)
|
||||
}
|
||||
d.client.SetHeader("user-agent", d.userAgent())
|
||||
|
||||
return d.login(ctx)
|
||||
}
|
||||
@ -504,6 +508,7 @@ func (d *BitQiu) uploadFileInChunks(ctx context.Context, tmpFile model.File, siz
|
||||
"hash": md5sum,
|
||||
"len": strconv.FormatInt(chunkLen, 10),
|
||||
"offset": strconv.FormatInt(offset, 10),
|
||||
"user-agent": d.userAgent(),
|
||||
}
|
||||
|
||||
var chunkResp ChunkUploadResponse
|
||||
@ -715,10 +720,18 @@ func (d *BitQiu) commonHeaders() map[string]string {
|
||||
"x-requested-with": "XMLHttpRequest",
|
||||
"referer": baseURL + "/",
|
||||
"origin": baseURL,
|
||||
"user-agent": d.userAgent(),
|
||||
}
|
||||
return headers
|
||||
}
|
||||
|
||||
func (d *BitQiu) userAgent() string {
|
||||
if ua := strings.TrimSpace(d.Addition.UserAgent); ua != "" {
|
||||
return ua
|
||||
}
|
||||
return defaultUserAgent
|
||||
}
|
||||
|
||||
func (d *BitQiu) resolveParentID(dir model.Obj) string {
|
||||
if dir != nil && dir.GetID() != "" {
|
||||
return dir.GetID()
|
||||
|
||||
@ -13,6 +13,7 @@ type Addition struct {
|
||||
OrderType string `json:"order_type" type:"select" options:"updateTime,createTime,name,size" default:"updateTime"`
|
||||
OrderDesc bool `json:"order_desc"`
|
||||
PageSize string `json:"page_size" default:"24" help:"Number of entries to request per page."`
|
||||
UserAgent string `json:"user_agent" default:"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36"`
|
||||
}
|
||||
|
||||
var config = driver.Config{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user