You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
2.4 KiB

package short
import (
"github.com/gin-gonic/gin"
"live/app/common"
"live/app/lib"
"live/app/lib/back"
"live/app/lib/tencent"
"live/app/lib/tools"
"live/app/logic/short"
short2 "live/app/model/short"
)
type Short struct {
}
// @Title 获取短视频上传签名
func (s *Short) UploadSign(c *gin.Context) {
uid := common.GetUserId(c)
if uid == 0 {
back.Fail(c, "未登录")
return
}
back.Suc(c, "操作成功", gin.H{
"sign": tencent.Short.Sign(),
})
}
type argsPublish struct {
Content string `json:"content" form:"content"`
FileId string `json:"fileId" form:"fileId"`
TopicId uint `json:"topicId" form:"topicId"`
GoodsId uint `json:"goodsId" form:"goodsId"`
}
// @Title 发布短视频
func (s *Short) Publish(c *gin.Context) {
uid := common.GetUserId(c)
if uid == 0 {
back.Fail(c, "未登录")
return
}
args := argsPublish{}
if err := tools.ParseParams(&args, c); err != nil {
back.Fail(c, err.Error())
return
}
if args.GoodsId <= 0 || args.Content == "" || args.FileId == "" {
back.Fail(c, "参数错误")
return
}
err := (&short.Short{}).Publish(uid, args.GoodsId, args.TopicId, args.FileId, args.Content, c.Request.Header.Get("X-Recook-Id"), c.Request.Header.Get("X-Recook-Token"))
if err != nil {
back.Fail(c, err.Error())
return
}
back.Suc(c, "发布成功", "")
return
}
func (s *Short) List(c *gin.Context) {
userId := common.GetUserId(c)
args := lib.Page{}
if err := tools.ParseParams(&args, c); err != nil {
back.Fail(c, err.Error())
return
}
list, count, err := (&short.Short{}).List(userId, args)
if err != nil {
back.Err(c, err.Error())
return
}
back.Suc(c, "操作成功", gin.H{
"total": count,
"list": list,
})
return
}
type argsInfo struct {
Id uint `json:"id" form:"id"`
}
type replyInfo struct {
MediaUrl string `json:"mediaUrl"`
FileId string `json:"fileId"`
SignPlay string `json:"signPlay"`
}
// @Title 短视频详情
func (s *Short) Info(c *gin.Context) {
args := argsInfo{}
if err := tools.ParseParams(&args, c); err != nil {
back.Fail(c, err.Error())
return
}
if args.Id <= 0 {
back.Fail(c, "参数错误")
return
}
shortInfo := (&short2.Short{}).GetInfoById(args.Id)
if shortInfo.Id <= 0 {
back.Fail(c, "参数错误")
return
}
sign, _ := tencent.Short.SignPlay(shortInfo.FileId)
reply := replyInfo{
FileId: shortInfo.FileId,
SignPlay: sign,
MediaUrl: shortInfo.MediaUrl,
}
back.Suc(c, "操作成功", reply)
}