Refactor Qiniu upload integration and remove legacy handlers

- Replaced common upload handler and service with Qiniu-specific implementations in main.go and route registration.
- Deleted outdated upload_handler.go and qiniu_service.go files to streamline the codebase.
- Updated route definitions to utilize the new Qiniu upload handler for improved file upload management.
This commit is contained in:
nepiedg
2025-12-31 03:22:16 +00:00
parent cd7ae5ac56
commit bba6dc6b4f
5 changed files with 12 additions and 12 deletions
+4 -4
View File
@@ -8,8 +8,8 @@ import (
"wx_service/config"
authhandler "wx_service/internal/common/auth/handler"
authservice "wx_service/internal/common/auth/service"
commonhandler "wx_service/internal/common/handler"
commonservice "wx_service/internal/common/service"
qiniuhandler "wx_service/internal/common/qiniu/handler"
qiniuservice "wx_service/internal/common/qiniu/service"
"wx_service/internal/database"
"wx_service/internal/model"
rmhandler "wx_service/internal/remove_watermark/handler"
@@ -57,8 +57,8 @@ func main() {
smokeLogService := smokeservice.NewSmokeLogService(database.DB)
smokeHandler := smokehandler.NewSmokeHandler(smokeLogService)
qiniuService := commonservice.NewQiniuService(config.AppConfig.Qiniu)
uploadHandler := commonhandler.NewUploadHandler(qiniuService)
qiniuService := qiniuservice.NewQiniuService(config.AppConfig.Qiniu)
uploadHandler := qiniuhandler.NewUploadHandler(qiniuService)
// 6) 注册路由:把 URL 映射到 handler
routes.Register(router, database.DB, authHandler, videoHandler, smokeHandler, uploadHandler)
@@ -6,16 +6,16 @@ import (
"github.com/gin-gonic/gin"
"wx_service/internal/common/service"
qiniuservice "wx_service/internal/common/qiniu/service"
"wx_service/internal/middleware"
"wx_service/internal/model"
)
type UploadHandler struct {
qiniuService *service.QiniuService
qiniuService *qiniuservice.QiniuService
}
func NewUploadHandler(qiniuService *service.QiniuService) *UploadHandler {
func NewUploadHandler(qiniuService *qiniuservice.QiniuService) *UploadHandler {
return &UploadHandler{qiniuService: qiniuService}
}
@@ -38,7 +38,7 @@ func (h *UploadHandler) QiniuToken(c *gin.Context) {
token, err := h.qiniuService.CreateUploadToken(user.MiniProgramID, user.ID, req.Filename)
if err != nil {
if errors.Is(err, service.ErrQiniuNotConfigured) {
if errors.Is(err, qiniuservice.ErrQiniuNotConfigured) {
c.JSON(http.StatusServiceUnavailable, model.Error(http.StatusServiceUnavailable, "未配置七牛上传服务,请联系管理员"))
return
}
+2 -2
View File
@@ -3,10 +3,10 @@ package routes
import (
"github.com/gin-gonic/gin"
commonhandler "wx_service/internal/common/handler"
qiniuhandler "wx_service/internal/common/qiniu/handler"
)
func registerCommonRoutes(protected *gin.RouterGroup, uploadHandler *commonhandler.UploadHandler) {
func registerCommonRoutes(protected *gin.RouterGroup, uploadHandler *qiniuhandler.UploadHandler) {
// 公共接口(所有小程序共用)
common := protected.Group("/common")
{
+2 -2
View File
@@ -7,7 +7,7 @@ import (
"gorm.io/gorm"
authhandler "wx_service/internal/common/auth/handler"
commonhandler "wx_service/internal/common/handler"
qiniuhandler "wx_service/internal/common/qiniu/handler"
"wx_service/internal/middleware"
rmhandler "wx_service/internal/remove_watermark/handler"
smokehandler "wx_service/internal/smoke/handler"
@@ -19,7 +19,7 @@ func Register(
authHandler *authhandler.AuthHandler,
videoHandler *rmhandler.VideoHandler,
smokeHandler *smokehandler.SmokeHandler,
uploadHandler *commonhandler.UploadHandler,
uploadHandler *qiniuhandler.UploadHandler,
) {
// Register 用来集中注册所有 HTTP 路由,便于工程结构更清晰:
// - main 只负责初始化(配置/DB/依赖注入)