fix: issues
This commit is contained in:
@@ -15,6 +15,7 @@ type ListFilter struct {
|
||||
|
||||
type ListItem struct {
|
||||
ID int64 `json:"-"`
|
||||
Poster string `json:"poster"`
|
||||
Hash string `json:"hash"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
|
||||
@@ -83,6 +83,7 @@ func (svc *Service) GetMediaByID(ctx context.Context, tenantId, userId, id int64
|
||||
func (svc *Service) ModelToListItem(ctx context.Context, m *model.Medias) *ListItem {
|
||||
return &ListItem{
|
||||
ID: m.ID,
|
||||
Poster: fmt.Sprintf("/static/%s/poster.jpg", m.Hash),
|
||||
Hash: m.Hash,
|
||||
Title: m.Title,
|
||||
Description: m.Description,
|
||||
@@ -96,7 +97,7 @@ func (svc *Service) ModelToListItem(ctx context.Context, m *model.Medias) *ListI
|
||||
}
|
||||
|
||||
// List
|
||||
func (svc *Service) List(ctx context.Context, tenantId, userId int64, filter *ListFilter) ([]ListItem, error) {
|
||||
func (svc *Service) List(ctx context.Context, tenantId, userId int64, filter *ListFilter) ([]*ListItem, error) {
|
||||
log := svc.log.WithField("method", "List")
|
||||
|
||||
boughtIDs, err := svc.GetUserBoughtMedias(ctx, tenantId, userId)
|
||||
@@ -144,21 +145,8 @@ func (svc *Service) List(ctx context.Context, tenantId, userId int64, filter *Li
|
||||
return nil, errors.Wrap(err, "query medias")
|
||||
}
|
||||
|
||||
items := lo.Map(dest, func(m model.Medias, _ int) ListItem {
|
||||
item := ListItem{
|
||||
ID: m.ID,
|
||||
Hash: m.Hash,
|
||||
Title: m.Title,
|
||||
Description: m.Description,
|
||||
Duration: m.Duration,
|
||||
Price: m.Price,
|
||||
Discount: m.Discount,
|
||||
Resources: m.Resources,
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
Bought: lo.Contains(boughtIDs, m.ID),
|
||||
}
|
||||
return item
|
||||
items := lo.Map(dest, func(m model.Medias, _ int) *ListItem {
|
||||
return svc.ModelToListItem(ctx, &m)
|
||||
})
|
||||
|
||||
return items, nil
|
||||
|
||||
@@ -14,12 +14,15 @@ import (
|
||||
)
|
||||
|
||||
func (f *Middlewares) WeChatAuthUserInfo(c fiber.Ctx) error {
|
||||
log.WithField("module", "middleware.WeChatAuthUserInfo").Debug("Begin")
|
||||
defer log.WithField("module", "middleware.WeChatAuthUserInfo").Debug("END")
|
||||
|
||||
// 如果请求存在 Authorization 头,则跳过
|
||||
if len(c.GetReqHeaders()["Authorization"]) != 0 {
|
||||
return c.Next()
|
||||
}
|
||||
|
||||
log.WithField("module", "middleware.AuthUserInfo").Debugf("query: %v", c.Queries())
|
||||
log.WithField("module", "middleware.AuthUserInfo").Debugf("%s, query: %v", c.OriginalURL(), c.Queries())
|
||||
state := c.Query("state")
|
||||
code := c.Query("code")
|
||||
|
||||
|
||||
@@ -11,6 +11,9 @@ import (
|
||||
)
|
||||
|
||||
func (f *Middlewares) WeChatSilentAuth(c fiber.Ctx) error {
|
||||
log.WithField("module", "middleware.WeChatSilentAuth").Debug("Begin")
|
||||
defer log.WithField("module", "middleware.WeChatSilentAuth").Debug("END")
|
||||
|
||||
// if cookie not exists key "openid", then redirect to the wechat auth page
|
||||
token := c.GetReqHeaders()["Authorization"]
|
||||
if len(token) != 0 {
|
||||
@@ -24,7 +27,7 @@ func (f *Middlewares) WeChatSilentAuth(c fiber.Ctx) error {
|
||||
url = strings.ReplaceAll(url, c.BaseURL(), *f.app.BaseURI)
|
||||
}
|
||||
|
||||
log.WithField("module", "middleware.SilentAuth").Debug("url:", url)
|
||||
log.WithField("module", "middleware.SilentAuth").Debug("redirect_uri: ", url)
|
||||
|
||||
to, err := f.client.ScopeAuthorizeURL(
|
||||
wechat.ScopeAuthorizeURLWithRedirectURI(url),
|
||||
|
||||
@@ -7,6 +7,9 @@ import (
|
||||
|
||||
// 此方法用于微信首次接入时的数据验证
|
||||
func (f *Middlewares) WeChatVerify(c fiber.Ctx) error {
|
||||
log.WithField("module", "middleware.WeChatVerify").Debug("Begin")
|
||||
defer log.WithField("module", "middleware.WeChatVerify").Debug("END")
|
||||
|
||||
// get the query parameters
|
||||
signature := c.Query("signature")
|
||||
timestamp := c.Query("timestamp")
|
||||
|
||||
@@ -2,9 +2,12 @@ package middlewares
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v3"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func (f *Middlewares) DebugMode(c fiber.Ctx) error {
|
||||
log.WithField("module", "middleware.DebugMode").Debug("Begin")
|
||||
defer log.WithField("module", "middleware.DebugMode").Debug("END")
|
||||
// fullURI := c.Request().URI().FullURI()
|
||||
// host := c.BaseURL()
|
||||
// fmt.Println(strings.Split(c.Path(), "/"))
|
||||
|
||||
@@ -8,6 +8,9 @@ import (
|
||||
)
|
||||
|
||||
func (f *Middlewares) ProcessResponse(c fiber.Ctx) error {
|
||||
log.WithField("module", "middleware.ProcessResponse").Debug("Begin")
|
||||
defer log.WithField("module", "middleware.ProcessResponse").Debug("END")
|
||||
|
||||
if err := c.Next(); err != nil {
|
||||
log.WithError(err).Error("process response error")
|
||||
|
||||
@@ -26,5 +29,5 @@ func (f *Middlewares) ProcessResponse(c fiber.Ctx) error {
|
||||
return errorx.Wrap(err).Response(c)
|
||||
|
||||
}
|
||||
return c.Next()
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user