From 111676bec43d0698c3f605993fe5b09bf4c93008 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期二, 21 五月 2024 17:59:57 +0800 Subject: [PATCH] 音频下载接口 --- docs/swagger.yaml | 22 +++++++ controllers/audio.go | 31 ++++++++++ docs/docs.go | 39 +++++++++++++ conf/config.yaml | 2 docs/swagger.json | 39 +++++++++++++ router/router.go | 1 6 files changed, 133 insertions(+), 1 deletions(-) diff --git a/conf/config.yaml b/conf/config.yaml index 6e08859..d2f5493 100644 --- a/conf/config.yaml +++ b/conf/config.yaml @@ -17,6 +17,6 @@ MaxBackups: 2 # 淇濈暀鐨勬棫鏃ュ織鏂囦欢涓暟 RotateDays: 5 # 鏃ュ織鏂囦欢鐨勬渶澶т繚鐣欏ぉ鏁� local: - storePath: uploads/ + storePath: uploads analysis: url: http://192.168.20.116:5000/recognition diff --git a/controllers/audio.go b/controllers/audio.go index 2476a6c..2924c9b 100644 --- a/controllers/audio.go +++ b/controllers/audio.go @@ -241,6 +241,37 @@ util.ResponseFormat(c, code.UpdateSuccess, audio) } +// AudioDownload +// @Tags 闊抽 +// @Summary 闊抽涓嬭浇 +// @Produce application/json +// @Param object query request.ProcessAudio true "鍙傛暟" +// @Success 200 {object} util.Response{data=models.Audio} "鎴愬姛" +// @Router /api-sa/v1/audio/download [get] +func (slf AudioCtl) AudioDownload(c *gin.Context) { + var params request.ProcessAudio + if err := c.ShouldBindQuery(¶ms); err != nil { + util.ResponseFormat(c, code.RequestParamError, err.Error()) + return + } + + audio, err := models.NewAudioSearch().SetID(params.ID).First() + if err != nil { + util.ResponseFormat(c, code.InternalError, "鏌ヨ澶辫触") + return + } + + if audio.FilePath == "" { + util.ResponseFormat(c, code.InternalError, "鏌ヨ澶辫触") + return + } + + c.Header("Content-Description", "File Transfer") + c.Header("Content-Disposition", "attachment; filename="+audio.Name) + c.Header("Content-Type", "application/octet-stream") + c.File(audio.FilePath) +} + // BatchProcess // @Tags 闊抽 // @Summary 鎵归噺澶勭悊闊抽 diff --git a/docs/docs.go b/docs/docs.go index 4704be6..59ee610 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -106,6 +106,45 @@ } } }, + "/api-sa/v1/audio/download": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "闊抽" + ], + "summary": "闊抽涓嬭浇", + "parameters": [ + { + "type": "integer", + "name": "id", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/util.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/models.Audio" + } + } + } + ] + } + } + } + } + }, "/api-sa/v1/audio/follow": { "post": { "produces": [ diff --git a/docs/swagger.json b/docs/swagger.json index e7c1bea..367573b 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -94,6 +94,45 @@ } } }, + "/api-sa/v1/audio/download": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "闊抽" + ], + "summary": "闊抽涓嬭浇", + "parameters": [ + { + "type": "integer", + "name": "id", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/util.Response" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/models.Audio" + } + } + } + ] + } + } + } + } + }, "/api-sa/v1/audio/follow": { "post": { "produces": [ diff --git a/docs/swagger.yaml b/docs/swagger.yaml index e6ed566..98fb174 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -264,6 +264,28 @@ summary: 鍒犻櫎闊抽 tags: - 闊抽 + /api-sa/v1/audio/download: + get: + parameters: + - in: query + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: 鎴愬姛 + schema: + allOf: + - $ref: '#/definitions/util.Response' + - properties: + data: + $ref: '#/definitions/models.Audio' + type: object + summary: 闊抽涓嬭浇 + tags: + - 闊抽 /api-sa/v1/audio/follow: post: parameters: diff --git a/router/router.go b/router/router.go index a60c840..421162d 100644 --- a/router/router.go +++ b/router/router.go @@ -28,6 +28,7 @@ audioAPi.POST("upload", audioCtl.Upload) // 涓婁紶闊抽 audioAPi.GET("list", audioCtl.List) // 闊抽妫�绱� audioAPi.GET("info", audioCtl.AudioInfo) // 闊抽璇︽儏 + audioAPi.GET("download", audioCtl.AudioDownload) // 闊抽涓嬭浇 audioAPi.GET("trainInfoList", audioCtl.TrainInfoList) // 鐏溅淇℃伅鍒楄〃 audioAPi.POST("process", audioCtl.Process) // 闊抽澶勭悊 audioAPi.POST("batchProcess", audioCtl.BatchProcess) // 闊抽鎵归噺澶勭悊 -- Gitblit v1.8.0