package videoapi import ( "videoweb/app/api/proto" "videoweb/app/service/configser" "videoweb/app/service/slugser" "videoweb/app/service/translationser" "videoweb/app/service/videoser" "videoweb/pub/common" "videoweb/pub/common/srvdef" "github.com/gin-gonic/gin" ) // List app端上架视频列表 // @Tags 视频相关接口 // @Summary app端上架视频列表 -- by 王鸣 // @Description 按分类和排序分页查询上架视频,最近更新按更新时间降序,每五条视频后穿插一条广告 // @Accept json // @Produce json // @Param params query proto.VideoListReq true "视频列表请求" // @Success 200 {object} proto.VideoListResp{list=[]proto.VideoRecommendListItem} "成功" // @Failure 400 {string} string "获取失败的返回结果" // @Router /api/app/video/list [get] func List(c *gin.Context) { var req proto.VideoListReq if err := c.ShouldBindQuery(&req); err != nil { common.ServerJSON(c, srvdef.ErrParamError, "") return } data, err := videoser.VideoList(c, &req) if err != nil { common.ServerJSON(c, err, "") return } common.ServerJSON(c, srvdef.Success, data) } // CategoryList 查询全部已启用视频分类 // @Tags 视频相关接口 // @Summary app端视频分类列表 // @Produce json // @Success 200 {object} proto.VideoCategoryListResp "成功" // @Router /api/app/video/category/list [get] func CategoryList(c *gin.Context) { resp, err := videoser.VideoCategoryList(c) if err != nil { common.ServerJSON(c, err, err.GetMsg()) return } common.ServerJSON(c, srvdef.Success, resp) } // RecommendList app端推荐视频列表 // @Tags 视频相关接口 // @Summary app端推荐视频列表 -- by 王鸣 // @Description 分页查询视频列表,带穿插列表广告,每间隔8条视频数据插入一个广告 // @Accept json // @Produce json // @Param params query proto.VideoRecommendListReq true "推荐视频列表请求" // @Success 200 {object} proto.VideoRecommendListResp{list=[]proto.VideoRecommendListItem} "成功" // @Failure 400 {string} string "获取失败的返回结果" // @Router /api/app/video/recommend/list [get] func RecommendList(c *gin.Context) { var req proto.VideoRecommendListReq if err := c.ShouldBindQuery(&req); err != nil { common.ServerJSON(c, srvdef.ErrParamError, "") return } data, err := videoser.VideoRecommendList(c, &req) if err != nil { common.ServerJSON(c, err, "") return } common.ServerJSON(c, srvdef.Success, data) } // GuessList 分页查询猜你喜欢视频 // @Tags 视频相关接口 // @Summary 猜你喜欢视频列表 -- by 王鸣 // @Description id可选,传入时排除当前视频,按展示观看量降序查询上架视频 // @Produce json // @Param params query proto.VideoGuessListReq true "猜你喜欢视频请求" // @Success 200 {object} proto.VideoGuessListResp{list=[]proto.VideoRecommendListItem} "成功" // @Router /api/app/video/guess/list [get] func GuessList(c *gin.Context) { var req proto.VideoGuessListReq if err := c.ShouldBindQuery(&req); err != nil { common.ServerJSON(c, srvdef.ErrParamError, "") return } data, err := videoser.VideoGuessList(c, &req) if err != nil { common.ServerJSON(c, err, err.GetMsg()) return } common.ServerJSON(c, srvdef.Success, data) } // TagList app端根据标签ID查询视频列表 // @Tags 视频相关接口 // @Summary app端根据标签ID查询视频列表 -- by 王鸣 // @Description 根据统一标签ID分页查询视频列表,带穿插列表广告,每间隔8条视频数据插入一个广告 // @Accept json // @Produce json // @Param id path int true "标签ID" // @Param pageNum query int false "页码,默认1" // @Param pageSize query int false "每页数量,默认20,最大100" // @Success 200 {object} proto.VideoRecommendListResp{list=[]proto.VideoRecommendListItem} "成功" // @Failure 400 {string} string "获取失败的返回结果" // @Router /api/app/video/tag/{id} [get] func TagList(c *gin.Context) { var req proto.ContentTagPageReq if err := c.ShouldBindQuery(&req); err != nil { common.ServerJSON(c, srvdef.ErrParamError, "") return } pathID, pathSlug := slugser.ParseIDOrSlug(c.Param("id")) if req.Id <= 0 { req.Id = pathID } if req.Slug == "" { req.Slug = pathSlug } data, err := videoser.VideoTagList(c, &req) if err != nil { common.ServerJSON(c, err, "") return } common.ServerJSON(c, srvdef.Success, data) } // QueryVideoMore // @Tags 视频相关接口 // @Summary 根据分类id查询视频列表 --by 王鸣 // @Description 根据分类id查询视频列表,带穿插列表广告,每间隔8条视频数据插入一个广告 // @Accept json // @Produce json // @Param params query proto.QueryVideoReq true "视频更多查询请求" // @Success 200 {object} proto.QueryVideoResp{list=[]proto.QueryVideoListItem{VideoInfo=proto.VideoInfo}} "成功" // @Failure 400 {string} string "获取失败的返回结果" // @Router /api/app/video/more [get] func QueryVideoMore(c *gin.Context) { var req proto.QueryVideoReq if err := c.ShouldBindQuery(&req); err != nil { common.ServerJSON(c, srvdef.ErrParamError, "") return } data, err := videoser.QueryVideoMore(c, &req) if err != nil { common.ServerJSON(c, err, "") return } common.ServerJSON(c, srvdef.Success, data) } // QueryVideoInfo 视频详情 // @Tags 视频相关接口 // @Summary 视频详情 -- by 王鸣 // @Description 查询视频详情、收藏状态和点赞状态 // @Accept json // @Produce json // @Param params query proto.QueryVideoInfoReq true "视频详情查询请求" // @Success 200 {object} proto.QueryVideoInfoResp{videoInfo=proto.VideoDetailInfo} "成功" // @Failure 400 {string} string "获取失败的返回结果" // @Router /api/app/video/info [get] func QueryVideoInfo(c *gin.Context) { var req proto.QueryVideoInfoReq if err := c.ShouldBindQuery(&req); err != nil { common.ServerJSON(c, srvdef.ErrParamError, "") return } data, err := videoser.QueryVideoInfo(c, common.GetUserId(c), videoser.H5M3U8RequestIP(c), c.Request.UserAgent(), &req) if err != nil { common.ServerJSON(c, err, "") return } common.ServerJSON(c, srvdef.Success, data) } // FavoriteVideo 收藏或取消收藏视频 // @Tags 视频相关接口 // @Summary 收藏或取消收藏视频 --by 旺鸣 // @Description 当前登录用户收藏或取消收藏指定视频,isFavorite=true表示收藏,isFavorite=false表示取消收藏 // @Accept json // @Produce json // @Param param body proto.FavoriteVideoReq true "收藏或取消收藏请求" // @Success 200 {object} proto.FavoriteVideoResp "成功" // @Failure 400 {string} string "获取失败的返回结果" // @Security ApiKeyAuth // @Router /api/app/video/favorite [post] func FavoriteVideo(c *gin.Context) { var req proto.FavoriteVideoReq if err := c.ShouldBindJSON(&req); err != nil { common.ServerJSON(c, srvdef.ErrParamError, "") return } userId := common.GetUserId(c) if userId <= 0 { common.ServerJSON(c, srvdef.InvalidToken, "") return } ua, _ := common.GetUA(c) if ua.UserAgent == "" { ua.UserAgent = c.Request.UserAgent() } data, err := videoser.FavoriteVideo(c, userId, c.ClientIP(), ua, &req) if err != nil { common.ServerJSON(c, err, "") return } common.ServerJSON(c, srvdef.Success, data) } // LikeVideo 点赞或取消点赞视频 // @Tags 视频相关接口 // @Summary 点赞或取消点赞视频 -- by 王鸣 // @Description 当前登录用户点赞或取消点赞指定视频,isLike=true表示点赞,isLike=false表示取消点赞 // @Accept json // @Produce json // @Param param body proto.LikeVideoReq true "点赞或取消点赞请求" // @Success 200 {object} proto.LikeVideoResp "成功" // @Failure 400 {string} string "获取失败的返回结果" // @Security ApiKeyAuth // @Router /api/app/video/like [post] func LikeVideo(c *gin.Context) { var req proto.LikeVideoReq if err := c.ShouldBindJSON(&req); err != nil { common.ServerJSON(c, srvdef.ErrParamError, "") return } userId := common.GetUserId(c) if userId <= 0 { common.ServerJSON(c, srvdef.InvalidToken, "") return } ua, _ := common.GetUA(c) if ua.UserAgent == "" { ua.UserAgent = c.Request.UserAgent() } data, err := videoser.LikeVideo(c, userId, c.ClientIP(), ua, &req) if err != nil { common.ServerJSON(c, err, "") return } common.ServerJSON(c, srvdef.Success, data) } // QueryVideoRank 视频收藏排行榜 // @Tags 视频相关接口 // @Summary 视频收藏排行榜 // @Description 视频收藏排行榜 // @Accept json // @Produce json // @Success 200 {object} proto.RankResp "成功" // @Failure 400 {string} string "获取失败的返回结果" // @Router /api/app/video/rank [get] func QueryVideoRank(c *gin.Context) { rank := proto.HomeRankData{ Total: configser.GetVideoRankList(configser.RankPeriodTotal, 0), Week: configser.GetVideoRankList(configser.RankPeriodWeek, 0), Month: configser.GetVideoRankList(configser.RankPeriodMonth, 0), Year: configser.GetVideoRankList(configser.RankPeriodYear, 0), } common.ServerJSON(c, srvdef.Success, proto.RankResp{ RankData: rank, Translations: translationser.GetTranslationData(), BottonTranslations: translationser.GetTranslationBottomList(), }) } // QueryVideoRankList 视频排行榜分页列表 // @Tags 视频相关接口 // @Summary 视频排行榜分页列表 -- by 王鸣 // @Description 分页查询视频排行榜,rankPeriod=0点赞榜(累计点赞)、1周榜/2月榜/3年榜(周期观看量),独立缓存10分钟,每榜最多50条,pageSize不是50时强制为50 // @Accept json // @Produce json // @Param params query proto.VideoRankReq true "视频排行榜分页请求" // @Success 200 {object} proto.VideoRankResp{list=[]proto.ContentData} "成功" // @Failure 400 {string} string "获取失败的返回结果" // @Router /api/app/video/rank/list [get] func QueryVideoRankList(c *gin.Context) { var req proto.VideoRankReq if err := c.ShouldBindQuery(&req); err != nil { common.ServerJSON(c, srvdef.ErrParamError, "") return } data, err := videoser.QueryVideoRank(c, &req) if err != nil { common.ServerJSON(c, err, "") return } common.ServerJSON(c, srvdef.Success, data) } // QueryFavoriteVideoList 当前登录用户收藏视频分页列表 // @Tags 视频相关接口 // @Summary 当前登录用户收藏视频分页列表 --by 旺鸣 // @Description 当前登录用户收藏视频分页列表,按收藏时间倒序排序 // @Accept json // @Produce json // @Param params query proto.QueryFavoriteVideoListReq true "收藏视频分页请求" // @Success 200 {object} proto.QueryFavoriteVideoListResp{list=[]proto.FavoriteVideoListItem} "成功" // @Failure 400 {string} string "获取失败的返回结果" // @Security ApiKeyAuth // @Router /api/app/video/favorite/list [get] func QueryFavoriteVideoList(c *gin.Context) { var req proto.QueryFavoriteVideoListReq if err := c.ShouldBindQuery(&req); err != nil { common.ServerJSON(c, srvdef.ErrParamError, "") return } userId := common.GetUserId(c) if userId <= 0 { common.ServerJSON(c, srvdef.InvalidToken, "") return } data, err := videoser.QueryFavoriteVideoList(c, userId, &req) if err != nil { common.ServerJSON(c, err, "") return } common.ServerJSON(c, srvdef.Success, data) } // QueryLikeVideoList 当前用户点赞视频分页列表 // @Tags 视频相关接口 // @Summary 当前用户点赞视频分页列表 // @Description 按点赞时间倒序返回当前用户点赞的上架视频 // @Produce json // @Param params query proto.QueryLikeVideoListReq true "点赞视频分页请求" // @Success 200 {object} proto.QueryLikeVideoListResp{list=[]proto.FavoriteVideoListItem} "成功" // @Security ApiKeyAuth // @Router /api/app/video/like/list [get] func QueryLikeVideoList(c *gin.Context) { var req proto.QueryLikeVideoListReq if err := c.ShouldBindQuery(&req); err != nil { common.ServerJSON(c, srvdef.ErrParamError, "") return } userID := common.GetUserId(c) if userID <= 0 { common.ServerJSON(c, srvdef.InvalidToken, "") return } resp, err := videoser.QueryLikeVideoList(c, userID, &req) if err != nil { common.ServerJSON(c, err, err.GetMsg()) return } common.ServerJSON(c, srvdef.Success, resp) } // ReportVideoHistory 播放成功后记录当前用户的视频 // @Tags 视频相关接口 // @Summary 上报视频观看历史 // @Accept json // @Produce json // @Param param body proto.VideoHistoryReportReq true "当前播放视频" // @Success 200 {object} proto.VideoHistoryReportResp "成功" // @Security ApiKeyAuth // @Router /api/app/video/history [post] func ReportVideoHistory(c *gin.Context) { userID := common.GetUserId(c) if userID <= 0 { common.ServerJSON(c, srvdef.InvalidToken, "") return } var req proto.VideoHistoryReportReq if err := c.ShouldBindJSON(&req); err != nil { common.ServerJSON(c, srvdef.ErrParamError, "") return } resp, err := videoser.ReportVideoHistory(c, userID, &req) if err != nil { common.ServerJSON(c, err, err.GetMsg()) return } common.ServerJSON(c, srvdef.Success, resp) } // QueryVideoHistoryList 当前用户视频观看历史分页列表 // @Tags 视频相关接口 // @Summary 视频观看历史列表 // @Produce json // @Param params query proto.VideoHistoryListReq true "分页请求" // @Success 200 {object} proto.VideoHistoryListResp{list=[]proto.VideoHistoryItem} "成功" // @Security ApiKeyAuth // @Router /api/app/video/history/list [get] func QueryVideoHistoryList(c *gin.Context) { userID := common.GetUserId(c) if userID <= 0 { common.ServerJSON(c, srvdef.InvalidToken, "") return } var req proto.VideoHistoryListReq if err := c.ShouldBindQuery(&req); err != nil { common.ServerJSON(c, srvdef.ErrParamError, "") return } resp, err := videoser.QueryVideoHistoryList(c, userID, &req) if err != nil { common.ServerJSON(c, err, err.GetMsg()) return } common.ServerJSON(c, srvdef.Success, resp) } // ClearVideoHistory 清空当前用户视频观看历史 // @Tags 视频相关接口 // @Summary 清空视频观看历史 // @Produce json // @Success 200 {object} proto.VideoHistoryClearResp "成功" // @Security ApiKeyAuth // @Router /api/app/video/history [delete] func ClearVideoHistory(c *gin.Context) { userID := common.GetUserId(c) if userID <= 0 { common.ServerJSON(c, srvdef.InvalidToken, "") return } resp, err := videoser.ClearVideoHistory(c, userID) if err != nil { common.ServerJSON(c, err, err.GetMsg()) return } common.ServerJSON(c, srvdef.Success, resp) }