🐛 fix s3 for #362
This commit is contained in:
parent
5c759217cf
commit
8245da485a
@ -12,7 +12,6 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -71,10 +70,16 @@ func (driver S3) Items() []base.Item {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "limit",
|
Name: "limit",
|
||||||
Label: "url expire time(hours)",
|
Label: "Sign url expire time(hours)",
|
||||||
Type: base.TypeNumber,
|
Type: base.TypeNumber,
|
||||||
Description: "default 4 hours",
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
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)))
|
disposition := fmt.Sprintf(`attachment;filename="%s"`, url.QueryEscape(utils.Base(path)))
|
||||||
input := &s3.GetObjectInput{
|
input := &s3.GetObjectInput{
|
||||||
Bucket: &account.Bucket,
|
Bucket: &account.Bucket,
|
||||||
Key: &path,
|
Key: &path,
|
||||||
ResponseContentDisposition: &disposition,
|
//ResponseContentDisposition: &disposition,
|
||||||
|
}
|
||||||
|
if account.CustomHost == "" {
|
||||||
|
input.ResponseContentDisposition = &disposition
|
||||||
}
|
}
|
||||||
req, _ := client.GetObjectRequest(input)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -73,9 +73,10 @@ func (driver S3) List(prefix string, account *model.Account) ([]model.File, erro
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, object := range listObjectsResult.CommonPrefixes {
|
for _, object := range listObjectsResult.CommonPrefixes {
|
||||||
|
name := utils.Base(strings.Trim(*object.Prefix, "/"))
|
||||||
file := model.File{
|
file := model.File{
|
||||||
//Id: *object.Key,
|
//Id: *object.Key,
|
||||||
Name: utils.Base(strings.Trim(*object.Prefix, "/")),
|
Name: name,
|
||||||
Driver: driver.Config().Name,
|
Driver: driver.Config().Name,
|
||||||
UpdatedAt: account.UpdatedAt,
|
UpdatedAt: account.UpdatedAt,
|
||||||
TimeStr: "-",
|
TimeStr: "-",
|
||||||
@ -84,9 +85,13 @@ func (driver S3) List(prefix string, account *model.Account) ([]model.File, erro
|
|||||||
files = append(files, file)
|
files = append(files, file)
|
||||||
}
|
}
|
||||||
for _, object := range listObjectsResult.Contents {
|
for _, object := range listObjectsResult.Contents {
|
||||||
|
name := utils.Base(*object.Key)
|
||||||
|
if name == account.Zone {
|
||||||
|
continue
|
||||||
|
}
|
||||||
file := model.File{
|
file := model.File{
|
||||||
//Id: *object.Key,
|
//Id: *object.Key,
|
||||||
Name: utils.Base(*object.Key),
|
Name: name,
|
||||||
Size: *object.Size,
|
Size: *object.Size,
|
||||||
Driver: driver.Config().Name,
|
Driver: driver.Config().Name,
|
||||||
UpdatedAt: object.LastModified,
|
UpdatedAt: object.LastModified,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user