优化结构

This commit is contained in:
Yvan
2026-08-22 12:13:16 +08:00
parent d987244d0e
commit b27a66e9d3
200 changed files with 1794 additions and 1715 deletions
+10 -9
View File
@@ -4,16 +4,17 @@ import (
"context"
"fmt"
"io"
"kra/internal/biz/system"
"net/http"
"os"
"path"
"strings"
"time"
"kra/internal/conf"
"github.com/qiniu/go-sdk/v7/auth/qbox"
qstorage "github.com/qiniu/go-sdk/v7/storage"
"kra/internal/biz"
"kra/internal/conf"
)
type qiniuStorage struct {
@@ -24,7 +25,7 @@ type qiniuStorage struct {
token string
}
func newQiniuStorage(config *conf.AdminBackend_Qiniu) (biz.FileStorage, error) {
func newQiniuStorage(config *conf.AdminBackend_Qiniu) (system.FileStorage, error) {
if config == nil || config.Bucket == "" || config.AccessKey == "" || config.SecretKey == "" {
return nil, fmt.Errorf("qiniu storage configuration is incomplete")
}
@@ -46,10 +47,10 @@ func newQiniuStorage(config *conf.AdminBackend_Qiniu) (biz.FileStorage, error) {
token := policy.UploadToken(mac)
return &qiniuStorage{config: config, upload: qstorage.NewFormUploader(&cfg), manager: qstorage.NewBucketManager(mac, &cfg), mac: mac, token: token}, nil
}
func (s *qiniuStorage) file(key string, size int64) *biz.StoredFile {
return &biz.StoredFile{Name: path.Base(key), Path: key, URL: strings.TrimSuffix(s.config.BaseUrl, "/") + "/" + key, Size: size}
func (s *qiniuStorage) file(key string, size int64) *system.StoredFile {
return &system.StoredFile{Name: path.Base(key), Path: key, URL: strings.TrimSuffix(s.config.BaseUrl, "/") + "/" + key, Size: size}
}
func (s *qiniuStorage) Put(ctx context.Context, name string, reader io.Reader) (*biz.StoredFile, error) {
func (s *qiniuStorage) Put(ctx context.Context, name string, reader io.Reader) (*system.StoredFile, error) {
temporary, err := os.CreateTemp("", "kra-qiniu-upload-*")
if err != nil {
return nil, err
@@ -91,7 +92,7 @@ func (s *qiniuStorage) Open(ctx context.Context, name string) (io.ReadCloser, er
func (s *qiniuStorage) Delete(ctx context.Context, name string) error {
return s.manager.Delete(s.config.Bucket, strings.TrimPrefix(name, "/"))
}
func (s *qiniuStorage) Compose(ctx context.Context, names []string, destination string) (*biz.StoredFile, string, error) {
func (s *qiniuStorage) Compose(ctx context.Context, names []string, destination string) (*system.StoredFile, string, error) {
return composeFiles(ctx, s, names, destination)
}
func (s *qiniuStorage) DeletePrefix(ctx context.Context, prefix string) error {
@@ -110,7 +111,7 @@ func (s *qiniuStorage) DeletePrefix(ctx context.Context, prefix string) error {
}
}
}
func (s *qiniuStorage) List(ctx context.Context, prefix, cursor string, limit int) ([]*biz.StoredFile, string, bool, error) {
func (s *qiniuStorage) List(ctx context.Context, prefix, cursor string, limit int) ([]*system.StoredFile, string, bool, error) {
if limit <= 0 {
limit = 100
}
@@ -118,7 +119,7 @@ func (s *qiniuStorage) List(ctx context.Context, prefix, cursor string, limit in
if err != nil {
return nil, "", false, err
}
out := make([]*biz.StoredFile, 0, len(entries))
out := make([]*system.StoredFile, 0, len(entries))
for _, entry := range entries {
item := s.file(entry.Key, entry.Fsize)
item.LastModified = time.Unix(0, entry.PutTime*100)