From 5aab80fcdd28edb64fb64e0ef399bd12941c029c Mon Sep 17 00:00:00 2001 From: lwl0608 Date: Tue, 7 May 2024 10:50:40 +0800 Subject: [PATCH] add media op --- api/proto/media/proto/proto.go | 31 +++++++++++++++++++++++++++++- app/mix/controller/init.go | 10 ++++------ app/mix/controller/media.go | 27 ++++++++++++++++++++++++++ app/mix/dao/mongo.go | 28 +++++++++++++++++++++++++++ app/mix/service/logic/media.go | 16 +++++++++++++++ app/mix/service/service.go | 22 +++++++++++++++++++++ dbstruct/media.go | 14 ++++++++++++++ library/mediafiller/mediafiller.go | 2 +- 8 files changed, 142 insertions(+), 8 deletions(-) diff --git a/api/proto/media/proto/proto.go b/api/proto/media/proto/proto.go index d6236282..9eccf513 100644 --- a/api/proto/media/proto/proto.go +++ b/api/proto/media/proto/proto.go @@ -1,6 +1,9 @@ package proto -import "service/api/base" +import ( + "service/api/base" + "service/dbstruct" +) const ( MediaTypeImg = 1 // 图片 @@ -75,3 +78,29 @@ type VideoListResp struct { base.BaseResponse Data *VideoListData `json:"data"` } + +// op +type OpGetVideosByStatusReq struct { + Ids []int64 `json:"ids"` + Status int `json:"status"` + Offset int `json:"offset"` + Limit int `json:"limit"` +} + +type OpGetVideosByStatusData struct { + List []*dbstruct.Video `json:"video"` +} + +// 更新压缩后的视频 +type OpUpdateVideoCompressReq struct { + Id int64 `json:"id"` + SizeSrc int64 `json:"size_src"` // 原视频大小 + SrcId720 string `json:"src_id_720"` // 720P视频 + Size720 int64 `json:"size_720"` // 720P视频大小 + SrcIdH264 string `json:"src_id_h264"` // 原视频h264 mp4 + SizeH264 int64 `json:"size_h264"` // 原视频h264 mp4大小 + Status int `json:"status"` // 状态 + ResizeT int64 `json:"resize_t"` // 压缩时间 +} + +type OpUpdateVideoCompressData struct{} diff --git a/app/mix/controller/init.go b/app/mix/controller/init.go index d8212b73..d8e69e82 100644 --- a/app/mix/controller/init.go +++ b/app/mix/controller/init.go @@ -454,6 +454,10 @@ func Init(r *gin.Engine) { mediaGroup.POST("auth", middleware.JSONParamValidator(mediaproto.MediaAuthReq{}), middleware.JwtAuthenticator(), MediaAuth) mediaGroup.POST("c_upload", middleware.JSONParamValidator(mediaproto.CUploadReq{}), middleware.JwtAuthenticator(), CUpload) + opMediaGroup := r.Group("/op/media", PrepareToC()) + opMediaGroup.POST("get_videos_by_status", middleware.JSONParamValidator(mediaproto.OpGetVideosByStatusReq{}), OpGetVideosByStatus) + opMediaGroup.POST("update_video_compress", middleware.JSONParamValidator(mediaproto.OpUpdateVideoCompressReq{}), OpUpdateVideoCompress) + // 主播标签 opStreamerTagGroup := r.Group("/op/streamer_tag", PrepareOp()) opStreamerTagGroup.POST("list", middleware.JSONParamValidator(base.BaseRequest{}), middleware.JwtAuthenticator(), OpGetStreamerTagList) @@ -514,12 +518,6 @@ func Init(r *gin.Engine) { // 视频审核callback extVideoModerationGroup := r.Group("/ext/video_moderation") extVideoModerationGroup.POST("callback", middleware.FORMParamValidator(video_moderation_proto.ExtVideoModerationReq{}), VideoModerationCallback) - - // 账号相关 - //accountGroup := r.Group("/account") - - // =============================== 以上是服务,只允许内网调用 =============================== - } func ServeFile(ctx *gin.Context) { diff --git a/app/mix/controller/media.go b/app/mix/controller/media.go index ec6e487b..08d054bc 100644 --- a/app/mix/controller/media.go +++ b/app/mix/controller/media.go @@ -41,3 +41,30 @@ func CUpload(ctx *gin.Context) { } ReplyOk(ctx, data) } + +// 获取待压缩的视频 +func OpGetVideosByStatus(ctx *gin.Context) { + req := ctx.MustGet("client_req").(*mediaproto.OpGetVideosByStatusReq) + list, ec := service.DefaultService.GetVideosByStatus(ctx, req) + if ec != errcode.ErrCodeMediaSrvOk { + logger.Error("GetVideosByStatus fail, req: %v, ec: %v", util.ToJson(req), ec) + ReplyErrCodeMsg(ctx, ec) + return + } + + data := &mediaproto.OpGetVideosByStatusData{ + List: list, + } + ReplyOk(ctx, data) +} + +func OpUpdateVideoCompress(ctx *gin.Context) { + req := ctx.MustGet("client_req").(*mediaproto.OpUpdateVideoCompressReq) + ec := service.DefaultService.OpUpdateVideoCompress(ctx, req) + if ec != errcode.ErrCodeMediaSrvOk { + logger.Error("OpUpdateVideoCompress fail, req: %v, ec: %v", util.ToJson(req), ec) + ReplyErrCodeMsg(ctx, ec) + return + } + ReplyOk(ctx, nil) +} diff --git a/app/mix/dao/mongo.go b/app/mix/dao/mongo.go index 82e8575f..607dae7c 100644 --- a/app/mix/dao/mongo.go +++ b/app/mix/dao/mongo.go @@ -5,6 +5,7 @@ import ( "service/api/consts" bannerproto "service/api/proto/banner/proto" catalogproto "service/api/proto/catalog/proto" + mediaproto "service/api/proto/media/proto" "service/bizcommon/common" "service/bizcommon/util" "strconv" @@ -933,6 +934,33 @@ func (m *Mongo) GetVideoByIds(ctx *gin.Context, ids []int64) ([]*dbstruct.Video, return list, nil } +func (m *Mongo) GetVideoByStatus(ctx *gin.Context, status, offset, limit int) ([]*dbstruct.Video, error) { + list := make([]*dbstruct.Video, 0) + col := m.getColVideo() + err := col.Find(ctx, qmgo.M{"status": status}).Skip(int64(offset)).Limit(int64(limit)).All(&list) + if err != nil { + return nil, err + } + return list, nil +} + +func (m *Mongo) UpdateVideoCompress(ctx *gin.Context, req *mediaproto.OpUpdateVideoCompressReq) error { + col := m.getColVideo() + set := qmgo.M{ + "size_src": req.SizeSrc, + "src_id_720": req.SrcId720, + "size_720": req.Size720, + "src_id_h264": req.SrcIdH264, + "size_h264": req.SizeH264, + "status": req.Status, + "resize_t": req.ResizeT, + } + up := qmgo.M{ + "$set": set, + } + return col.UpdateId(ctx, req.Id, up) +} + // 登录表 func (m *Mongo) CreateLogin(ctx *gin.Context, login *dbstruct.Login) error { col := m.getColLogin() diff --git a/app/mix/service/logic/media.go b/app/mix/service/logic/media.go index f499c6d4..8ee32a96 100644 --- a/app/mix/service/logic/media.go +++ b/app/mix/service/logic/media.go @@ -259,3 +259,19 @@ func (m *Media) GetVideoByIds(ctx *gin.Context, ids []int64) ([]*dbstruct.Video, } return list, nil } + +func (m *Media) OpGetVideosByStatus(ctx *gin.Context, req *mediaproto.OpGetVideosByStatusReq) ([]*dbstruct.Video, error) { + if len(req.Ids) > 0 { + return m.store.GetVideoByIds(ctx, req.Ids) + } + list, err := m.store.GetVideoByStatus(ctx, req.Status, req.Offset, req.Limit) + if err != nil { + logger.Error("GetVideoByStatus fail, req: %v, err: %v", util.ToJson(req), err) + return make([]*dbstruct.Video, 0), err + } + return list, nil +} + +func (m *Media) OpUpdateVideoCompress(ctx *gin.Context, req *mediaproto.OpUpdateVideoCompressReq) error { + return m.store.UpdateVideoCompress(ctx, req) +} diff --git a/app/mix/service/service.go b/app/mix/service/service.go index 353ade4c..6d974ba4 100644 --- a/app/mix/service/service.go +++ b/app/mix/service/service.go @@ -2466,6 +2466,28 @@ func (s *Service) GetVideoByIds(ctx *gin.Context, req *mediaproto.VideoListReq) return } +func (s *Service) GetVideosByStatus(ctx *gin.Context, req *mediaproto.OpGetVideosByStatusReq) (list []*dbstruct.Video, ec errcode.ErrCode) { + ec = errcode.ErrCodeMediaSrvOk + list, err := _DefaultMedia.OpGetVideosByStatus(ctx, req) + if err != nil { + logger.Error("OpGetVideosByStatus fail, req: %v, err: %v", util.ToJson(req), err) + ec = errcode.ErrCodeMediaSrvFail + return + } + return +} + +func (s *Service) OpUpdateVideoCompress(ctx *gin.Context, req *mediaproto.OpUpdateVideoCompressReq) (ec errcode.ErrCode) { + ec = errcode.ErrCodeMediaSrvOk + err := _DefaultMedia.OpUpdateVideoCompress(ctx, req) + if err != nil { + logger.Error("OpUpdateVideoCompress fail, req: %v, err: %v", util.ToJson(req), err) + ec = errcode.ErrCodeMediaSrvFail + return + } + return +} + func (s *Service) OpGetPlatformListByIds(ctx *gin.Context, ids []int64) (list []*apollostruct.PlatformCfg, ec errcode.ErrCode) { ec = errcode.ErrCodeOk diff --git a/dbstruct/media.go b/dbstruct/media.go index bea94a1a..e278a9b0 100644 --- a/dbstruct/media.go +++ b/dbstruct/media.go @@ -12,6 +12,13 @@ const ( ImageStatusResizeFail = 101 ) +// 视频 +const ( + VideoStatusResizeInit = 0 + VideoStatusResizeDone = 100 + VideoStatusResizeFail = 101 +) + type Image struct { Id int64 `json:"id" bson:"_id"` // 图片id Ct int64 `json:"ct" bson:"ct"` // 创建时间 @@ -56,6 +63,13 @@ type Video struct { Ct int64 `json:"ct" bson:"ct"` // 创建时间 Ut int64 `json:"ut" bson:"ut"` // 更新时间 SrcId string `json:"src_id" bson:"src_id"` // 源id + SizeSrc int64 `json:"size_src" bson:"size_src"` // 原视频大小 + SrcId720 string `json:"src_id_720" bson:"src_id_720"` // 720P视频 + Size720 int64 `json:"size_720" bson:"size_720"` // 720P视频大小 + SrcIdH264 string `json:"src_id_h264" bson:"src_id_h264"` // 原视频h264 mp4 + SizeH264 int64 `json:"size_h264" bson:"size_h264"` // 原视频h264 mp4大小 + Status int `json:"status" bson:"status"` // 状态 + ResizeT int64 `json:"resize_t" bson:"resize_t"` // 压缩时间 CoverSrcId string `json:"cover_src_id" bson:"cover_src_id"` // cover srcId CoverId int64 `json:"cover_id" bson:"cover_id"` // 封面id MD5 string `json:"md5" bson:"md5"` // 视频md5 diff --git a/library/mediafiller/mediafiller.go b/library/mediafiller/mediafiller.go index ab17fd8d..47879865 100644 --- a/library/mediafiller/mediafiller.go +++ b/library/mediafiller/mediafiller.go @@ -41,7 +41,7 @@ func SetFileServerDomainName(fileServerDomainName string) { } func (p *MediaFiller) GetFileServerDomain() string { - if rand.Intn(100) < 5 { + if rand.Intn(100) < 30 { return "https://filecdnhw01.tiefen.fun/" } return "https://filecdn01.tiefen.fun/"