chore: stabilize lint and verify builds

This commit is contained in:
2026-02-06 11:51:32 +08:00
parent edede17880
commit 1782f64417
114 changed files with 3032 additions and 1345 deletions

View File

@@ -5,6 +5,7 @@ import (
"os"
"path/filepath"
"quyun/v2/app/errorx"
"quyun/v2/providers/storage"
"github.com/gofiber/fiber/v3"
@@ -27,30 +28,30 @@ type Storage struct {
// @Success 200 {string} string "success"
// @Bind expires query
// @Bind sign query
func (s *Storage) Upload(ctx fiber.Ctx, expires, sign string) (string, error) {
func (storageHandler *Storage) Upload(ctx fiber.Ctx, expires, sign string) (string, error) {
key := ctx.Params("*")
if err := s.storage.Verify("PUT", key, expires, sign); err != nil {
if err := storageHandler.storage.Verify("PUT", key, expires, sign); err != nil {
return "", fiber.NewError(fiber.StatusForbidden, err.Error())
}
// Save file
localPath := s.storage.Config.LocalPath
localPath := storageHandler.storage.Config.LocalPath
if localPath == "" {
localPath = "./storage"
}
fullPath := filepath.Join(localPath, key)
if err := os.MkdirAll(filepath.Dir(fullPath), 0o755); err != nil {
return "", err
return "", errorx.ErrFileSystemError.WithCause(err)
}
f, err := os.Create(fullPath)
file, err := os.Create(fullPath)
if err != nil {
return "", err
return "", errorx.ErrFileSystemError.WithCause(err)
}
defer f.Close()
defer file.Close()
if _, err := io.Copy(f, ctx.Request().BodyStream()); err != nil {
return "", err
if _, err := io.Copy(file, ctx.Request().BodyStream()); err != nil {
return "", errorx.ErrFileSystemError.WithCause(err)
}
return "success", nil
@@ -68,17 +69,21 @@ func (s *Storage) Upload(ctx fiber.Ctx, expires, sign string) (string, error) {
// @Success 200 {file} file
// @Bind expires query
// @Bind sign query
func (s *Storage) Download(ctx fiber.Ctx, expires, sign string) error {
func (storageHandler *Storage) Download(ctx fiber.Ctx, expires, sign string) error {
key := ctx.Params("*")
if err := s.storage.Verify("GET", key, expires, sign); err != nil {
if err := storageHandler.storage.Verify("GET", key, expires, sign); err != nil {
return fiber.NewError(fiber.StatusForbidden, err.Error())
}
localPath := s.storage.Config.LocalPath
localPath := storageHandler.storage.Config.LocalPath
if localPath == "" {
localPath = "./storage"
}
fullPath := filepath.Join(localPath, key)
return ctx.SendFile(fullPath)
if err := ctx.SendFile(fullPath); err != nil {
return errorx.ErrFileSystemError.WithCause(err)
}
return nil
}