update: Device Middleware

This commit is contained in:
EUForest 2025-10-14 15:08:59 +08:00
parent f67c2e34dc
commit 571628710b

View File

@ -40,20 +40,18 @@ func DeviceMiddleware(srvCtx *svc.ServiceContext) func(c *gin.Context) {
return return
} }
var loginType string ctx := c.Request.Context()
if c.Value(constant.CtxKeyUser) == nil { if ctx.Value(constant.CtxKeyUser) == nil && c.GetHeader("Login-Type") != "" {
loginType = c.GetHeader("Login-Type") ctx = context.WithValue(ctx, constant.LoginType, c.GetHeader("Login-Type"))
} else { c.Request = c.Request.WithContext(ctx)
loginType = c.GetString(string(constant.LoginType))
} }
if loginType != "device" { loginType, ok := ctx.Value(constant.LoginType).(string)
if !ok || loginType != "device" {
c.Next() c.Next()
return return
} }
c.Request = c.Request.WithContext(context.WithValue(c.Request.Context(), constant.LoginType, loginType))
rw := NewResponseWriter(c, srvCtx) rw := NewResponseWriter(c, srvCtx)
if !rw.Decrypt() { if !rw.Decrypt() {
result.HttpResult(c, nil, errors.Wrapf(xerr.NewErrCode(xerr.InvalidCiphertext), "Invalid ciphertext")) result.HttpResult(c, nil, errors.Wrapf(xerr.NewErrCode(xerr.InvalidCiphertext), "Invalid ciphertext"))