feat(storage): 更新存储结构以使用新的存储提供者并优化文件上传和下载逻辑

This commit is contained in:
2025-12-30 18:07:58 +08:00
parent d87eac7d94
commit 3952d80d30
2 changed files with 32 additions and 15 deletions

View File

@@ -5,13 +5,15 @@ import (
"os"
"path/filepath"
"quyun/v2/app/services"
"quyun/v2/providers/storage"
"github.com/gofiber/fiber/v3"
)
// @provider
type Storage struct{}
type Storage struct {
storage *storage.Storage
}
// Upload file
//
@@ -28,12 +30,12 @@ type Storage struct{}
// @Bind expires query
// @Bind sign query
func (s *Storage) Upload(ctx fiber.Ctx, key, expires, sign string) (string, error) {
if err := services.Storage.Verify("PUT", key, expires, sign); err != nil {
if err := s.storage.Verify("PUT", key, expires, sign); err != nil {
return "", fiber.NewError(fiber.StatusForbidden, err.Error())
}
// Save file
localPath := services.Storage.Config.LocalPath
localPath := s.storage.Config.LocalPath
if localPath == "" {
localPath = "./storage"
}
@@ -70,11 +72,11 @@ func (s *Storage) Upload(ctx fiber.Ctx, key, expires, sign string) (string, erro
// @Bind expires query
// @Bind sign query
func (s *Storage) Download(ctx fiber.Ctx, key, expires, sign string) error {
if err := services.Storage.Verify("GET", key, expires, sign); err != nil {
if err := s.storage.Verify("GET", key, expires, sign); err != nil {
return fiber.NewError(fiber.StatusForbidden, err.Error())
}
localPath := services.Storage.Config.LocalPath
localPath := s.storage.Config.LocalPath
if localPath == "" {
localPath = "./storage"
}