This commit is contained in:
tamakyi
2026-10-19 02:25:19 +08:00
parent 4592b6ef24
commit 12a37e726f
14 changed files with 315 additions and 5 deletions
+13
View File
@@ -27,6 +27,8 @@ const (
abuseAlertThreshold24h = 8
abuseAlertThreshold7d = 20
abuseAlertCooldown = 24 * time.Hour
// abuseAlertCooldownMaxEntries 冷却表的清理阈值(超过即回收已过期的条目)。
abuseAlertCooldownMaxEntries = 1024
)
// abuseAlertCooldowns 每个箱主上次发送阈值告警的时间。
@@ -46,6 +48,17 @@ func allowAbuseAlert(userID uint) bool {
return false
}
abuseAlertCooldowns[userID] = time.Now()
// 惰性清理:条目数超过阈值时删掉已经过冷却窗口的历史项。
// 没有这一步这个 map 只增不减(每个箱主一个时间戳,量不大但没有任何回收路径)。
if len(abuseAlertCooldowns) > abuseAlertCooldownMaxEntries {
now := time.Now()
for id, last := range abuseAlertCooldowns {
if now.Sub(last) >= abuseAlertCooldown {
delete(abuseAlertCooldowns, id)
}
}
}
return true
}
+3
View File
@@ -17,6 +17,7 @@ import (
"github.com/tamakyi/TamaBox/internal/context"
"github.com/tamakyi/TamaBox/internal/db"
"github.com/tamakyi/TamaBox/internal/dbutil"
"github.com/tamakyi/TamaBox/internal/i18n"
)
type conversationDetail struct {
@@ -370,6 +371,8 @@ func QuestionList(ctx context.Context) {
logrus.WithContext(ctx.Request().Context()).WithError(rErr).Error("Failed to query active restriction")
} else if level != "" {
ctx.Data["RestrictionLevel"] = string(level)
// 条幅里给「人话」而不是裸 L2:箱主看不懂级别代号,只会以为被打了个莫名其妙的标记。
ctx.Data["RestrictionLevelName"] = i18n.T(ctx.Lang(), "restriction.level."+string(level))
if active != nil {
ctx.Data["RestrictionExpiresAt"] = active.ExpiresAt.Format("2006-01-02")
}