Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Throttle discord alerts

Neeraj Guptacf4084380cc6
diff --git a/server/pkg/controller/discord/discord.go b/server/pkg/controller/discord/discord.go
index 94876c8149..91a9b7ce7e 100644
--- a/server/pkg/controller/discord/discord.go
+++ b/server/pkg/controller/discord/discord.go
@@ -2,6 +2,7 @@ package discord
import (
"fmt"
+ "sync"
"time"
"github.com/bwmarrin/discordgo"
@@ -19,6 +20,8 @@ type DiscordController struct {
HostName string
Environment string
UserRepo *repo.UserRepository
+ lastSent map[string]time.Time
+ mu sync.Mutex
}
func NewDiscordController(userRepo *repo.UserRepository, hostName string, environment string) *DiscordController {
@@ -28,6 +31,7 @@ func NewDiscordController(userRepo *repo.UserRepository, hostName string, enviro
HostName: hostName,
Environment: environment,
UserRepo: userRepo,
+ lastSent: make(map[string]time.Time),
}
}
@@ -106,6 +110,14 @@ func (c *DiscordController) NotifyAccountDelete(userID int64, paymentProvider st
}
func (c *DiscordController) NotifyPotentialAbuse(message string) {
+ c.mu.Lock()
+ defer c.mu.Unlock()
+ now := time.Now()
+ if lastTime, exists := c.lastSent[message]; exists && now.Sub(lastTime) < time.Minute {
+ log.Infof("Skipping duplicate abuse notification: %s", message)
+ return
+ }
+ c.lastSent[message] = now
c.Notify(fmt.Sprintf("%s: %s", c.HostName, message))
}
diff --git a/server/pkg/middleware/rate_limit.go b/server/pkg/middleware/rate_limit.go
index 747cb9a867..48a94bd847 100644
--- a/server/pkg/middleware/rate_limit.go
+++ b/server/pkg/middleware/rate_limit.go
@@ -147,6 +147,8 @@ func (r *RateLimitMiddleware) APIRateLimitForUserMiddleware(urlSanitizer func(_
func (r *RateLimitMiddleware) getLimiter(reqPath string, reqMethod string) *limiter.Limiter {
if reqPath == "/users/ott" ||
reqPath == "/users/verify-email" ||
+ reqPath == "/user/change-email" ||
+ reqPath == "/users/public-key" ||
reqPath == "/public-collection/verify-password" ||
reqPath == "/family/accept-invite" ||
reqPath == "/users/srp/attributes" ||