feat: 完成 #40 营销图后台七牛直传与页面上传能力

This commit is contained in:
root
2026-03-09 19:17:25 +08:00
parent 88d02ed6db
commit 9daf5e98ff
3 changed files with 112 additions and 6 deletions
@@ -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))
}