🐛 fix s3 for #362

This commit is contained in:
微凉 2022-01-15 20:24:57 +08:00
parent 5c759217cf
commit 8245da485a
2 changed files with 28 additions and 9 deletions

View File

@ -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
}

View File

@ -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,