Skip to content

Commit

Permalink
fix: update the expire for the sign
Browse files Browse the repository at this point in the history
  • Loading branch information
saltbo committed Jul 8, 2021
1 parent 5c7ba93 commit 79762c1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
6 changes: 6 additions & 0 deletions internal/pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ import (
"net/http"
"net/url"
"strings"
"time"
)

var urlEncode = url.QueryEscape

var corsAllowHeaders = []string{"content-type", "content-disposition", "x-amz-acl"}

const (
defaultUploadExp = time.Hour
defaultDownloadExp = time.Hour * 24
)

// Object is the basic operation unit
type Object struct {
Key string // remote file path
Expand Down
5 changes: 2 additions & 3 deletions internal/pkg/provider/provider_s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"net/http"
"net/url"
"strings"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
Expand Down Expand Up @@ -139,7 +138,7 @@ func (p *S3Provider) SignedPutURL(key, filetype string, filesize int64, public b
ContentType: aws.String(filetype),
}
req, _ := p.client.PutObjectRequest(input)
us, headers, err := req.PresignRequest(time.Minute * 5)
us, headers, err := req.PresignRequest(defaultUploadExp)
return us, headerRebuild(headers), err
}

Expand All @@ -151,7 +150,7 @@ func (p *S3Provider) SignedGetURL(key, filename string) (string, error) {
ResponseContentDisposition: aws.String(disposition),
}
req, _ := p.client.GetObjectRequest(input)
return req.Presign(time.Minute)
return req.Presign(defaultDownloadExp)
}

func (p *S3Provider) PublicURL(key string) string {
Expand Down
7 changes: 5 additions & 2 deletions internal/pkg/provider/provider_uss.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ func (p *USSProvider) Move(object, newObject string) error {
}

func (p *USSProvider) SignedPutURL(key, filetype string, filesize int64, public bool) (url string, headers http.Header, err error) {
//expireAt := time.Now().Add(time.Minute * 15).Unix()
// todo 新版签名存在跨域问题暂时不能用,客服反馈正在调试,后续通知。
//expireAt := time.Now().Add(defaultUploadExp).Unix()
//headers.Set("X-Upyun-Expire", fmt.Sprint(expireAt))
//headers.Set("X-Upyun-Uri-Prefix", uriPrefix)

//老版签名不能设置有效期,固定为30min
headers = make(http.Header)
uri := fmt.Sprintf("/%s/%s", p.client.Bucket, key)
date := time.Now().UTC().Format(http.TimeFormat)
Expand All @@ -56,7 +59,7 @@ func (p *USSProvider) SignedPutURL(key, filetype string, filesize int64, public
}

func (p *USSProvider) SignedGetURL(key, filename string) (url string, err error) {
expireAt := time.Now().Add(time.Minute * 15).Unix()
expireAt := time.Now().Add(defaultDownloadExp).Unix()
upt := p.buildUpt(expireAt, fmt.Sprintf("/%s", key))
return fmt.Sprintf("%s?_upt=%s", p.PublicURL(key), upt), err
}
Expand Down

0 comments on commit 79762c1

Please sign in to comment.