fix: issues
This commit is contained in:
BIN
backend/__debug_bin457628671
Executable file
BIN
backend/__debug_bin457628671
Executable file
Binary file not shown.
@@ -27,7 +27,7 @@ DevMode = true
|
||||
|
||||
[JWT]
|
||||
ExpiresTime = "168h"
|
||||
SignKey = "LiXi.Y@140202"
|
||||
SigningKey = "LiXi.Y@140202"
|
||||
|
||||
[HashIDs]
|
||||
Salt = "LiXi.Y@140202"
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -15,6 +15,9 @@ import (
|
||||
"git.ipao.vip/rogeecn/atom"
|
||||
"git.ipao.vip/rogeecn/atom/container"
|
||||
"git.ipao.vip/rogeecn/atom/contracts"
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"github.com/gofiber/fiber/v3/middleware/favicon"
|
||||
"github.com/gofiber/fiber/v3/middleware/static"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"go.uber.org/dig"
|
||||
@@ -50,6 +53,7 @@ type Http struct {
|
||||
dig.In
|
||||
|
||||
App *app.Config
|
||||
Storage *storage.Config
|
||||
Service *http.Service
|
||||
Initials []contracts.Initial `group:"initials"`
|
||||
Routes []contracts.HttpRoute `group:"routes"`
|
||||
@@ -61,16 +65,31 @@ func Serve(cmd *cobra.Command, args []string) error {
|
||||
if http.App.Mode == app.AppModeDevelopment {
|
||||
log.SetLevel(log.DebugLevel)
|
||||
}
|
||||
|
||||
engine := http.Service.Engine
|
||||
mid := http.Middlewares
|
||||
http.Service.Engine.Use(mid.DebugMode)
|
||||
http.Service.Engine.Use(mid.ProcessResponse)
|
||||
http.Service.Engine.Use(mid.WeChatVerify)
|
||||
http.Service.Engine.Use(mid.WeChatAuthUserInfo)
|
||||
http.Service.Engine.Use(mid.WeChatSilentAuth)
|
||||
http.Service.Engine.Use(mid.ParseJWT)
|
||||
|
||||
engine.Use(mid.DebugMode)
|
||||
engine.Use(mid.ProcessResponse)
|
||||
|
||||
wechatGroup := engine.Group("/t")
|
||||
wechatGroup.Use(mid.WeChatVerify)
|
||||
wechatGroup.Use(mid.WeChatAuthUserInfo)
|
||||
wechatGroup.Use(mid.WeChatSilentAuth)
|
||||
wechatGroup.Get("*", func(c fiber.Ctx) error {
|
||||
return c.SendString("ok")
|
||||
})
|
||||
|
||||
http.Service.Engine.Use(favicon.New(favicon.Config{
|
||||
Data: []byte{},
|
||||
}))
|
||||
|
||||
http.Service.Engine.Use("/static", static.New(http.Storage.Path, static.Config{
|
||||
Browse: true,
|
||||
}))
|
||||
|
||||
group := http.Service.Engine.Group("/v1")
|
||||
group.Use(mid.ParseJWT)
|
||||
|
||||
for _, route := range http.Routes {
|
||||
route.Register(group)
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"backend/modules/medias"
|
||||
"backend/modules/users"
|
||||
"backend/providers/app"
|
||||
"backend/providers/hashids"
|
||||
"backend/providers/postgres"
|
||||
"backend/providers/storage"
|
||||
|
||||
@@ -21,6 +22,7 @@ func defaultProviders(providers ...container.ProviderContainer) container.Provid
|
||||
app.DefaultProvider(),
|
||||
storage.DefaultProvider(),
|
||||
postgres.DefaultProvider(),
|
||||
hashids.DefaultProvider(),
|
||||
}, providers...)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@Token=Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJvcGVuX2lkIjoib01MYTV0eUoydlJIYS1ISTRDTUVrSHp0cTNlVSIsInRlbmFudCI6InlwbCIsInVzZXJfaWQiOjEsInRlbmFudF9pZCI6MSwiZXhwIjoxNzM0MzQ5NDA3LCJuYmYiOjE3MzM3NDQ1OTd9.iQtyxfFDXht4mpCYSllv7opFjYuUHO22WwBl7hAzQYw
|
||||
@Token=Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJvcGVuX2lkIjoib01MYTV0eUoydlJIYS1ISTRDTUVrSHp0cTNlVSIsInRlbmFudCI6InlwbCIsInVzZXJfaWQiOjEsInRlbmFudF9pZCI6MiwiZXhwIjoxNzM0NDkxNzkwLCJuYmYiOjE3MzM4ODY5ODB9.qwG-Z3bkh1RD7wYVH7DTLRTdjHYrCW0aSnghhNlmOzo
|
||||
@host=http://localhost:9600
|
||||
|
||||
### Get Medias
|
||||
|
||||
Reference in New Issue
Block a user