优化结构
This commit is contained in:
@@ -4,15 +4,16 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"kra/internal/biz/system"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
cos "github.com/tencentyun/cos-go-sdk-v5"
|
||||
"kra/internal/biz"
|
||||
"kra/internal/conf"
|
||||
|
||||
cos "github.com/tencentyun/cos-go-sdk-v5"
|
||||
)
|
||||
|
||||
type tencentStorage struct {
|
||||
@@ -20,7 +21,7 @@ type tencentStorage struct {
|
||||
baseURL, prefix string
|
||||
}
|
||||
|
||||
func newTencentStorage(config *conf.AdminBackend_ObjectStore) (biz.FileStorage, error) {
|
||||
func newTencentStorage(config *conf.AdminBackend_ObjectStore) (system.FileStorage, error) {
|
||||
if config == nil || config.Bucket == "" || config.Region == "" || config.AccessKey == "" || config.SecretKey == "" {
|
||||
return nil, fmt.Errorf("tencent-cos storage configuration is incomplete")
|
||||
}
|
||||
@@ -50,12 +51,12 @@ func (s *tencentStorage) key(name string) string {
|
||||
func (s *tencentStorage) unkey(key string) string {
|
||||
return strings.TrimPrefix(strings.TrimPrefix(key, s.prefix), "/")
|
||||
}
|
||||
func (s *tencentStorage) file(key string, size int64) *biz.StoredFile {
|
||||
func (s *tencentStorage) file(key string, size int64) *system.StoredFile {
|
||||
name := s.unkey(key)
|
||||
fileURL := s.baseURL + "/" + key
|
||||
return &biz.StoredFile{Name: path.Base(name), Path: name, URL: fileURL, Size: size}
|
||||
return &system.StoredFile{Name: path.Base(name), Path: name, URL: fileURL, Size: size}
|
||||
}
|
||||
func (s *tencentStorage) Put(ctx context.Context, name string, reader io.Reader) (*biz.StoredFile, error) {
|
||||
func (s *tencentStorage) Put(ctx context.Context, name string, reader io.Reader) (*system.StoredFile, error) {
|
||||
key := s.key(name)
|
||||
if _, err := s.client.Object.Put(ctx, key, reader, nil); err != nil {
|
||||
return nil, err
|
||||
@@ -77,7 +78,7 @@ func (s *tencentStorage) Delete(ctx context.Context, name string) error {
|
||||
_, err := s.client.Object.Delete(ctx, s.key(name))
|
||||
return err
|
||||
}
|
||||
func (s *tencentStorage) Compose(ctx context.Context, names []string, destination string) (*biz.StoredFile, string, error) {
|
||||
func (s *tencentStorage) Compose(ctx context.Context, names []string, destination string) (*system.StoredFile, string, error) {
|
||||
return composeFiles(ctx, s, names, destination)
|
||||
}
|
||||
func (s *tencentStorage) DeletePrefix(ctx context.Context, prefix string) error {
|
||||
@@ -98,7 +99,7 @@ func (s *tencentStorage) DeletePrefix(ctx context.Context, prefix string) error
|
||||
cursor = next
|
||||
}
|
||||
}
|
||||
func (s *tencentStorage) List(ctx context.Context, prefix, cursor string, limit int) ([]*biz.StoredFile, string, bool, error) {
|
||||
func (s *tencentStorage) List(ctx context.Context, prefix, cursor string, limit int) ([]*system.StoredFile, string, bool, error) {
|
||||
if limit <= 0 {
|
||||
limit = 100
|
||||
}
|
||||
@@ -106,7 +107,7 @@ func (s *tencentStorage) List(ctx context.Context, prefix, cursor string, limit
|
||||
if err != nil {
|
||||
return nil, "", false, err
|
||||
}
|
||||
items := make([]*biz.StoredFile, 0, len(result.Contents))
|
||||
items := make([]*system.StoredFile, 0, len(result.Contents))
|
||||
for _, object := range result.Contents {
|
||||
item := s.file(object.Key, object.Size)
|
||||
for _, layout := range []string{time.RFC3339, "2006-01-02T15:04:05.000Z"} {
|
||||
|
||||
Reference in New Issue
Block a user