From 092ed068331631fd800ec1d667ba2054e06ccca5 Mon Sep 17 00:00:00 2001 From: Kuingsmile Date: Wed, 30 Aug 2023 00:16:26 -0700 Subject: [PATCH] feat(uss): add `AntiTheftChainToken` field (#5115) * feat(uss): add AntiTheftChainToken; fix link func * feat(uss): optimize _upt generation --- drivers/uss/driver.go | 6 +++++- drivers/uss/meta.go | 9 +++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/uss/driver.go b/drivers/uss/driver.go index 2ca19c0a..447515d8 100644 --- a/drivers/uss/driver.go +++ b/drivers/uss/driver.go @@ -80,7 +80,11 @@ func (d *USS) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*m downExp := time.Hour * time.Duration(d.SignURLExpire) expireAt := time.Now().Add(downExp).Unix() upd := url.QueryEscape(path.Base(file.GetPath())) - signStr := strings.Join([]string{d.OperatorPassword, fmt.Sprint(expireAt), fmt.Sprintf("/%s", key)}, "&") + tokenOrPassword := d.AntiTheftChainToken + if tokenOrPassword == "" { + tokenOrPassword = d.OperatorPassword + } + signStr := strings.Join([]string{tokenOrPassword, fmt.Sprint(expireAt), fmt.Sprintf("/%s", key)}, "&") upt := utils.GetMD5EncodeStr(signStr)[12:20] + fmt.Sprint(expireAt) link := fmt.Sprintf("%s?_upd=%s&_upt=%s", u, upd, upt) return &model.Link{URL: link}, nil diff --git a/drivers/uss/meta.go b/drivers/uss/meta.go index 4ed7c96e..388df589 100644 --- a/drivers/uss/meta.go +++ b/drivers/uss/meta.go @@ -7,10 +7,11 @@ import ( type Addition struct { driver.RootPath - Bucket string `json:"bucket" required:"true"` - Endpoint string `json:"endpoint" required:"true"` - OperatorName string `json:"operator_name" required:"true"` - OperatorPassword string `json:"operator_password" required:"true"` + Bucket string `json:"bucket" required:"true"` + Endpoint string `json:"endpoint" required:"true"` + OperatorName string `json:"operator_name" required:"true"` + OperatorPassword string `json:"operator_password" required:"true"` + AntiTheftChainToken string `json:"anti_theft_chain_token" required:"false" default:""` //CustomHost string `json:"custom_host"` //Endpoint与CustomHost作用相同,去除 SignURLExpire int `json:"sign_url_expire" type:"number" default:"4"` }