diff --git a/drivers/s3/driver.go b/drivers/s3/driver.go index b3b1e231..7b005c06 100644 --- a/drivers/s3/driver.go +++ b/drivers/s3/driver.go @@ -12,7 +12,6 @@ import ( log "github.com/sirupsen/logrus" "net/url" "path/filepath" - "strings" "time" ) @@ -71,10 +70,16 @@ func (driver S3) Items() []base.Item { }, { Name: "limit", - Label: "url expire time(hours)", + Label: "Sign url expire time(hours)", Type: base.TypeNumber, Description: "default 4 hours", }, + { + Name: "zone", + Label: "placeholder filename", + Type: base.TypeNumber, + Description: "default empty string", + }, } } @@ -141,15 +146,24 @@ func (driver S3) Link(args base.Args, account *model.Account) (*base.Link, error if err != nil { return nil, err } - path := strings.TrimPrefix(args.Path, "/") + path := driver.GetKey(args.Path, account, false) disposition := fmt.Sprintf(`attachment;filename="%s"`, url.QueryEscape(utils.Base(path))) input := &s3.GetObjectInput{ - Bucket: &account.Bucket, - Key: &path, - ResponseContentDisposition: &disposition, + Bucket: &account.Bucket, + Key: &path, + //ResponseContentDisposition: &disposition, + } + if account.CustomHost == "" { + input.ResponseContentDisposition = &disposition } req, _ := client.GetObjectRequest(input) - link, err := req.Presign(time.Hour * time.Duration(account.Limit)) + var link string + if account.CustomHost != "" { + err = req.Build() + link = req.HTTPRequest.URL.String() + } else { + link, err = req.Presign(time.Hour * time.Duration(account.Limit)) + } if err != nil { return nil, err } diff --git a/drivers/s3/s3.go b/drivers/s3/s3.go index bfccb01f..05606d55 100644 --- a/drivers/s3/s3.go +++ b/drivers/s3/s3.go @@ -73,9 +73,10 @@ func (driver S3) List(prefix string, account *model.Account) ([]model.File, erro return nil, err } for _, object := range listObjectsResult.CommonPrefixes { + name := utils.Base(strings.Trim(*object.Prefix, "/")) file := model.File{ //Id: *object.Key, - Name: utils.Base(strings.Trim(*object.Prefix, "/")), + Name: name, Driver: driver.Config().Name, UpdatedAt: account.UpdatedAt, TimeStr: "-", @@ -84,9 +85,13 @@ func (driver S3) List(prefix string, account *model.Account) ([]model.File, erro files = append(files, file) } for _, object := range listObjectsResult.Contents { + name := utils.Base(*object.Key) + if name == account.Zone { + continue + } file := model.File{ //Id: *object.Key, - Name: utils.Base(*object.Key), + Name: name, Size: *object.Size, Driver: driver.Config().Name, UpdatedAt: object.LastModified,