fix: issues

This commit is contained in:
yanghao05
2025-04-25 21:19:03 +08:00
parent b35abb2090
commit 5bc3ae468d
15 changed files with 129 additions and 64 deletions

View File

@@ -7,23 +7,21 @@ import (
"quyun/app/models"
"github.com/gofiber/fiber/v3"
"github.com/gofiber/fiber/v3/log"
log "github.com/sirupsen/logrus"
)
func (f *Middlewares) Auth(ctx fiber.Ctx) error {
if strings.HasPrefix(ctx.Path(), "/MP_verify_") {
return ctx.Next()
}
if strings.HasPrefix(ctx.Path(), "/auth/") {
if strings.HasPrefix(ctx.Path(), "/v1/auth/") {
return ctx.Next()
}
uu, err := models.Users.GetByID(ctx.Context(), 1)
if err != nil {
log.WithError(err).Error("failed to get user")
return ctx.SendString("NOT OK")
}
ctx.Locals("user", uu)
log.Infof("set ctx user: %d", uu.ID)
return ctx.Next()
fullUrl := string(ctx.Request().URI().FullURI())

View File

@@ -1,10 +1,16 @@
package middlewares
import (
"strings"
"github.com/gofiber/fiber/v3"
)
func (f *Middlewares) AuthAdmin(ctx fiber.Ctx) error {
if !strings.HasPrefix(ctx.Path(), "/v1/admin") {
return ctx.Next()
}
if ctx.Path() == "/v1/admin/auth" {
return ctx.Next()
}

View File

@@ -6,9 +6,12 @@ import (
)
func (f *Middlewares) DebugMode(ctx fiber.Ctx) error {
log.Info("------------------")
log.Infof("c.Path: %s", ctx.Path())
log.Infof("Request Method: %s", ctx.Method())
log.Infof("FullURL: %s", ctx.Request().URI().FullURI())
log.Infof("StartPATH: %s", ctx.Params("*"))
log.Info("------------------")
return ctx.Next()
}

View File

@@ -0,0 +1,19 @@
package middlewares
import (
"strings"
"github.com/gofiber/fiber/v3"
)
func (f *Middlewares) WechatMpVerify(ctx fiber.Ctx) error {
if !strings.HasPrefix(ctx.Path(), "/MP_verify_") {
return ctx.Next()
}
path := strings.Replace(ctx.Path(), "MP_verify_", "", 1)
path = strings.Replace(path, ".txt", "", 1)
path = strings.Trim(path, "/")
return ctx.SendString(path)
}