|
@@ -7,7 +7,6 @@ import (
|
|
|
"eta/eta_api/utils"
|
|
|
"fmt"
|
|
|
"github.com/kgiannakakis/mp3duration/src/mp3duration"
|
|
|
- "github.com/rdlucklib/rdluck_tools/file"
|
|
|
"github.com/rdlucklib/rdluck_tools/http"
|
|
|
"io/ioutil"
|
|
|
"os"
|
|
@@ -194,36 +193,80 @@ func (this *VoiceCommonController) Download() {
|
|
|
br.ErrMsg = "获取,ReportId,Err:" + err.Error()
|
|
|
return
|
|
|
}
|
|
|
- report, err := models.GetReportById(reportId)
|
|
|
+ reportInfo, err := models.GetReportById(reportId)
|
|
|
if err != nil {
|
|
|
br.Msg = "获取信息失败"
|
|
|
br.ErrMsg = "获取信息失败,Err:" + err.Error()
|
|
|
return
|
|
|
}
|
|
|
- savePath := time.Now().Format(utils.FormatDateTimeUnSpace) + utils.GetRandString(5) + ".mp3"
|
|
|
- fileBody, err := http.Get(report.VideoUrl)
|
|
|
- if err != nil {
|
|
|
- br.Msg = "获取信息失败"
|
|
|
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
|
|
|
- return
|
|
|
+
|
|
|
+ savePath, fileName, err, errMsg := services.DownloadVoice(reportInfo)
|
|
|
+ // 如果生成了文件,那么就在退出的时候,删除该文件
|
|
|
+ if savePath != `` {
|
|
|
+ defer func() {
|
|
|
+ os.Remove(savePath)
|
|
|
+ }()
|
|
|
}
|
|
|
- err = file.SaveFile(fileBody, savePath)
|
|
|
+
|
|
|
if err != nil {
|
|
|
- br.Msg = "保存信息失败"
|
|
|
- br.ErrMsg = "保存信息失败,Err:" + err.Error()
|
|
|
+ br.Msg = errMsg
|
|
|
+ br.ErrMsg = "下载失败,Err:" + err.Error()
|
|
|
return
|
|
|
}
|
|
|
- fileName := report.VideoName + ".mp3"
|
|
|
- this.Ctx.Output.Download(savePath, fileName)
|
|
|
- defer func() {
|
|
|
- os.Remove(savePath)
|
|
|
- }()
|
|
|
+
|
|
|
+ if savePath != `` {
|
|
|
+ this.Ctx.Output.Download(savePath, fileName)
|
|
|
+ }
|
|
|
+
|
|
|
br.Ret = 200
|
|
|
br.Msg = "下载成功"
|
|
|
br.Success = true
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+//func (this *VoiceCommonController) Download() {
|
|
|
+// br := new(models.BaseResponse).Init()
|
|
|
+// defer func() {
|
|
|
+// this.Data["json"] = br
|
|
|
+// this.ServeJSON()
|
|
|
+// }()
|
|
|
+// reportId, err := this.GetInt("ReportId")
|
|
|
+// if err != nil {
|
|
|
+// br.Msg = "参数错误"
|
|
|
+// br.ErrMsg = "获取,ReportId,Err:" + err.Error()
|
|
|
+// return
|
|
|
+// }
|
|
|
+// report, err := models.GetReportById(reportId)
|
|
|
+// if err != nil {
|
|
|
+// br.Msg = "获取信息失败"
|
|
|
+// br.ErrMsg = "获取信息失败,Err:" + err.Error()
|
|
|
+// return
|
|
|
+// }
|
|
|
+// savePath := time.Now().Format(utils.FormatDateTimeUnSpace) + utils.GetRandString(5) + ".mp3"
|
|
|
+// fileBody, err := http.Get(report.VideoUrl)
|
|
|
+// if err != nil {
|
|
|
+// br.Msg = "获取信息失败"
|
|
|
+// br.ErrMsg = "获取信息失败,Err:" + err.Error()
|
|
|
+// return
|
|
|
+// }
|
|
|
+// err = file.SaveFile(fileBody, savePath)
|
|
|
+// if err != nil {
|
|
|
+// br.Msg = "保存信息失败"
|
|
|
+// br.ErrMsg = "保存信息失败,Err:" + err.Error()
|
|
|
+// return
|
|
|
+// }
|
|
|
+// fileName := report.VideoName + ".mp3"
|
|
|
+// this.Ctx.Output.Download(savePath, fileName)
|
|
|
+// defer func() {
|
|
|
+// os.Remove(savePath)
|
|
|
+// }()
|
|
|
+// br.Ret = 200
|
|
|
+// br.Msg = "下载成功"
|
|
|
+// br.Success = true
|
|
|
+// return
|
|
|
+//}
|
|
|
+
|
|
|
// ReportChapterDownload
|
|
|
// @Title 报告章节列表音频下载
|
|
|
// @Description 音频下载接口
|