From e668b9232d590b500cc0b1cfe002a8380eb9c833 Mon Sep 17 00:00:00 2001 From: wucongxing8150 <815046773@qq.com> Date: Thu, 10 Oct 2024 17:30:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=BA=86=E4=B8=8A=E4=BC=A0os?= =?UTF-8?q?s=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/controller/public.go | 31 +++++++++++++++++++++++++++++++ api/requests/Public.go | 10 ++++++++++ api/router/router.go | 10 +++++++++- 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 api/requests/Public.go diff --git a/api/controller/public.go b/api/controller/public.go index 81af0a6..265dbf8 100644 --- a/api/controller/public.go +++ b/api/controller/public.go @@ -2,7 +2,10 @@ package controller import ( "github.com/gin-gonic/gin" + "knowledge/api/requests" "knowledge/api/responses" + "knowledge/extend/aliyun" + "knowledge/global" "knowledge/utils" ) @@ -20,3 +23,31 @@ func (b *Public) GetCaptcha(c *gin.Context) { "b64s": b64s, }, c) } + +// GetOssSign 获取oss签名 +func (b *Public) GetOssSign(c *gin.Context) { + publicRequest := requests.PublicRequest{} + req := publicRequest.GetOssSign + if err := c.ShouldBind(&req); err != nil { + responses.FailWithMessage(err.Error(), c) + return + } + + // 参数验证 + if err := global.Validate.Struct(req); err != nil { + responses.FailWithMessage(utils.Translate(err), c) + return + } + + // 获取oss签名 + dir := "question/" + + // 生成签名 + ossSign, err := aliyun.GetOssSign(dir) + if err != nil { + responses.FailWithMessage("获取签名失败", c) + return + } + + responses.OkWithData(ossSign, c) +} diff --git a/api/requests/Public.go b/api/requests/Public.go new file mode 100644 index 0000000..5f7b1c9 --- /dev/null +++ b/api/requests/Public.go @@ -0,0 +1,10 @@ +package requests + +type PublicRequest struct { + GetOssSign // 获取oss签名 +} + +// GetOssSign 获取oss签名 +type GetOssSign struct { + Scene int `json:"scene" form:"scene" validate:"required,oneof=1 2" label:"场景"` // (1:场内题目 2:场外题目) +} diff --git a/api/router/router.go b/api/router/router.go index 9d4a24b..993a6e3 100644 --- a/api/router/router.go +++ b/api/router/router.go @@ -111,7 +111,15 @@ func publicRouter(r *gin.Engine, api controller.Api) { // adminRouter 公共路由-验证权限 func adminRouter(r *gin.Engine, api controller.Api) { - + adminGroup := r.Group("/admin") + { + // 签名 + signGroup := adminGroup.Group("/sign") + { + // 获取oss签名 + signGroup.GET("/oss", api.Public.GetOssSign) + } + } } // basicRouter 基础数据-验证权限