fix: issues

This commit is contained in:
Rogee
2024-12-13 20:12:57 +08:00
parent 8a48f202f2
commit 13ebc91220
11 changed files with 109 additions and 37 deletions

Binary file not shown.

View File

@@ -36,3 +36,4 @@ Salt = "LiXi.Y@140202"
Type = "local" Type = "local"
# Path = "/projects/mp-qvyun/backend/fixtures/processed" # Path = "/projects/mp-qvyun/backend/fixtures/processed"
Path = "/mnt/yangpingliang/publish/processed" Path = "/mnt/yangpingliang/publish/processed"
Asset = "/projects/mp-qvyun/frontend/dist"

View File

@@ -1,6 +1,9 @@
package middlewares package middlewares
import ( import (
_ "embed"
"os"
"path/filepath"
"strings" "strings"
"backend/pkg/pg" "backend/pkg/pg"
@@ -14,9 +17,6 @@ import (
) )
func (f *Middlewares) WeChatAuthUserInfo(c fiber.Ctx) error { func (f *Middlewares) WeChatAuthUserInfo(c fiber.Ctx) error {
log.WithField("module", "middleware.WeChatAuthUserInfo").Debug("Begin")
defer log.WithField("module", "middleware.WeChatAuthUserInfo").Debug("END")
// 如果请求存在 Authorization 头,则跳过 // 如果请求存在 Authorization 头,则跳过
if len(c.GetReqHeaders()["Authorization"]) != 0 { if len(c.GetReqHeaders()["Authorization"]) != 0 {
return c.Next() return c.Next()
@@ -81,6 +81,13 @@ func (f *Middlewares) WeChatAuthUserInfo(c fiber.Ctx) error {
return errors.Wrap(err, "failed to create token") return errors.Wrap(err, "failed to create token")
} }
// TODO: send html with jwt token b, err := os.ReadFile(filepath.Join(f.storagePath.Asset, "index.html"))
return c.SendString(jwtToken) if err != nil {
return errors.Wrap(err, "failed to read file")
}
html := strings.ReplaceAll(string(b), "{{JWT}}", jwtToken)
c.Set("Content-Type", "text/html")
return c.SendString(html)
} }

View File

@@ -11,9 +11,6 @@ import (
) )
func (f *Middlewares) WeChatSilentAuth(c fiber.Ctx) error { 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 // if cookie not exists key "openid", then redirect to the wechat auth page
token := c.GetReqHeaders()["Authorization"] token := c.GetReqHeaders()["Authorization"]
if len(token) != 0 { if len(token) != 0 {

View File

@@ -7,9 +7,6 @@ import (
// 此方法用于微信首次接入时的数据验证 // 此方法用于微信首次接入时的数据验证
func (f *Middlewares) WeChatVerify(c fiber.Ctx) error { 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 // get the query parameters
signature := c.Query("signature") signature := c.Query("signature")
timestamp := c.Query("timestamp") timestamp := c.Query("timestamp")

View File

@@ -2,12 +2,9 @@ package middlewares
import ( import (
"github.com/gofiber/fiber/v3" "github.com/gofiber/fiber/v3"
log "github.com/sirupsen/logrus"
) )
func (f *Middlewares) DebugMode(c fiber.Ctx) error { 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() // fullURI := c.Request().URI().FullURI()
// host := c.BaseURL() // host := c.BaseURL()
// fmt.Println(strings.Split(c.Path(), "/")) // fmt.Println(strings.Split(c.Path(), "/"))

View File

@@ -8,9 +8,6 @@ import (
) )
func (f *Middlewares) ProcessResponse(c fiber.Ctx) error { func (f *Middlewares) ProcessResponse(c fiber.Ctx) error {
log.WithField("module", "middleware.ProcessResponse").Debug("Begin")
defer log.WithField("module", "middleware.ProcessResponse").Debug("END")
err := c.Next() err := c.Next()
if err != nil { if err != nil {
log.WithError(err).Error("process response error") log.WithError(err).Error("process response error")

View File

@@ -4,6 +4,7 @@ import (
"backend/modules/users" "backend/modules/users"
"backend/providers/app" "backend/providers/app"
"backend/providers/jwt" "backend/providers/jwt"
"backend/providers/storage"
"backend/providers/wechat" "backend/providers/wechat"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
@@ -11,11 +12,12 @@ import (
// @provider // @provider
type Middlewares struct { type Middlewares struct {
app *app.Config app *app.Config
client *wechat.Client storagePath *storage.Config
userSvc *users.Service client *wechat.Client
jwt *jwt.JWT userSvc *users.Service
log *log.Entry `inject:"false"` jwt *jwt.JWT
log *log.Entry `inject:"false"`
} }
func (f *Middlewares) Prepare() error { func (f *Middlewares) Prepare() error {

View File

@@ -1,6 +1,8 @@
package http package http
import ( import (
"path/filepath"
"backend/modules/medias" "backend/modules/medias"
"backend/modules/middlewares" "backend/modules/middlewares"
"backend/modules/users" "backend/modules/users"
@@ -15,7 +17,6 @@ import (
"git.ipao.vip/rogeecn/atom" "git.ipao.vip/rogeecn/atom"
"git.ipao.vip/rogeecn/atom/container" "git.ipao.vip/rogeecn/atom/container"
"git.ipao.vip/rogeecn/atom/contracts" "git.ipao.vip/rogeecn/atom/contracts"
"github.com/gofiber/fiber/v3"
"github.com/gofiber/fiber/v3/middleware/favicon" "github.com/gofiber/fiber/v3/middleware/favicon"
"github.com/gofiber/fiber/v3/middleware/static" "github.com/gofiber/fiber/v3/middleware/static"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
@@ -70,21 +71,19 @@ func Serve(cmd *cobra.Command, args []string) error {
engine.Use(mid.DebugMode) engine.Use(mid.DebugMode)
engine.Use(mid.ProcessResponse) engine.Use(mid.ProcessResponse)
engine.Use(mid.WeChatVerify)
wechatGroup := engine.Group("/t") engine.Use("/t+", mid.WeChatAuthUserInfo, mid.WeChatSilentAuth)
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{ http.Service.Engine.Use(favicon.New(favicon.Config{
Data: []byte{}, Data: []byte{},
})) }))
http.Service.Engine.Use("/static", static.New(http.Storage.Path, static.Config{ http.Service.Engine.Use("/static", static.New(http.Storage.Path, static.Config{
Browse: true, Browse: http.App.IsDevMode(),
}))
http.Service.Engine.Use("/assets", static.New(filepath.Join(http.Storage.Asset, "assets"), static.Config{
Browse: http.App.IsDevMode(),
})) }))
group := http.Service.Engine.Group("/v1") group := http.Service.Engine.Group("/v1")

View File

@@ -3,17 +3,90 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<link rel="icon" href="/favicon.ico"> <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>加载中...</title> <title>加载中...</title>
<script> <script>
var __GA = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJvcGVuX2lkIjoib01MYTV0eUoydlJIYS1ISTRDTUVrSHp0cTNlVSIsInRlbmFudCI6InlwbCIsInVzZXJfaWQiOjEsInRlbmFudF9pZCI6MiwiZXhwIjoxNzM0NTAzMDQzLCJuYmYiOjE3MzM4OTgyMzN9.wl4c-4DdZ-qC7MJHMD8rP2zPiTwBK7J_YKw2im3ve9U" var __GA = "{{JWT}}"
</script> </script>
<style>
* {
padding: 0;
margin: 0;
}
#loading {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
background-color: #f5f5f5;
}
.ball {
width: 240px;
height: 90px;
text-align: center;
margin: 20px auto;
}
.ball>p {
padding: 20px 0;
}
.ball>div {
width: 18px;
height: 18px;
background: #1abc9c;
border-radius: 100%;
display: inline-block;
animation: move 1.4s infinite ease-in-out both;
}
.ball .ball1 {
animation-delay: 0.16s;
}
.ball .ball2 {
animation-delay: 0.32s;
}
.ball .ball3 {
animation-delay: 0.48s;
}
@keyframes move {
0% {
transform: scale(0)
}
40% {
transform: scale(1.0)
}
100% {
transform: scale(0)
}
}
</style>
</head> </head>
<body> <body>
<div id="loading">
<div class="cont">
<div class="ball">
<p>页面正在加载,请稍后~</p>
<div class="ball1"></div>
<div class="ball2"></div>
<div class="ball3"></div>
</div>
</div>
</div>
<div id="app"></div> <div id="app"></div>
<script type="module" src="/src/main.js"></script> <script type="module" src="/src/main.js"></script>
</body> </body>
</html>

View File

@@ -10,4 +10,6 @@ const app = createApp(App)
app.use(createPinia()) app.use(createPinia())
app.use(router) app.use(router)
// remove loading
document.getElementById("loading").remove()
app.mount('#app') app.mount('#app')