|
|
@@ -111,6 +111,9 @@ func (slf AudioCtl) Upload(c *gin.Context) {
|
|
|
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 @@ func (slf AudioCtl) AudioDownload(c *gin.Context) {
|
|
|
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 @@ func (slf AudioCtl) AudioDownload(c *gin.Context) {
|
|
|
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 @@ func (slf AudioCtl) Follow(c *gin.Context) {
|
|
|
|
|
|
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)
|
|
|
+}
|