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.
94 lines
2.2 KiB
94 lines
2.2 KiB
package handler
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"laic-backend/common"
|
|
"laic-backend/service"
|
|
"laic-backend/vo"
|
|
)
|
|
|
|
// CreateVideoUpload 申请视频上传
|
|
func CreateVideoUpload(c *gin.Context) {
|
|
var req vo.VideoUploadReq
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
common.FailWithBindError(c, common.ErrParam, err)
|
|
return
|
|
}
|
|
result, busiErr := service.DefaultVideoService.CreateUpload(common.GetUserId(c), &req)
|
|
if busiErr != nil {
|
|
common.FailWithBusiError(c, busiErr)
|
|
return
|
|
}
|
|
common.OKWithData(c, result)
|
|
}
|
|
|
|
// CompleteVideoUpload 上传完成确认
|
|
func CompleteVideoUpload(c *gin.Context) {
|
|
videoID, busiErr := parseID(c)
|
|
if busiErr != nil {
|
|
common.FailWithBusiError(c, busiErr)
|
|
return
|
|
}
|
|
var req vo.VideoCompleteReq
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
common.FailWithBindError(c, common.ErrParam, err)
|
|
return
|
|
}
|
|
video, busiErr := service.DefaultVideoService.Complete(common.GetUserId(c), videoID, &req)
|
|
if busiErr != nil {
|
|
common.FailWithBusiError(c, busiErr)
|
|
return
|
|
}
|
|
common.OKWithData(c, video)
|
|
}
|
|
|
|
// GetVideoPage 视频分页列表
|
|
func GetVideoPage(c *gin.Context) {
|
|
var req vo.VideoPageReq
|
|
_ = c.ShouldBindQuery(&req)
|
|
if req.PageNum <= 0 {
|
|
req.PageNum = 1
|
|
}
|
|
if req.PageSize <= 0 {
|
|
req.PageSize = 10
|
|
}
|
|
page, busiErr := service.DefaultVideoService.GetPage(common.GetUserId(c), common.IsAdmin(c), &req)
|
|
if busiErr != nil {
|
|
common.FailWithBusiError(c, busiErr)
|
|
return
|
|
}
|
|
common.OKWithData(c, page)
|
|
}
|
|
|
|
// GetVideo 视频详情
|
|
func GetVideo(c *gin.Context) {
|
|
videoID, busiErr := parseID(c)
|
|
if busiErr != nil {
|
|
common.FailWithBusiError(c, busiErr)
|
|
return
|
|
}
|
|
video, busiErr := service.DefaultVideoService.GetDetail(common.GetUserId(c), common.IsAdmin(c), videoID)
|
|
if busiErr != nil {
|
|
common.FailWithBusiError(c, busiErr)
|
|
return
|
|
}
|
|
common.OKWithData(c, video)
|
|
}
|
|
|
|
// DownloadVideo 下载视频
|
|
func DownloadVideo(c *gin.Context) {
|
|
videoID, busiErr := parseID(c)
|
|
if busiErr != nil {
|
|
common.FailWithBusiError(c, busiErr)
|
|
return
|
|
}
|
|
result, busiErr := service.DefaultVideoService.Download(
|
|
common.GetUserId(c), common.IsAdmin(c), videoID, c.GetHeader("Idempotency-Key"),
|
|
)
|
|
if busiErr != nil {
|
|
common.FailWithBusiError(c, busiErr)
|
|
return
|
|
}
|
|
common.OKWithData(c, result)
|
|
}
|
|
|