|
|
@ -17,7 +17,6 @@ import (
|
|
|
|
"net/http"
|
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
"net/url"
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// Handler 远程存储策略适配器
|
|
|
|
// Handler 远程存储策略适配器
|
|
|
@ -106,7 +105,7 @@ func (handler Handler) Thumb(ctx context.Context, path string) (*response.Conten
|
|
|
|
sourcePath := base64.RawURLEncoding.EncodeToString([]byte(path))
|
|
|
|
sourcePath := base64.RawURLEncoding.EncodeToString([]byte(path))
|
|
|
|
thumbURL := handler.getAPI("thumb") + "/" + sourcePath
|
|
|
|
thumbURL := handler.getAPI("thumb") + "/" + sourcePath
|
|
|
|
ttl := model.GetIntSetting("slave_api_timeout", 60)
|
|
|
|
ttl := model.GetIntSetting("slave_api_timeout", 60)
|
|
|
|
signedThumbURL, err := auth.SignURI(handler.AuthInstance, thumbURL, time.Now().Unix()+int64(ttl))
|
|
|
|
signedThumbURL, err := auth.SignURI(handler.AuthInstance, thumbURL, int64(ttl))
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -137,23 +136,19 @@ func (handler Handler) Source(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
var (
|
|
|
|
expires int64
|
|
|
|
|
|
|
|
signedURI *url.URL
|
|
|
|
signedURI *url.URL
|
|
|
|
controller = "/api/v3/slave/download"
|
|
|
|
controller = "/api/v3/slave/download"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
if !isDownload {
|
|
|
|
if !isDownload {
|
|
|
|
controller = "/api/v3/slave/source"
|
|
|
|
controller = "/api/v3/slave/source"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ttl > 0 {
|
|
|
|
|
|
|
|
expires = time.Now().Unix() + ttl
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 签名下载地址
|
|
|
|
// 签名下载地址
|
|
|
|
sourcePath := base64.RawURLEncoding.EncodeToString([]byte(file.SourceName))
|
|
|
|
sourcePath := base64.RawURLEncoding.EncodeToString([]byte(file.SourceName))
|
|
|
|
signedURI, err = auth.SignURI(
|
|
|
|
signedURI, err = auth.SignURI(
|
|
|
|
handler.AuthInstance,
|
|
|
|
handler.AuthInstance,
|
|
|
|
fmt.Sprintf("%s/%d/%s/%s", controller, speed, sourcePath, file.Name),
|
|
|
|
fmt.Sprintf("%s/%d/%s/%s", controller, speed, sourcePath, file.Name),
|
|
|
|
expires,
|
|
|
|
ttl,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
@ -191,7 +186,7 @@ func (handler Handler) Token(ctx context.Context, TTL int64, key string) (serial
|
|
|
|
uploadRequest.Header = map[string][]string{
|
|
|
|
uploadRequest.Header = map[string][]string{
|
|
|
|
"X-Policy": {policyEncoded},
|
|
|
|
"X-Policy": {policyEncoded},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auth.SignRequest(handler.AuthInstance, uploadRequest, time.Now().Unix()+TTL)
|
|
|
|
auth.SignRequest(handler.AuthInstance, uploadRequest, TTL)
|
|
|
|
|
|
|
|
|
|
|
|
if credential, ok := uploadRequest.Header["Authorization"]; ok && len(credential) == 1 {
|
|
|
|
if credential, ok := uploadRequest.Header["Authorization"]; ok && len(credential) == 1 {
|
|
|
|
return serializer.UploadCredential{
|
|
|
|
return serializer.UploadCredential{
|
|
|
|