|
@@ -78,9 +78,11 @@ func CreateVideo(report *models.Report) (err error) {
|
|
|
|
|
|
saveName := utils.GetRandStringNoSpecialChar(16) + ".mp3"
|
|
|
savePath := "./" + saveName
|
|
|
- //if utils.FileIsExist(savePath) {
|
|
|
- // os.Remove(savePath)
|
|
|
- //}
|
|
|
+ defer func() {
|
|
|
+ if utils.FileIsExist(savePath) {
|
|
|
+ os.Remove(savePath)
|
|
|
+ }
|
|
|
+ }()
|
|
|
|
|
|
// 如果没有文本内容,那么就不生成了
|
|
|
videoContent = strings.TrimSpace(videoContent)
|
|
@@ -106,20 +108,6 @@ func CreateVideo(report *models.Report) (err error) {
|
|
|
}
|
|
|
|
|
|
uploadUrl := ``
|
|
|
- //上传到阿里云 和 minio
|
|
|
- //if utils.ObjectStorageClient == "minio" {
|
|
|
- // uploadUrl, err = UploadAudioToMinIo(saveName, savePath)
|
|
|
- // if err != nil {
|
|
|
- // err = errors.New("UploadAudioAliyun Err:" + err.Error())
|
|
|
- // return
|
|
|
- // }
|
|
|
- //} else {
|
|
|
- // uploadUrl, err = UploadAudioAliyun(saveName, savePath)
|
|
|
- // if err != nil {
|
|
|
- // err = errors.New("UploadAudioAliyun Err:" + err.Error())
|
|
|
- // return
|
|
|
- // }
|
|
|
- //}
|
|
|
ossClient := NewOssClient()
|
|
|
if ossClient == nil {
|
|
|
err = fmt.Errorf("初始化OSS服务失败")
|
|
@@ -145,11 +133,7 @@ func CreateVideo(report *models.Report) (err error) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if playSeconds > 0 {
|
|
|
- if utils.FileIsExist(savePath) {
|
|
|
- os.Remove(savePath)
|
|
|
- }
|
|
|
- }
|
|
|
+ // 修改报告的音频信息
|
|
|
err = models.ModifyReportVideo(report.Id, uploadUrl, videoName, sizeStr, playSeconds)
|
|
|
|
|
|
return
|
|
@@ -299,11 +283,19 @@ func CreateReportVideo(reportTitle, reportContent, reportTime string) (uploadUrl
|
|
|
param.Data.Status = 2
|
|
|
videoContent := doc.Text()
|
|
|
|
|
|
+ // 如果没有文本内容,那么就不生成了
|
|
|
+ videoContent = strings.TrimSpace(videoContent)
|
|
|
+ if videoContent == `` {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
saveName := utils.GetRandStringNoSpecialChar(16) + ".mp3"
|
|
|
savePath := "./" + saveName
|
|
|
- //if utils.FileIsExist(savePath) {
|
|
|
- // os.Remove(savePath)
|
|
|
- //}
|
|
|
+ defer func() {
|
|
|
+ if utils.FileIsExist(savePath) {
|
|
|
+ os.Remove(savePath)
|
|
|
+ }
|
|
|
+ }()
|
|
|
contentArr := GetChineseCount(videoContent)
|
|
|
for _, v := range contentArr {
|
|
|
newText := v
|
|
@@ -360,11 +352,5 @@ func CreateReportVideo(reportTitle, reportContent, reportTime string) (uploadUrl
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if playSeconds > 0 {
|
|
|
- if utils.FileIsExist(savePath) {
|
|
|
- os.Remove(savePath)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
return
|
|
|
}
|