Initial commit
This commit is contained in:
@@ -0,0 +1,193 @@
|
||||
package mediaapi
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"net/http"
|
||||
"stat/common/m3u8"
|
||||
"stat/common/stdLog"
|
||||
"stat/service/storage"
|
||||
"stat/service/storage/proxy"
|
||||
"stat/statg"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// @Tags 视频列表
|
||||
// @Summary 视频body上传
|
||||
// @Description 视频body上传
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object}} proxy.UploadVideoBodyResp "成功"
|
||||
// @Failure 400 {string} string "失败"
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /api/stat/media/videoBody [POST]
|
||||
func VideoBody(ctx *gin.Context) {
|
||||
form, err := ctx.MultipartForm()
|
||||
if err != nil {
|
||||
stdLog.ServerJSON(ctx, stdLog.ParamError, err.Error())
|
||||
return
|
||||
}
|
||||
videoUploadDomain := "http://118.107.15.137:18092"
|
||||
result, err := storage.UploadVideoBody(ctx, form, videoUploadDomain)
|
||||
if err != nil || result.Code != http.StatusOK {
|
||||
stdLog.ServerJSON(ctx, stdLog.Failure, err)
|
||||
return
|
||||
}
|
||||
resp := &proxy.UploadVideoBodyResp{
|
||||
Id: result.Data.Id,
|
||||
VideoUri: result.Data.VideoUri,
|
||||
}
|
||||
stdLog.ServerJSON(ctx, stdLog.Success, resp)
|
||||
}
|
||||
|
||||
// @Tags 视频列表
|
||||
// @Summary 视频body上传完成信息调用
|
||||
// @Description 视频body上传完成信息调用
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param req body proxy.BaseInfo true "参数列表"
|
||||
// @Success 200 {int} int "ok"
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /api/stat/media/videoOk [post]
|
||||
func VideoOK(ctx *gin.Context) {
|
||||
var req proxy.BaseInfo
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
stdLog.ServerJSON(ctx, stdLog.ParamError, err.Error())
|
||||
return
|
||||
}
|
||||
videoUploadDomain := "http://118.107.15.137:18092"
|
||||
result, err := storage.UploadVideoOK(ctx, &req, videoUploadDomain)
|
||||
if err != nil || result.Code != http.StatusOK {
|
||||
stdLog.ServerJSON(ctx, stdLog.Failure, err)
|
||||
return
|
||||
}
|
||||
|
||||
stdLog.ServerJSON(ctx, stdLog.Success, result.Data)
|
||||
}
|
||||
|
||||
// @Tags 视频列表
|
||||
// @Summary 根据参数获取视频列表
|
||||
// @Description 获取视频列表
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param req body proxy.MediaSearchReq true "参数列表"
|
||||
// @Success 200 {object} proxy.MediaSearchResp "成功"
|
||||
// @Failure 400 {string} string "获取失败的返回结果"
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /api/stat/media/search [post]
|
||||
func VideoSearch(ctx *gin.Context) {
|
||||
var req proxy.MediaSearchReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
stdLog.ServerJSON(ctx, stdLog.ParamError, err.Error())
|
||||
return
|
||||
}
|
||||
videoUploadDomain := "http://118.107.15.137:18092"
|
||||
result, err := proxy.PostSearch(&req, videoUploadDomain)
|
||||
if err != nil {
|
||||
stdLog.ServerJSON(ctx, stdLog.Failure, err)
|
||||
return
|
||||
}
|
||||
stdLog.ServerJSON(ctx, stdLog.Success, result)
|
||||
|
||||
}
|
||||
|
||||
// @Tags 视频列表
|
||||
// @Summary 更新视频信息
|
||||
// @Description 更新视频信息
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param req body proxy.MediasUpdateReq true "参数列表"
|
||||
// @Success 200 {object} proxy.MediasUpdateResp "成功"
|
||||
// @Failure 400 {string} string "获取失败的返回结果"
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /api/stat/media/update [post]
|
||||
func VideoUpdate(ctx *gin.Context) {
|
||||
var req proxy.MediasUpdateReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
stdLog.ServerJSON(ctx, stdLog.ParamError, err.Error())
|
||||
return
|
||||
}
|
||||
videoUploadDomain := "http://118.107.15.137:18092"
|
||||
result, err := proxy.PostUpdate(&req, videoUploadDomain)
|
||||
if err != nil {
|
||||
stdLog.ServerJSON(ctx, stdLog.Failure, err)
|
||||
return
|
||||
}
|
||||
stdLog.ServerJSON(ctx, stdLog.Success, result)
|
||||
}
|
||||
|
||||
// @Tags 视频列表
|
||||
// @Summary 删除视频列表
|
||||
// @Description 删除视频列表
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param req body proxy.MediasDelReq true "参数列表"
|
||||
// @Success 200 {object} proxy.MediasDelResp "成功"
|
||||
// @Failure 400 {string} string "获取失败的返回结果"
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /api/stat/media/delete [post]
|
||||
func VideoDelete(ctx *gin.Context) {
|
||||
var req proxy.MediasDelReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
stdLog.ServerJSON(ctx, stdLog.ParamError, err.Error())
|
||||
return
|
||||
}
|
||||
videoUploadDomain := "http://118.107.15.137:18092"
|
||||
result, err := proxy.PostDelete(&req, videoUploadDomain)
|
||||
if err != nil {
|
||||
stdLog.ServerJSON(ctx, stdLog.Failure, err)
|
||||
return
|
||||
}
|
||||
stdLog.ServerJSON(ctx, stdLog.Success, result)
|
||||
}
|
||||
|
||||
type fileHandler func(ctx *gin.Context) (contentLength int64, contentType string, reader io.Reader, extraHeaders map[string]string, err error)
|
||||
|
||||
func Enkey(ctx *gin.Context) {
|
||||
fn := func(c *gin.Context) (contentLength int64, contentType string, reader io.Reader, extraHeaders map[string]string, err error) {
|
||||
buffer, err := m3u8.Enkey(c)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
contentLength = int64(buffer.Len())
|
||||
contentType = "application/octet-stream"
|
||||
reader = buffer
|
||||
extraHeaders = map[string]string{}
|
||||
return
|
||||
}
|
||||
handlerFile(ctx, fn)
|
||||
}
|
||||
|
||||
func handlerFile(ctx *gin.Context, h fileHandler) {
|
||||
contentLength, contentType, reader, extraHeaders, err := h(ctx)
|
||||
if err != nil {
|
||||
stdLog.ServerJSON(ctx, stdLog.DownloadM3u8File, err)
|
||||
return
|
||||
}
|
||||
ctx.DataFromReader(http.StatusOK, contentLength, contentType, reader, extraHeaders)
|
||||
}
|
||||
|
||||
func GetM3U8(ctx *gin.Context) {
|
||||
fn := func(c *gin.Context) (contentLength int64, contentType string, reader io.Reader, extraHeaders map[string]string, err error) {
|
||||
m3u8Name := ctx.Param("key")
|
||||
var req m3u8.Req
|
||||
if err = ctx.BindQuery(&req); err != nil {
|
||||
return
|
||||
}
|
||||
req.Name = m3u8Name
|
||||
cdnDomain := statg.Conf.LandPageCDN
|
||||
originDomain := "https://resourceyuan.bbaazz.me"
|
||||
_, buff, err := m3u8.TransFormWithSafely(&req, cdnDomain, originDomain, req.NeedHeader, 1)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
contentType = "application/vnd.apple.mpegurl"
|
||||
reader = bytes.NewReader(buff.Bytes())
|
||||
contentLength = int64(buff.Len())
|
||||
extraHeaders = map[string]string{}
|
||||
return
|
||||
}
|
||||
|
||||
handlerFile(ctx, fn)
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package mediaapi
|
||||
|
||||
import (
|
||||
"stat/api/proto"
|
||||
"stat/common/stdLog"
|
||||
"stat/service/mediatagSer"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// @Tags 视频标签
|
||||
// @Summary 分组分页获取视频标签
|
||||
// @Description 分组分页获取视频标签
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param param body proto.MediaTagSearch true "参数列表"
|
||||
// @Success 200 {object} proto.MediaTagSearchResp "成功"
|
||||
// @Failure 400 {string} string "获取失败的返回结果"
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /api/stat/mediatag/list [POST]
|
||||
func GetMediaTag(ctx *gin.Context) {
|
||||
var req = &proto.MediaTagSearch{}
|
||||
if err := ctx.ShouldBind(req); err != nil {
|
||||
stdLog.ServerJSON(ctx, stdLog.ParamError, err)
|
||||
return
|
||||
}
|
||||
resp, serr := mediatagSer.MediaTag(ctx, req)
|
||||
if serr != nil {
|
||||
stdLog.ServerJSON(ctx, stdLog.Failure, serr)
|
||||
return
|
||||
}
|
||||
|
||||
stdLog.ServerJSON(ctx, stdLog.Success, resp)
|
||||
}
|
||||
|
||||
// @Tags 视频标签
|
||||
// @Summary 添加一个视频标签
|
||||
// @Description 添加一个视频标签
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param param body proto.MediaTagAddReq true "参数列表"
|
||||
// @Success 200 {string} string "成功"
|
||||
// @Failure 400 {string} string "获取失败的返回结果"
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /api/stat/mediatag/add [POST]
|
||||
func AddOneLandpage(ctx *gin.Context) {
|
||||
var req = &proto.MediaTagAddReq{}
|
||||
if err := ctx.ShouldBind(req); err != nil {
|
||||
stdLog.ServerJSON(ctx, stdLog.ParamError, err)
|
||||
return
|
||||
}
|
||||
|
||||
serr := mediatagSer.AddMediaTag(ctx, req)
|
||||
if serr != nil {
|
||||
stdLog.ServerJSON(ctx, stdLog.Failure, serr)
|
||||
return
|
||||
}
|
||||
|
||||
stdLog.ServerJSON(ctx, stdLog.Success, "")
|
||||
}
|
||||
|
||||
// @Tags 视频标签
|
||||
// @Summary 删除一个视频标签
|
||||
// @Description 删除一个视频标签
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param param body proto.MediaTagDelReq true "参数列表"
|
||||
// @Failure 400 {string} string "获取失败的返回结果"
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /api/stat/mediatag/del [POST]
|
||||
func DelOneLandpage(ctx *gin.Context) {
|
||||
var req = &proto.MediaTagDelReq{}
|
||||
if err := ctx.ShouldBind(req); err != nil {
|
||||
stdLog.ServerJSON(ctx, stdLog.ParamError, err)
|
||||
return
|
||||
}
|
||||
serr := mediatagSer.DelMediaTag(ctx, req.Id)
|
||||
if serr != nil {
|
||||
stdLog.ServerJSON(ctx, stdLog.Failure, serr)
|
||||
return
|
||||
}
|
||||
|
||||
stdLog.ServerJSON(ctx, stdLog.Success, "")
|
||||
}
|
||||
|
||||
// @Tags 视频标签
|
||||
// @Summary 更新一个视频标签
|
||||
// @Description 更新一个视频标签
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param param body proto.MediaTagUpdateReq true "参数列表"
|
||||
// @Success 200 {string} string "成功"
|
||||
// @Failure 400 {string} string "获取失败的返回结果"
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /api/stat/mediatag/update [POST]
|
||||
func UpdateOneLandpage(ctx *gin.Context) {
|
||||
var req = &proto.MediaTagUpdateReq{}
|
||||
if err := ctx.ShouldBind(req); err != nil {
|
||||
stdLog.ServerJSON(ctx, stdLog.ParamError, nil)
|
||||
return
|
||||
}
|
||||
serr := mediatagSer.UpdateMediaTag(ctx, req)
|
||||
if serr != nil {
|
||||
stdLog.ServerJSON(ctx, stdLog.Failure, serr)
|
||||
return
|
||||
}
|
||||
|
||||
stdLog.ServerJSON(ctx, stdLog.Success, "")
|
||||
}
|
||||
Reference in New Issue
Block a user