zhangqian 2 rokov pred
rodič
commit
111676bec4
6 zmenil súbory, kde vykonal 133 pridanie a 1 odobranie
  1. 1 1
      conf/config.yaml
  2. 31 0
      controllers/audio.go
  3. 39 0
      docs/docs.go
  4. 39 0
      docs/swagger.json
  5. 22 0
      docs/swagger.yaml
  6. 1 0
      router/router.go

+ 1 - 1
conf/config.yaml

@@ -17,6 +17,6 @@ log:
   MaxBackups: 2  # 保留的旧日志文件个数
   RotateDays: 5  # 日志文件的最大保留天数
 local:
-  storePath: uploads/
+  storePath: uploads
 analysis:
   url: http://192.168.20.116:5000/recognition

+ 31 - 0
controllers/audio.go

@@ -241,6 +241,37 @@ func (slf AudioCtl) AudioInfo(c *gin.Context) {
 	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(&params); 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   批量处理音频

+ 39 - 0
docs/docs.go

@@ -106,6 +106,45 @@ const docTemplate = `{
                 }
             }
         },
+        "/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": [

+ 39 - 0
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": [

+ 22 - 0
docs/swagger.yaml

@@ -264,6 +264,28 @@ paths:
       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:

+ 1 - 0
router/router.go

@@ -28,6 +28,7 @@ func NewRouter() *gin.Engine {
 		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)  // 音频批量处理