mirror of
https://github.com/eiblog/eiblog.git
synced 2026-03-01 00:34:58 +08:00
update vendor
This commit is contained in:
+10
-16
@@ -8,20 +8,11 @@ import (
|
||||
)
|
||||
|
||||
// CreateTimestampAntileechURL 构建带时间戳防盗链的链接
|
||||
// host需要加上 "http://" 或 "https://"
|
||||
// encryptKey 七牛防盗链key
|
||||
func CreateTimestampAntileechURL(host, fileName string, queryStr url.Values, encryptKey string, durationInSeconds int64) (antileechURL string, err error) {
|
||||
func CreateTimestampAntileechURL(urlStr string, encryptKey string, durationInSeconds int64) (antileechURL string, err error) {
|
||||
|
||||
var urlStr string
|
||||
if queryStr != nil {
|
||||
urlStr = fmt.Sprintf("%s/%s?%s", host, fileName, queryStr.Encode())
|
||||
} else {
|
||||
urlStr = fmt.Sprintf("%s/%s", host, fileName)
|
||||
}
|
||||
|
||||
u, parseErr := url.Parse(urlStr)
|
||||
if parseErr != nil {
|
||||
err = parseErr
|
||||
u, err := url.Parse(urlStr)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -29,13 +20,16 @@ func CreateTimestampAntileechURL(host, fileName string, queryStr url.Values, enc
|
||||
toSignStr := fmt.Sprintf("%s%s%x", encryptKey, u.EscapedPath(), expireTime)
|
||||
signedStr := fmt.Sprintf("%x", md5.Sum([]byte(toSignStr)))
|
||||
|
||||
q := u.Query()
|
||||
q := url.Values{}
|
||||
q.Add("sign", signedStr)
|
||||
q.Add("t", fmt.Sprintf("%x", expireTime))
|
||||
u.RawQuery = q.Encode()
|
||||
|
||||
antileechURL = fmt.Sprintf("%s://%s%s?%s", u.Scheme, u.Host, u.EscapedPath(), u.Query().Encode())
|
||||
if u.RawQuery == "" {
|
||||
antileechURL = u.String() + "?" + q.Encode()
|
||||
} else {
|
||||
|
||||
antileechURL = u.String() + "&" + q.Encode()
|
||||
}
|
||||
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user