From e82398a53ce04923241ee362d86fec5abb575a92 Mon Sep 17 00:00:00 2001 From: shenjiachi Date: Wed, 27 Nov 2024 13:31:09 +0800 Subject: [PATCH] update --- app/hdl/comm/hdl_comm.go | 12 ++--- app/md/comm/hdl_comm.go | 3 +- app/router/router.go | 2 +- docs/docs.go | 99 +++++++++++++++++++++------------------- docs/swagger.json | 99 +++++++++++++++++++++------------------- docs/swagger.yaml | 66 ++++++++++++++------------- 6 files changed, 145 insertions(+), 136 deletions(-) diff --git a/app/hdl/comm/hdl_comm.go b/app/hdl/comm/hdl_comm.go index 279b45a..2aa86aa 100644 --- a/app/hdl/comm/hdl_comm.go +++ b/app/hdl/comm/hdl_comm.go @@ -11,7 +11,6 @@ import ( enum2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum" "github.com/aliyun/aliyun-oss-go-sdk/oss" "github.com/gin-gonic/gin" - "strings" "time" ) @@ -25,7 +24,7 @@ import ( // @Param req body comm.ImgReqUploadReq true "签名上传url" // @Success 200 {string} "许可链接" // @Failure 400 {object} md.Response "具体错误" -// @Router /api/comm/getOssUrl [get] +// @Router /api/v1/comm/getOssUrl [POST] func GetOssUrl(c *gin.Context) { var args comm.ImgReqUploadReq err := c.ShouldBindJSON(&args) @@ -56,7 +55,6 @@ func GetOssUrl(c *gin.Context) { ossBucketScheme := cfgMap[enum2.AliyunOssBucketScheme] accessKeyID := cfgMap[enum2.AliyunOssAccessKeyID] accessKeySecret := cfgMap[enum2.AliyunOssAccessKeySecret] - aliyunOptions := cfgMap[enum2.AliyunOptions] // 创建OSSClient实例。 client, err := oss.New(ossBucketScheme+"://"+endpoint, accessKeyID, accessKeySecret) @@ -72,12 +70,8 @@ func GetOssUrl(c *gin.Context) { return } - optionsList := strings.Split(aliyunOptions, ",") - - var options []oss.Option - - for _, option := range optionsList { - options = append(options, oss.ContentType(option)) + options := []oss.Option{ + oss.ContentType(args.ContentType), } signedURL, err := bucket.SignURL(args.FileName, oss.HTTPPut, 60*5, options...) diff --git a/app/md/comm/hdl_comm.go b/app/md/comm/hdl_comm.go index bce692a..e178a1d 100644 --- a/app/md/comm/hdl_comm.go +++ b/app/md/comm/hdl_comm.go @@ -5,7 +5,8 @@ type AccessRecordsReq struct { } type ImgReqUploadReq struct { - FileName string `json:"file_name" binding:"required" example:"文件名"` + FileName string `json:"file_name,required" binding:"required" example:"文件名"` + ContentType string `json:"content_type,required" binding:"required" example:"image/jpeg"` } type UploadReq struct { diff --git a/app/router/router.go b/app/router/router.go index a45d283..28dad7f 100644 --- a/app/router/router.go +++ b/app/router/router.go @@ -144,6 +144,6 @@ func route(r *gin.RouterGroup) { } func rComm(r *gin.RouterGroup) { - r.GET("/getOssUrl", comm.GetOssUrl) // 获取阿里云上传PutObject所需的签名URL + r.POST("/getOssUrl", comm.GetOssUrl) // 获取阿里云上传PutObject所需的签名URL r.GET("/accessRecords", comm.AccessRecords) // 访问记录 } diff --git a/docs/docs.go b/docs/docs.go index 238311c..3ec03ff 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -24,53 +24,6 @@ const docTemplate = `{ "host": "{{.Host}}", "basePath": "{{.BasePath}}", "paths": { - "/api/comm/getOssUrl": { - "get": { - "description": "上传许可链接(获取)", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "对象存储" - ], - "summary": "通用请求-对象存储-上传许可链接(获取)", - "parameters": [ - { - "type": "string", - "description": "验证参数Bearer和token空格拼接", - "name": "Authorization", - "in": "header", - "required": true - }, - { - "description": "签名上传url", - "name": "req", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/comm.ImgReqUploadReq" - } - } - ], - "responses": { - "200": { - "description": "许可链接", - "schema": { - "type": "string" - } - }, - "400": { - "description": "具体错误", - "schema": { - "$ref": "#/definitions/md.Response" - } - } - } - } - }, "/api/v1/addFriend/basalRate": { "get": { "description": "基础速率(获取)", @@ -727,6 +680,53 @@ const docTemplate = `{ } } }, + "/api/v1/comm/getOssUrl": { + "post": { + "description": "上传许可链接(获取)", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "对象存储" + ], + "summary": "通用请求-对象存储-上传许可链接(获取)", + "parameters": [ + { + "type": "string", + "description": "验证参数Bearer和token空格拼接", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "description": "签名上传url", + "name": "req", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/comm.ImgReqUploadReq" + } + } + ], + "responses": { + "200": { + "description": "许可链接", + "schema": { + "type": "string" + } + }, + "400": { + "description": "具体错误", + "schema": { + "$ref": "#/definitions/md.Response" + } + } + } + } + }, "/api/v1/config": { "get": { "description": "基本配置", @@ -2361,9 +2361,14 @@ const docTemplate = `{ "comm.ImgReqUploadReq": { "type": "object", "required": [ + "content_type", "file_name" ], "properties": { + "content_type": { + "type": "string", + "example": "image/jpeg" + }, "file_name": { "type": "string", "example": "文件名" diff --git a/docs/swagger.json b/docs/swagger.json index 88fe638..c550489 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -18,53 +18,6 @@ "host": "ddxq.izhim.com", "basePath": "/api/v1", "paths": { - "/api/comm/getOssUrl": { - "get": { - "description": "上传许可链接(获取)", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "对象存储" - ], - "summary": "通用请求-对象存储-上传许可链接(获取)", - "parameters": [ - { - "type": "string", - "description": "验证参数Bearer和token空格拼接", - "name": "Authorization", - "in": "header", - "required": true - }, - { - "description": "签名上传url", - "name": "req", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/comm.ImgReqUploadReq" - } - } - ], - "responses": { - "200": { - "description": "许可链接", - "schema": { - "type": "string" - } - }, - "400": { - "description": "具体错误", - "schema": { - "$ref": "#/definitions/md.Response" - } - } - } - } - }, "/api/v1/addFriend/basalRate": { "get": { "description": "基础速率(获取)", @@ -721,6 +674,53 @@ } } }, + "/api/v1/comm/getOssUrl": { + "post": { + "description": "上传许可链接(获取)", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "对象存储" + ], + "summary": "通用请求-对象存储-上传许可链接(获取)", + "parameters": [ + { + "type": "string", + "description": "验证参数Bearer和token空格拼接", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "description": "签名上传url", + "name": "req", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/comm.ImgReqUploadReq" + } + } + ], + "responses": { + "200": { + "description": "许可链接", + "schema": { + "type": "string" + } + }, + "400": { + "description": "具体错误", + "schema": { + "$ref": "#/definitions/md.Response" + } + } + } + } + }, "/api/v1/config": { "get": { "description": "基本配置", @@ -2355,9 +2355,14 @@ "comm.ImgReqUploadReq": { "type": "object", "required": [ + "content_type", "file_name" ], "properties": { + "content_type": { + "type": "string", + "example": "image/jpeg" + }, "file_name": { "type": "string", "example": "文件名" diff --git a/docs/swagger.yaml b/docs/swagger.yaml index b0670be..6b6af8b 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -20,10 +20,14 @@ definitions: type: object comm.ImgReqUploadReq: properties: + content_type: + example: image/jpeg + type: string file_name: example: 文件名 type: string required: + - content_type - file_name type: object md.AdvertisingBasic: @@ -1246,37 +1250,6 @@ info: title: 蛋蛋星球-APP客户端 version: "1.0" paths: - /api/comm/getOssUrl: - get: - consumes: - - application/json - description: 上传许可链接(获取) - parameters: - - description: 验证参数Bearer和token空格拼接 - in: header - name: Authorization - required: true - type: string - - description: 签名上传url - in: body - name: req - required: true - schema: - $ref: '#/definitions/comm.ImgReqUploadReq' - produces: - - application/json - responses: - "200": - description: 许可链接 - schema: - type: string - "400": - description: 具体错误 - schema: - $ref: '#/definitions/md.Response' - summary: 通用请求-对象存储-上传许可链接(获取) - tags: - - 对象存储 /api/v1/addFriend/basalRate: get: consumes: @@ -1710,6 +1683,37 @@ paths: summary: 蛋蛋学院-文章-分享后调用统计数量 tags: - 蛋蛋学院 + /api/v1/comm/getOssUrl: + post: + consumes: + - application/json + description: 上传许可链接(获取) + parameters: + - description: 验证参数Bearer和token空格拼接 + in: header + name: Authorization + required: true + type: string + - description: 签名上传url + in: body + name: req + required: true + schema: + $ref: '#/definitions/comm.ImgReqUploadReq' + produces: + - application/json + responses: + "200": + description: 许可链接 + schema: + type: string + "400": + description: 具体错误 + schema: + $ref: '#/definitions/md.Response' + summary: 通用请求-对象存储-上传许可链接(获取) + tags: + - 对象存储 /api/v1/config: get: consumes: