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) }