forked from TrueCloudLab/frostfs-s3-gw
Migrate to SDK 0.3.0 and fixes
- fix displaying list objects - simplify `ListObjects` - simplify `GetObjectHandler` - simplify `HeadObjectHandler` - add method for `GetBucketVersioningHandler` - add method for `ListMultipartUploadsHandler` - improvements for `HeadObjectHandler`, to display folders meta - update dependencies - github.com/aws/aws-sdk-go v1.36.26 - github.com/google/uuid v1.1.4 - github.com/gorilla/mux v1.8.0 - github.com/nspcc-dev/cdn-sdk v0.3.0 - github.com/nspcc-dev/neofs-api-go v1.22.0 - github.com/prometheus/client_golang v1.9.0 - github.com/stretchr/testify v1.7.0 - google.golang.org/grpc v1.35.0 Signed-off-by: Evgeniy Kulikov <kim@nspcc.ru>
This commit is contained in:
parent
ef7b480493
commit
2a93a216f8
16 changed files with 592 additions and 178 deletions
|
@ -13,7 +13,8 @@ import (
|
|||
|
||||
type (
|
||||
ObjectInfo struct {
|
||||
id *object.ID
|
||||
id *object.ID
|
||||
isDir bool
|
||||
|
||||
Bucket string
|
||||
Name string
|
||||
|
@ -49,7 +50,10 @@ type (
|
|||
}
|
||||
)
|
||||
|
||||
const pathSeparator = string(os.PathSeparator)
|
||||
const (
|
||||
rootSeparator = "root://"
|
||||
PathSeparator = string(os.PathSeparator)
|
||||
)
|
||||
|
||||
func userHeaders(attrs []*object.Attribute) map[string]string {
|
||||
result := make(map[string]string, len(attrs))
|
||||
|
@ -61,12 +65,24 @@ func userHeaders(attrs []*object.Attribute) map[string]string {
|
|||
return result
|
||||
}
|
||||
|
||||
func objectInfoFromMeta(bkt *BucketInfo, meta *object.Object) *ObjectInfo {
|
||||
func objectInfoFromMeta(bkt *BucketInfo, meta *object.Object, prefix string) *ObjectInfo {
|
||||
var (
|
||||
creation time.Time
|
||||
filename = meta.ID().String()
|
||||
isDir bool
|
||||
size int64
|
||||
mimeType string
|
||||
creation time.Time
|
||||
filename = meta.ID().String()
|
||||
name, dirname = nameFromObject(meta)
|
||||
)
|
||||
|
||||
if !strings.HasPrefix(dirname, prefix) && prefix != rootSeparator {
|
||||
return nil
|
||||
}
|
||||
|
||||
if ln := len(prefix); ln > 0 && prefix[ln-1:] != PathSeparator {
|
||||
prefix += PathSeparator
|
||||
}
|
||||
|
||||
userHeaders := userHeaders(meta.Attributes())
|
||||
if val, ok := userHeaders[object.AttributeFileName]; ok {
|
||||
filename = val
|
||||
|
@ -80,17 +96,33 @@ func objectInfoFromMeta(bkt *BucketInfo, meta *object.Object) *ObjectInfo {
|
|||
delete(userHeaders, object.AttributeTimestamp)
|
||||
}
|
||||
|
||||
mimeType := http.DetectContentType(meta.Payload())
|
||||
tail := strings.TrimPrefix(dirname, prefix)
|
||||
index := strings.Index(tail, PathSeparator)
|
||||
|
||||
if prefix == rootSeparator {
|
||||
size = int64(meta.PayloadSize())
|
||||
mimeType = http.DetectContentType(meta.Payload())
|
||||
} else if index < 0 {
|
||||
filename = name
|
||||
size = int64(meta.PayloadSize())
|
||||
mimeType = http.DetectContentType(meta.Payload())
|
||||
} else {
|
||||
isDir = true
|
||||
filename = tail[:index] + PathSeparator
|
||||
userHeaders = nil
|
||||
}
|
||||
|
||||
return &ObjectInfo{
|
||||
id: meta.ID(),
|
||||
id: meta.ID(),
|
||||
isDir: isDir,
|
||||
|
||||
Bucket: bkt.Name,
|
||||
Name: filename,
|
||||
Created: creation,
|
||||
ContentType: mimeType,
|
||||
Headers: userHeaders,
|
||||
Size: int64(meta.PayloadSize()),
|
||||
Owner: meta.OwnerID(),
|
||||
Size: size,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,9 +137,14 @@ func nameFromObject(o *object.Object) (string, string) {
|
|||
}
|
||||
}
|
||||
|
||||
ind := strings.LastIndex(name, pathSeparator)
|
||||
return NameFromString(name)
|
||||
}
|
||||
|
||||
func NameFromString(name string) (string, string) {
|
||||
ind := strings.LastIndex(name, PathSeparator)
|
||||
return name[ind+1:], name[:ind+1]
|
||||
}
|
||||
|
||||
func (o *ObjectInfo) ID() *object.ID { return o.id }
|
||||
|
||||
func (o *ObjectInfo) IsDir() bool { return o.isDir }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue