Files
2026-11-07 10:47:32 +08:00

237 lines
7.4 KiB
Go

package web_video
import (
"videoweb/pub/common"
"videoweb/pub/common/srvdef"
"videoweb/web/api/proto"
"videoweb/web/middleware/auth"
"videoweb/web/service/srv_videoinfo"
"videoweb/web/service/srv_videoslug"
"github.com/gin-gonic/gin"
)
// @Tags 视频管理
// @Summary 分组分页获取视频管理
// @Description 分组分页获取视频管理
// @Accept json
// @Produce json
// @Param param body srv_videoinfo.VideoInfoReq true "参数列表"
// @Success 200 {object} srv_videoinfo.VideoInfoResp "成功"
// @Failure 400 {string} string "获取失败的返回结果"
// @Security ApiKeyAuth
// @Router /api/web/videoinfo/list [POST]
func GetVideoInfo(ctx *gin.Context) {
var req = &srv_videoinfo.VideoInfoReq{}
if err := ctx.ShouldBind(req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
return
}
resp, serr := srv_videoinfo.GetVideoInfos(ctx, req)
if serr != nil {
common.ServerJSON(ctx, serr.Code, serr.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// @Tags 视频管理
// @Summary 从切片列表同步多个视频
// @Description 从切片列表同步多个视频
// @Accept json
// @Produce json
// @Param param body srv_videoinfo.AddVideoReq true "参数列表"
// @Success 200 {string} string "成功"
// @Failure 400 {string} string "获取失败的返回结果"
// @Security ApiKeyAuth
// @Router /api/web/videoinfo/sync [POST]
func SyncVideoInfo(ctx *gin.Context) {
var req = &srv_videoinfo.AddVideoReq{}
if err := ctx.ShouldBind(req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, err)
return
}
serr := srv_videoinfo.SyncVideoInfo(ctx, req)
if serr != nil {
common.ServerJSON(ctx, serr.Code, serr.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, "")
}
// @Tags 视频管理
// @Summary 删除一个视频管理
// @Description 删除一个视频管理
// @Accept json
// @Produce json
// @Param param body srv_videoinfo.VideoInfoDelReq true "参数列表"
// @Success 200 {string} string "成功"
// @Failure 400 {string} string "获取失败的返回结果"
// @Security ApiKeyAuth
// @Router /api/web/videoinfo/del [POST]
func DelOneVideoInfo(ctx *gin.Context) {
var req = &srv_videoinfo.VideoInfoDelReq{}
if err := ctx.ShouldBind(req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, err)
return
}
serr := srv_videoinfo.DelVideoInfo(ctx, req.Id)
if serr != nil {
common.ServerJSON(ctx, serr.Code, serr.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, "")
}
// @Tags 视频管理
// @Summary 更新一个视频管理
// @Description 更新一个视频管理
// @Accept json
// @Produce json
// @Param param body srv_videoinfo.VideoInfoUpdateReq true "参数列表"
// @Success 200 {string} string "成功"
// @Failure 400 {string} string "获取失败的返回结果"
// @Security ApiKeyAuth
// @Router /api/web/videoinfo/update [POST]
func UpdateOneVideoInfo(ctx *gin.Context) {
var req = &srv_videoinfo.VideoInfoUpdateReq{}
if err := ctx.ShouldBind(req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
return
}
userId := ctx.GetInt64(auth.AccId)
ua, _ := common.GetUA(ctx)
serr := srv_videoinfo.UpdateVideoInfo(ctx, req.Id, userId, req.Param, ua)
if serr != nil {
common.ServerJSON(ctx, serr.Code, serr.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, "")
}
// @Tags 视频管理
// @Summary 新增一个视频合集
// @Description 新增一个视频合集
// @Accept json
// @Produce json
// @Param param body srv_videoinfo.AddVideoCollectionReq true "参数列表"
// @Success 200 {string} string "成功"
// @Failure 400 {string} string "获取失败的返回结果"
// @Security ApiKeyAuth
// @Router /api/web/videoinfo/addcoll [POST]
func AddOneVideoCollection(ctx *gin.Context) {
var req = &srv_videoinfo.AddVideoCollectionReq{}
if err := ctx.ShouldBind(req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
return
}
serr := srv_videoinfo.AddVideoCollection(ctx, req)
if serr != nil {
common.ServerJSON(ctx, serr.Code, serr.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, "")
}
// SetVideoFakeWatchTimes 单/批量设置视频假观看次数
// @Tags 视频管理
// @Summary 单/批量设置视频假观看次数 --by 旺鸣
// @Description 根据ids批量随机设置视频假观看次数
// @Accept json
// @Produce json
// @Param param body srv_videoinfo.SetFakeWatchTimesReq true "参数列表"
// @Success 200 {object} srv_videoinfo.SetFakeCountResp "成功"
// @Failure 400 {string} string "获取失败的返回结果"
// @Security ApiKeyAuth
// @Router /api/web/videoinfo/setFakeWatchTimes [post]
func SetVideoFakeWatchTimes(ctx *gin.Context) {
req := &srv_videoinfo.SetFakeWatchTimesReq{}
if err := ctx.ShouldBind(req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, err.Error())
return
}
resp, err := srv_videoinfo.SetVideoFakeWatchTimes(ctx, req)
if err != nil {
common.ServerJSON(ctx, err.Code, err.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// SetCategory web端单/批量设置视频分类
// @Tags 视频管理
// @Summary web端单/批量设置视频分类
// @Description 根据视频ID集合批量更新 video_information 集合 categoryIds 字段,传1个ID表示单条设置,传多个ID表示批量设置;categoryIds 可为空,不传或空数组表示清空分类
// @Accept json
// @Produce json
// @Param param body srv_videoinfo.SetVideoCategoryReq true "单/批量设置视频分类请求"
// @Success 200 {string} string "成功"
// @Failure 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/web/videoinfo/category/set [post]
func SetCategory(ctx *gin.Context) {
var req srv_videoinfo.SetVideoCategoryReq
if err := ctx.ShouldBindJSON(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
return
}
if err := srv_videoinfo.SetVideoCategory(ctx, &req); err != nil {
common.ServerJSON(ctx, err.Code, err.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, "")
}
type TranscodeVideoReq struct {
Id int64 `json:"id" binding:"required"`
}
// @Tags 视频管理
// @Summary 提交视频 H265 转码
// @Router /api/web/videoinfo/transcode [POST]
func TranscodeVideo(ctx *gin.Context) {
var req TranscodeVideoReq
if err := ctx.ShouldBindJSON(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
return
}
if serr := srv_videoinfo.TranscodeVideo(ctx, req.Id); serr != nil {
common.ServerJSON(ctx, serr.Code, serr.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, nil)
}
// SyncSlug web端同步视频相关历史空 slug
// @Tags 视频管理
// @Summary 同步历史空 slug
// @Description 为分类、标签、题材、作者、视频中空的 slug 按 SEO 关键词或名称自动生成。可重复调用,hasMore 为 true 时继续请求。
// @Accept json
// @Produce json
// @Param param body proto.VideoSlugSyncReq false "同步参数"
// @Success 200 {object} proto.VideoSlugSyncResp "成功"
// @Failure 400 {string} string "参数错误"
// @Security ApiKeyAuth
// @Router /api/web/videoinfo/slug/sync [POST]
func SyncSlug(ctx *gin.Context) {
var req proto.VideoSlugSyncReq
if ctx.Request.ContentLength > 0 {
if err := ctx.ShouldBindJSON(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
return
}
}
resp, serr := srv_videoslug.SyncEmptySlugs(ctx, &req)
if serr != nil {
common.ServerJSON(ctx, serr.Code, serr.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}