download file by attach model
| | |
| | | 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} |
| | |
| | | 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, "查询失败") |
| | |
| | | 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 { |
| | |
| | | |
| | | 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) |
| | | } |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/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": [ |
| | |
| | | } |
| | | } |
| | | }, |
| | | "response.PreLoadPathResp": { |
| | | "type": "object", |
| | | "properties": { |
| | | "preLoadPath": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "util.Response": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/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": [ |
| | |
| | | } |
| | | } |
| | | }, |
| | | "response.PreLoadPathResp": { |
| | | "type": "object", |
| | | "properties": { |
| | | "preLoadPath": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "util.Response": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | - $ref: '#/definitions/constvar.BoolType' |
| | | description: 1 已关注 2未关注 |
| | | type: object |
| | | response.PreLoadPathResp: |
| | | properties: |
| | | preLoadPath: |
| | | type: string |
| | | type: object |
| | | util.Response: |
| | | properties: |
| | | code: |
| | |
| | | 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: |
| | |
| | | type FollowResp struct { |
| | | FollowStatus constvar.BoolType `json:"followStatus"` //1 已关注 2未关注 |
| | | } |
| | | |
| | | type PreLoadPathResp struct { |
| | | PreLoadPath string `json:"preLoadPath"` |
| | | } |
| | |
| | | audioAPi.DELETE("delete", audioCtl.Delete) // 音频删除 |
| | | audioAPi.DELETE("batchDelete", audioCtl.BatchDelete) // 音频批量删除 |
| | | audioAPi.POST("follow", audioCtl.Follow) // 关注/取消关注 |
| | | audioAPi.GET("preLoadPath", audioCtl.PreLoadPath) // 获取自动加载路径 |
| | | |
| | | } |
| | | |