use s3Service interface

This commit is contained in:
2021-11-23 20:12:24 +01:00
parent 60817c2249
commit 8d85d645d6
9 changed files with 162 additions and 257 deletions

View File

@@ -6,37 +6,15 @@ import (
"strings"
"time"
"git.kapelle.org/niklas/s3browser/internal/s3"
types "git.kapelle.org/niklas/s3browser/internal/types"
"github.com/golang-jwt/jwt"
"github.com/minio/minio-go/v7"
log "github.com/sirupsen/logrus"
)
func GetFilenameFromKey(id string) string {
return filepath.Base(id)
}
func DeleteMultiple(ctx context.Context, s3Client minio.Client, bucket string, keys []string) error {
objectsCh := make(chan minio.ObjectInfo, 1)
go func() {
defer close(objectsCh)
for _, id := range keys {
objectsCh <- minio.ObjectInfo{
Key: id,
}
}
}()
log.Debug("S3 'RemoveObject': ", keys)
for err := range s3Client.RemoveObjects(ctx, bucket, objectsCh, minio.RemoveObjectsOptions{}) {
log.Error("Failed to delete object ", err.ObjectName, " because: ", err.Err.Error())
// TODO: error handel
}
return nil
}
func GetParentDir(id types.ID) types.ID {
dirs := strings.Split(id.Key, "/")
@@ -57,17 +35,10 @@ func GetParentDir(id types.ID) types.ID {
return parent
}
func ObjInfoToFile(objInfo minio.ObjectInfo, bucket string) *types.File {
objID := types.ID{
Bucket: bucket,
Key: objInfo.Key,
}
objID.Normalize()
func ObjInfoToFile(objInfo s3.Object, bucket string) *types.File {
return &types.File{
ID: objID,
Name: GetFilenameFromKey(objID.Key),
ID: objInfo.ID,
Name: objInfo.ID.Name(),
Size: objInfo.Size,
ContentType: objInfo.ContentType,
ETag: objInfo.ETag,