yinbangzhong
2024-06-19 dd2c694c124c4a0f5b1d9c5a876337bd424d697f
download file by attach model
6个文件已修改
131 ■■■■■ 已修改文件
controllers/audio.go 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
response/audio.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/router.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/audio.go
@@ -111,6 +111,9 @@
    if err := models.NewAudioSearch().Create(audio); err != nil {
        util.ResponseFormat(c, code.SaveFail, "上传失败")
        return
    } else {
        util.ResponseFormat(c, code.SaveFail, "上传成功")
        return
    }
    go func() {
        var trainInfoNames = []string{audio.LocomotiveNumber, audio.TrainNumber, audio.Station}
@@ -290,13 +293,17 @@
    filepath := ""
    if params.Filetype == 1 {
        filepath = audio.FilePath
        c.Header("Content-Type", "audio/mpeg") // 设置音频文件类型
        c.Header("Content-Type", "audio/mpeg")                                              // 设置音频文件类型
        c.Header("Content-Disposition", "attachment; filename="+url.PathEscape(audio.Name)) // 在浏览器中直接打开
    }
    if params.Filetype == 2 {
        filepath = audio.TxtFilePath
        //设置Content-Type为txt文件类型,避免中文乱码
        c.Header("Content-Type", "text/plain; charset=utf-8")
        c.Header("Content-Transfer-Encoding", "binary")
        //去掉audio.Name中.之后的内容,只保留文件名称
        fileName := strings.Split(audio.Name, ".")[0]
        c.Header("Content-Disposition", "attachment; filename="+url.PathEscape(fmt.Sprintf("%s.txt", fileName))) // 在浏览器中直接打开
    }
    if filepath == "" {
        util.ResponseFormat(c, code.InternalError, "查询失败")
@@ -316,7 +323,6 @@
        return
    }
    c.Header("Content-Disposition", "inline; filename="+url.PathEscape(audio.Name)) // 在浏览器中直接打开
    c.Header("Content-Length", fmt.Sprint(fileInfo.Size()))
    if _, err := io.Copy(c.Writer, file); err != nil {
@@ -470,3 +476,19 @@
    util.ResponseFormat(c, code.UpdateSuccess, resp)
}
// PreLoadPath
// @Tags      音频自动加载路径
// @Summary   音频自动加载路径
// @Produce   application/json
// @Success   200 {object} util.Response{data=response.PreLoadPathResp} "成功"
// @Router    /api-sa/v1/audio/preLoadPath [get]
func (slf AudioCtl) PreLoadPath(c *gin.Context) {
    //获取PRELOAD_PATH环境变量
    preLoadPath := os.Getenv("PRELOAD_PATH")
    if len(preLoadPath) == 0 {
        preLoadPath = "./preloads"
    }
    resp := response.PreLoadPathResp{PreLoadPath: preLoadPath}
    util.ResponseFormat(c, code.UpdateSuccess, resp)
}
docs/docs.go
@@ -360,6 +360,37 @@
                }
            }
        },
        "/api-sa/v1/audio/preLoadPath": {
            "get": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "音频自动加载路径"
                ],
                "summary": "音频自动加载路径",
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/util.Response"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/definitions/response.PreLoadPathResp"
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/api-sa/v1/audio/process": {
            "post": {
                "produces": [
@@ -927,6 +958,14 @@
                }
            }
        },
        "response.PreLoadPathResp": {
            "type": "object",
            "properties": {
                "preLoadPath": {
                    "type": "string"
                }
            }
        },
        "util.Response": {
            "type": "object",
            "properties": {
docs/swagger.json
@@ -349,6 +349,37 @@
                }
            }
        },
        "/api-sa/v1/audio/preLoadPath": {
            "get": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "音频自动加载路径"
                ],
                "summary": "音频自动加载路径",
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/util.Response"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/definitions/response.PreLoadPathResp"
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/api-sa/v1/audio/process": {
            "post": {
                "produces": [
@@ -916,6 +947,14 @@
                }
            }
        },
        "response.PreLoadPathResp": {
            "type": "object",
            "properties": {
                "preLoadPath": {
                    "type": "string"
                }
            }
        },
        "util.Response": {
            "type": "object",
            "properties": {
docs/swagger.yaml
@@ -192,6 +192,11 @@
        - $ref: '#/definitions/constvar.BoolType'
        description: 1 已关注 2未关注
    type: object
  response.PreLoadPathResp:
    properties:
      preLoadPath:
        type: string
    type: object
  util.Response:
    properties:
      code:
@@ -430,6 +435,23 @@
      summary: 音频分析检索
      tags:
      - 音频
  /api-sa/v1/audio/preLoadPath:
    get:
      produces:
      - application/json
      responses:
        "200":
          description: 成功
          schema:
            allOf:
            - $ref: '#/definitions/util.Response'
            - properties:
                data:
                  $ref: '#/definitions/response.PreLoadPathResp'
              type: object
      summary: 音频自动加载路径
      tags:
      - 音频自动加载路径
  /api-sa/v1/audio/process:
    post:
      parameters:
response/audio.go
@@ -5,3 +5,7 @@
type FollowResp struct {
    FollowStatus constvar.BoolType `json:"followStatus"` //1 已关注 2未关注
}
type PreLoadPathResp struct {
    PreLoadPath string `json:"preLoadPath"`
}
router/router.go
@@ -35,6 +35,7 @@
        audioAPi.DELETE("delete", audioCtl.Delete)            // 音频删除
        audioAPi.DELETE("batchDelete", audioCtl.BatchDelete)  // 音频批量删除
        audioAPi.POST("follow", audioCtl.Follow)              // 关注/取消关注
        audioAPi.GET("preLoadPath", audioCtl.PreLoadPath)     // 获取自动加载路径
    }