feat: 完成 #40 营销图后台七牛直传与页面上传能力
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"wx_service/config"
|
||||
qiniuservice "wx_service/internal/common/qiniu/service"
|
||||
"wx_service/internal/marketing/service"
|
||||
"wx_service/internal/middleware"
|
||||
"wx_service/internal/model"
|
||||
@@ -89,3 +92,25 @@ func (h *DownloadHandler) AdminStats(c *gin.Context) {
|
||||
}
|
||||
c.JSON(http.StatusOK, model.Success(stats))
|
||||
}
|
||||
|
||||
type adminQiniuTokenRequest struct {
|
||||
Filename string `json:"filename"`
|
||||
}
|
||||
|
||||
func (h *DownloadHandler) AdminQiniuToken(c *gin.Context) {
|
||||
var req adminQiniuTokenRequest
|
||||
_ = c.ShouldBindJSON(&req)
|
||||
|
||||
qiniuSvc := qiniuservice.NewQiniuService(config.AppConfig.Qiniu)
|
||||
token, err := qiniuSvc.CreateUploadToken(0, 0, req.Filename)
|
||||
if err != nil {
|
||||
if errors.Is(err, qiniuservice.ErrQiniuNotConfigured) {
|
||||
c.JSON(http.StatusServiceUnavailable, model.Error(http.StatusServiceUnavailable, "未配置七牛上传服务"))
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusInternalServerError, model.Error(http.StatusInternalServerError, "获取上传凭证失败"))
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, model.Success(token))
|
||||
}
|
||||
|
||||
@@ -46,5 +46,6 @@ func registerMarketingRoutes(
|
||||
admin.DELETE("/templates/:id", templateHandler.AdminDelete)
|
||||
|
||||
admin.GET("/stats", downloadHandler.AdminStats)
|
||||
admin.POST("/upload/qiniu/token", downloadHandler.AdminQiniuToken)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user