Merge pull request 'feature-pay_picture-wxy-20241216' (#922) from feature-pay_picture-wxy-20241216 into main
Reviewed-on: https://git.wishpal.cn/wishpal_ironfan/service/pulls/922
This commit is contained in:
commit
500f98b43b
|
@ -79,6 +79,11 @@ const (
|
||||||
Deleted = 1 //已删除
|
Deleted = 1 //已删除
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
PermanentMember = 1 // 会员
|
||||||
|
NoPermanentMember = 0 // 非会员
|
||||||
|
)
|
||||||
|
|
||||||
// 默认login初始化配置
|
// 默认login初始化配置
|
||||||
const (
|
const (
|
||||||
OriginalLoginMid = -1
|
OriginalLoginMid = -1
|
||||||
|
@ -99,6 +104,16 @@ const (
|
||||||
RedisMomentPrefix = "moment:" //moment服务前缀
|
RedisMomentPrefix = "moment:" //moment服务前缀
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
ImageTiff = "image_tiff"
|
||||||
|
ImageWebp = "image/webp"
|
||||||
|
ImageHeic = "image/heic"
|
||||||
|
ImageJpeg = "image/jpeg"
|
||||||
|
ImageGif = "image/gif"
|
||||||
|
ImagePng = "image/png"
|
||||||
|
VideoMp4 = "video/mp4"
|
||||||
|
)
|
||||||
|
|
||||||
//const PackageRootPath = "C:/Users/PC/Desktop/service"
|
//const PackageRootPath = "C:/Users/PC/Desktop/service"
|
||||||
|
|
||||||
const PackageRootPath = "/app/wishpal-ironfan"
|
const PackageRootPath = "/app/wishpal-ironfan"
|
||||||
|
|
|
@ -261,6 +261,9 @@ var ErrCodeMsgMap = map[ErrCode]string{
|
||||||
|
|
||||||
ErrCodeRavenIQTestVisitSrvFail: "瑞文智商测试访问表服务错误",
|
ErrCodeRavenIQTestVisitSrvFail: "瑞文智商测试访问表服务错误",
|
||||||
ErrCodeRavenIQTestVisitNotExist: "瑞文智商测试访问表不存在",
|
ErrCodeRavenIQTestVisitNotExist: "瑞文智商测试访问表不存在",
|
||||||
|
|
||||||
|
ErrCodeImageOriginalVipView: "会员可查看原图",
|
||||||
|
ErrCodeImageAlreadyOriginal: "当前已经是原图",
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -633,4 +636,9 @@ const (
|
||||||
ErrCodeRavenIQTestVisitSrvOk ErrCode = ErrCodeOk
|
ErrCodeRavenIQTestVisitSrvOk ErrCode = ErrCodeOk
|
||||||
ErrCodeRavenIQTestVisitSrvFail ErrCode = -102001 // 瑞文智商测试访问表服务错误
|
ErrCodeRavenIQTestVisitSrvFail ErrCode = -102001 // 瑞文智商测试访问表服务错误
|
||||||
ErrCodeRavenIQTestVisitNotExist ErrCode = -102002 // 瑞文智商测试访问表不存在
|
ErrCodeRavenIQTestVisitNotExist ErrCode = -102002 // 瑞文智商测试访问表不存在
|
||||||
|
|
||||||
|
// Image
|
||||||
|
ErrCodeImageOriginalVipView ErrCode = -103001 // 会员可查看原图
|
||||||
|
ErrCodeImageAlreadyOriginal ErrCode = -103002 // 已经是原图
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
package proto
|
||||||
|
|
||||||
|
import (
|
||||||
|
"service/api/base"
|
||||||
|
"service/dbstruct"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ApiOriginalImageReq struct {
|
||||||
|
base.BaseRequest
|
||||||
|
ImageId int64 `json:"image_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ApiOriginalImageData struct {
|
||||||
|
*dbstruct.ToCImage
|
||||||
|
}
|
||||||
|
|
||||||
|
type ApiOriginalImageResp struct {
|
||||||
|
base.BaseResponse
|
||||||
|
Data *ApiOriginalImageData `json:"data"`
|
||||||
|
}
|
|
@ -1 +1,34 @@
|
||||||
package controller
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"service/api/errcode"
|
||||||
|
previewsproto "service/api/proto/previews/proto"
|
||||||
|
"service/app/mix/service"
|
||||||
|
"service/bizcommon/util"
|
||||||
|
"service/library/logger"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ApiGetOriginalImage(ctx *gin.Context) {
|
||||||
|
req := ctx.MustGet("client_req").(*previewsproto.ApiOriginalImageReq)
|
||||||
|
if req.ImageId <= 0 {
|
||||||
|
logger.Error(" ApiGetOriginalImage, invalid param, req: %v", util.ToJson(req))
|
||||||
|
ReplyErrCodeMsg(ctx, errcode.ErrCodeBadParam)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err, ec := service.DefaultService.ApiGetOriginalImage(ctx, req)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("image ApiGetOriginalImage ApiGetOriginalImage err, req: %v", util.ToJson(req))
|
||||||
|
ReplyErrCodeMsg(ctx, ec)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if ec == errcode.ErrCodeImageOriginalVipView {
|
||||||
|
logger.Info("ApiGetOriginalImage user is not vip, req: %v", util.ToJson(req))
|
||||||
|
ReplyErrCodeMsg(ctx, errcode.ErrCodeImageOriginalVipView)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ReplyOk(ctx, data)
|
||||||
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@ import (
|
||||||
loginproto "service/api/proto/login/proto"
|
loginproto "service/api/proto/login/proto"
|
||||||
momentproto "service/api/proto/moment/proto"
|
momentproto "service/api/proto/moment/proto"
|
||||||
moment_audit_taskproto "service/api/proto/moment_audit_task/proto"
|
moment_audit_taskproto "service/api/proto/moment_audit_task/proto"
|
||||||
|
imageproto "service/api/proto/previews/proto"
|
||||||
productproto "service/api/proto/product/proto"
|
productproto "service/api/proto/product/proto"
|
||||||
realname_authenticationproto "service/api/proto/realname_authentication/proto"
|
realname_authenticationproto "service/api/proto/realname_authentication/proto"
|
||||||
streamerproto "service/api/proto/streamer/proto"
|
streamerproto "service/api/proto/streamer/proto"
|
||||||
|
@ -318,6 +319,9 @@ func Init(r *gin.Engine) {
|
||||||
apiConfigGroup := r.Group("/api/config", PrepareToC())
|
apiConfigGroup := r.Group("/api/config", PrepareToC())
|
||||||
apiConfigGroup.POST("cold_config", middleware.JSONParamValidator(base.BaseRequest{}), ColdConfigHandler)
|
apiConfigGroup.POST("cold_config", middleware.JSONParamValidator(base.BaseRequest{}), ColdConfigHandler)
|
||||||
|
|
||||||
|
apiPreviewsGroup := r.Group("/api/previews", PrepareToC())
|
||||||
|
apiPreviewsGroup.POST("original_image", middleware.JSONParamValidator(imageproto.ApiOriginalImageReq{}), middleware.JwtAuthenticator(), ApiGetOriginalImage)
|
||||||
|
|
||||||
// =============================== 以下是服务,只允许内网调用 ===============================
|
// =============================== 以下是服务,只允许内网调用 ===============================
|
||||||
|
|
||||||
// op相关,直接调用服务,不调用gateway
|
// op相关,直接调用服务,不调用gateway
|
||||||
|
|
|
@ -59,6 +59,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
Raven_IQ_testproto "service/api/proto/Raven_IQ_test/proto"
|
Raven_IQ_testproto "service/api/proto/Raven_IQ_test/proto"
|
||||||
|
previewsproto "service/api/proto/previews/proto"
|
||||||
|
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
goproto "google.golang.org/protobuf/proto"
|
goproto "google.golang.org/protobuf/proto"
|
||||||
|
@ -4462,3 +4463,49 @@ func (s *Service) ApiGetRavenIQTestVisitCount(ctx *gin.Context, req *Raven_IQ_te
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Service) ApiGetOriginalImage(ctx *gin.Context, req *previewsproto.ApiOriginalImageReq) (*previewsproto.ApiOriginalImageData, error, errcode.ErrCode) {
|
||||||
|
ec := errcode.ErrCodeMediaSrvOk
|
||||||
|
// 获取用户付费状态
|
||||||
|
account, err := _DefaultAccount.OpListByMid(ctx, &accountproto.OpListByMidReq{
|
||||||
|
Mid: &req.Mid,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
ec = errcode.ErrCodeImageAlreadyOriginal
|
||||||
|
logger.Error("ApiGetOriginalImage failed : %v", err)
|
||||||
|
return nil, err, ec
|
||||||
|
}
|
||||||
|
|
||||||
|
// 会员可以查看原图
|
||||||
|
if account.GetIsAMember() != consts.PermanentMember {
|
||||||
|
ec = errcode.ErrCodeImageOriginalVipView
|
||||||
|
return nil, nil, ec
|
||||||
|
}
|
||||||
|
|
||||||
|
ids := make([]int64, 0)
|
||||||
|
ids = append(ids, req.ImageId)
|
||||||
|
|
||||||
|
// 获取图片
|
||||||
|
list, err := _DefaultMedia.GetImageByIds(ctx, ids)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("ApiGetOriginalImage GetImageByIds fail, req: %v, err: %v", util.ToJson(req), err)
|
||||||
|
ec = errcode.ErrCodeMediaSrvFail
|
||||||
|
return nil, err, ec
|
||||||
|
}
|
||||||
|
if len(list) == 0 {
|
||||||
|
ec = errcode.ErrCodeImageAlreadyOriginal
|
||||||
|
logger.Error("ApiGetOriginalImage list len is 0, req: %v", util.ToJson(req))
|
||||||
|
return nil, nil, ec
|
||||||
|
}
|
||||||
|
|
||||||
|
images := make([]*dbstruct.ToCImage, 0)
|
||||||
|
for _, image := range list {
|
||||||
|
images = append(images, _DefaultImage.TransToCImage(image, account.GetIsAMember()))
|
||||||
|
}
|
||||||
|
|
||||||
|
data := &previewsproto.ApiOriginalImageData{
|
||||||
|
ToCImage: images[0],
|
||||||
|
}
|
||||||
|
|
||||||
|
return data, err, ec
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"service/api/consts"
|
||||||
|
"service/app/mix/dao"
|
||||||
|
"service/dbstruct"
|
||||||
|
_ "service/library/logger"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Image struct {
|
||||||
|
store *dao.Store
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *Image) TransToCImage(image *dbstruct.Image, isAMember int64) *dbstruct.ToCImage {
|
||||||
|
if image == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 选择内存最小的图片
|
||||||
|
imgSrcId := image.SelectMinSizeOssId()
|
||||||
|
|
||||||
|
// 会员可以查看原图
|
||||||
|
if isAMember == consts.PermanentMember && (image.Fmt == consts.ImageWebp || image.Fmt == consts.ImageJpeg || image.Fmt == consts.ImagePng) {
|
||||||
|
imgSrcId = image.SrcId
|
||||||
|
}
|
||||||
|
|
||||||
|
return &dbstruct.ToCImage{
|
||||||
|
Id: image.Id,
|
||||||
|
W: image.W,
|
||||||
|
H: image.H,
|
||||||
|
Fmt: image.Fmt,
|
||||||
|
Urls: []string{v.getFileServerDomain() + imgSrcId},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *Image) getFileServerDomain() string {
|
||||||
|
return "https://levianderwinv01.tiefen.space/"
|
||||||
|
}
|
|
@ -155,6 +155,7 @@ var (
|
||||||
_DefaultRavenIQTest *logic.RavenIQTest
|
_DefaultRavenIQTest *logic.RavenIQTest
|
||||||
_DefaultRavenIQTestVisit *logic.RavenIQTestVisit
|
_DefaultRavenIQTestVisit *logic.RavenIQTestVisit
|
||||||
_DefaultVeriCodeWrongTimes *logic.VeriCodeWrongTimes
|
_DefaultVeriCodeWrongTimes *logic.VeriCodeWrongTimes
|
||||||
|
_DefaultImage *logic.Image
|
||||||
|
|
||||||
_DefaultStreamerDecrtByEs *logic.StreamerDecrtByEs
|
_DefaultStreamerDecrtByEs *logic.StreamerDecrtByEs
|
||||||
_DefaultZoneDecrtByEs *logic.ZoneDecrtByEs
|
_DefaultZoneDecrtByEs *logic.ZoneDecrtByEs
|
||||||
|
|
|
@ -88,6 +88,13 @@ func (p *Account) GetRole() int64 {
|
||||||
return *p.Role
|
return *p.Role
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Account) GetIsAMember() int64 {
|
||||||
|
if p == nil || p.IsAMember == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return *p.IsAMember
|
||||||
|
}
|
||||||
|
|
||||||
// StreamerAcct 用户结构
|
// StreamerAcct 用户结构
|
||||||
type StreamerAcct struct {
|
type StreamerAcct struct {
|
||||||
Mid *int64 `json:"mid" bson:"_id"` // 用户表Id
|
Mid *int64 `json:"mid" bson:"_id"` // 用户表Id
|
||||||
|
|
|
@ -20,7 +20,9 @@ func init() {
|
||||||
rand.Seed(time.Now().Unix())
|
rand.Seed(time.Now().Unix())
|
||||||
}
|
}
|
||||||
|
|
||||||
var defaultMediaFiller *MediaFiller
|
var (
|
||||||
|
defaultMediaFiller *MediaFiller
|
||||||
|
)
|
||||||
|
|
||||||
type GetImageByIdsFunc func(ctx *gin.Context, ids []int64) ([]*dbstruct.Image, error)
|
type GetImageByIdsFunc func(ctx *gin.Context, ids []int64) ([]*dbstruct.Image, error)
|
||||||
type GetVideoByIdsFunc func(ctx *gin.Context, ids []int64) ([]*dbstruct.Video, error)
|
type GetVideoByIdsFunc func(ctx *gin.Context, ids []int64) ([]*dbstruct.Video, error)
|
||||||
|
|
Loading…
Reference in New Issue