|
@@ -1,12 +1,15 @@
|
|
|
package community
|
|
|
|
|
|
import (
|
|
|
+ "encoding/json"
|
|
|
"fmt"
|
|
|
"github.com/gin-gonic/gin"
|
|
|
"hongze/hongze_yb/controller/response"
|
|
|
"hongze/hongze_yb/global"
|
|
|
"hongze/hongze_yb/logic/yb_community_question"
|
|
|
"hongze/hongze_yb/models/request"
|
|
|
+ "hongze/hongze_yb/models/tables/yb_resource"
|
|
|
+ "strings"
|
|
|
|
|
|
respond "hongze/hongze_yb/models/response"
|
|
|
responseModel "hongze/hongze_yb/models/response"
|
|
@@ -159,6 +162,16 @@ func QuestionReply(c *gin.Context) {
|
|
|
response.Fail("音频不可为空", c)
|
|
|
return
|
|
|
}
|
|
|
+ for i := range req.AudioList {
|
|
|
+ if req.AudioList[i].AudioUrl == "" || req.AudioList[i].AudioPlaySeconds == "" || req.AudioList[i].AudioSize == "" {
|
|
|
+ response.Fail("音频信息有误, 请重新上传", c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if !strings.Contains(req.AudioList[i].AudioUrl, utils.ALIYUN_OSS_HOST) {
|
|
|
+ response.Fail("音频地址有误, 请重新上传", c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
userinfo := user.GetInfoByClaims(c)
|
|
|
msg, err := community.ReplyUserQuestion(int(userinfo.UserID), req.QuestionId, req.AudioList)
|
|
|
if err != nil {
|
|
@@ -278,6 +291,36 @@ func QuestionUploadAudio(c *gin.Context) {
|
|
|
AudioPlaySeconds: fmt.Sprint(seconds),
|
|
|
AudioSize: fmt.Sprint(mb),
|
|
|
}
|
|
|
+
|
|
|
+ // 记录文件
|
|
|
+ userInfo := user.GetInfoByClaims(c)
|
|
|
+ go func() {
|
|
|
+ extendData := struct {
|
|
|
+ FileName string
|
|
|
+ AudioURL string
|
|
|
+ AudioPlaySeconds string
|
|
|
+ AudioSize string
|
|
|
+ UserId int
|
|
|
+ }{
|
|
|
+ file.Filename,
|
|
|
+ resourceUrl,
|
|
|
+ fmt.Sprint(seconds),
|
|
|
+ fmt.Sprint(mb),
|
|
|
+ int(userInfo.UserID),
|
|
|
+ }
|
|
|
+ dataByte, e := json.Marshal(extendData)
|
|
|
+ if e != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ re := new(yb_resource.YbResource)
|
|
|
+ re.ResourceUrl = resourceUrl
|
|
|
+ re.ResourceType = yb_resource.ResourceTypeAudio
|
|
|
+ re.ExtendData = string(dataByte)
|
|
|
+ re.CreateTime = time.Now().Local()
|
|
|
+ if e = re.Create(); e != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }()
|
|
|
response.OkData("上传成功", resp, c)
|
|
|
}
|
|
|
|