sync: 对齐小程序 v1.0.2 生产代码并脱敏

This commit is contained in:
MiFaZhan
2026-10-29 15:15:12 +08:00
parent a7abd476f0
commit 5fcf74deb0
423 changed files with 15001 additions and 6382 deletions
@@ -1,17 +1,17 @@
// Package mcache
// @Link https://github.com/xiujiecn/xiu-admin
// @Copyright Copyright (c) 2025 LiXiujie
// @Author Lxj <li@xiujie.cn>
// @Author Lxj <li@example.com>
// @License https://github.com/xiujiecn/xiu-admin/blob/master/LICENSE
package mcache
import (
"context"
"fmt"
"time"
"git.5iot.com/iotlcm-public/iotlcm-app/internal/consts"
"git.5iot.com/iotlcm-public/iotlcm-app/internal/library/event"
"git.5iot.com/iotlcm-public/iotlcm-app/internal/service"
"time"
"github.com/gogf/gf/v2/frame/g"
)
@@ -28,7 +28,29 @@ func init() {
}
type requestAccessKey struct{}
type requestAccessSnapshot struct {
userId int64
codes []string
scopes []string
}
// WithFreshUserAccess 为小程序请求读取当前权限并保留请求内快照。
// 控制台清理本地缓存不会清理小程序进程内的权限缓存。
func WithFreshUserAccess(ctx context.Context, userId int64) (context.Context, error) {
codes, scopes, err := service.SysAuth().GetUserAccessCodeList(ctx, userId)
if err != nil {
return ctx, err
}
snapshot := requestAccessSnapshot{userId: userId, codes: ensureCurrentUserAccessCode(codes), scopes: scopes}
return context.WithValue(ctx, requestAccessKey{}, snapshot), nil
}
func GetUserAccessCodeList(ctx context.Context, userId int64) ([]string, []string, error) {
if snapshot, ok := ctx.Value(requestAccessKey{}).(requestAccessSnapshot); ok && snapshot.userId == userId {
return snapshot.codes, snapshot.scopes, nil
}
accessCodeList, err := Instance().Get(ctx, fmt.Sprintf(consts.MemCacheUserAccessCodeList, userId))
menuRoleDataAccessCodeList, err := Instance().Get(ctx, fmt.Sprintf(consts.MemCacheUserRoleDataAccessCodeList, userId))
if err != nil || accessCodeList == nil {