This repository has been archived on 2026-06-21. You can view files and clone it, but cannot push or open issues or pull requests.
Files
MetaLab/internal/middleware/ratelimit_cleanup.go
Victor_Jay 7bc2dbd970 refactor: 拆分 middleware/router 为单一职责文件,新增站点设置管理页面
middleware:
- 拆分 auth.go → auth.go + auth_token.go + auth_parser.go + auth_admin.go
- 拆分 csrf.go → csrf.go + csrf_token.go
- 拆分 ratelimit.go → ratelimit.go + ratelimit_core.go + ratelimit_cleanup.go
- 修复 import 未使用/缺失问题

router:
- 拆分 router.go → admin.go + api.go + frontend.go + deps_core.go + deps_extra.go

feat(admin): 站点设置管理页面
- 新增 SSR 页面 /admin/site-settings(仅 Owner)
- 审核开关 Toggle 即时保存
- 通用设置展示
- 侧边栏新增站点设置入口
- 注册 UpdateBoolSetting/GetBoolSetting API 路由
2026-05-27 15:03:04 +08:00

33 lines
746 B
Go

package middleware
import "time"
// Clear 登录成功后清除该 email 和 IP 的失败计数
func (rl *RateLimiter) Clear(email, ip string) {
rl.mu.Lock()
defer rl.mu.Unlock()
delete(rl.accountFailures, email)
delete(rl.ipFailures, ip)
}
// cleanupLoop 定期清理过期条目
func (rl *RateLimiter) cleanupLoop() {
ticker := time.NewTicker(cleanupInterval)
defer ticker.Stop()
for range ticker.C {
rl.mu.Lock()
now := time.Now()
clean := func(m map[string]*windowState) {
for k, v := range m {
if (v.blockedUntil.IsZero() || now.After(v.blockedUntil)) &&
now.Sub(v.windowStart) > accountWindow+ipBlockDur {
delete(m, k)
}
}
}
clean(rl.accountFailures)
clean(rl.ipFailures)
rl.mu.Unlock()
}
}