chore: build
Backend - Build & Lint / build (push) Successful in 31m59s
Frontend Admin - EAS Build / build (push) Successful in 1h32m56s

This commit is contained in:
Xor290
2026-11-01 13:08:58 +01:00
parent f3eaea4347
commit 0a18460f13
20 changed files with 1694 additions and 190 deletions
+58 -1
View File
@@ -48,6 +48,30 @@ func checkRateLimit(key string) bool {
return true
}
// isRateLimited indique si la clé est actuellement bloquée, sans compter de requête.
func isRateLimited(key string) bool {
rateLimitMu.Lock()
defer rateLimitMu.Unlock()
return countRecent(rateLimitMap[key], timeWindow) >= maxRequests
}
func resetRateLimit(key string) {
rateLimitMu.Lock()
defer rateLimitMu.Unlock()
delete(rateLimitMap, key)
}
func countRecent(timestamps []time.Time, window time.Duration) int {
now := time.Now()
n := 0
for _, ts := range timestamps {
if now.Sub(ts) < window {
n++
}
}
return n
}
func safeGetUsername(c *gin.Context) (string, error) {
username, exists := c.Get("username")
if !exists {
@@ -356,7 +380,7 @@ func UpdateOwnCommandAddress(c *gin.Context) {
return
}
rateLimitKey := fmt.Sprintf("update_own_addr:%s", clientUsername)
rateLimitKey := ownAddressRateLimitKey(clientUsername)
if !checkRateLimit(rateLimitKey) {
c.JSON(http.StatusTooManyRequests, gin.H{"error": "Trop de requêtes, réessayez plus tard"})
return
@@ -746,6 +770,39 @@ func GetAvailableDeliveryPersons(c *gin.Context) {
return
}
// Enrichissement en un seul aller-retour groupé (statut, position, queue,
// compteurs) au lieu de laisser le frontend refaire un appel par livreur.
usernames := make([]string, len(livreurs))
for i, l := range livreurs {
if u, ok := l["username"].(string); ok {
usernames[i] = u
}
}
detailsByUsername := database.GetDeliveryPersonsDetailsBatch(usernames)
for i, l := range livreurs {
username, _ := l["username"].(string)
det := detailsByUsername[username]
if det == nil {
det = &db.DeliveryPersonDetails{Status: "offline"}
}
l["status"] = det.Status
l["queue_size"] = det.QueueSize
l["total_deliveries"] = det.TotalDeliveries
l["completed_deliveries"] = det.CompletedDeliveries
l["pending_deliveries"] = det.PendingDeliveries
if det.CurrentCommand != 0 {
l["current_command"] = det.CurrentCommand
} else {
l["current_command"] = nil
}
if det.HasLocation {
l["location"] = gin.H{"latitude": det.Latitude, "longitude": det.Longitude}
} else {
l["location"] = nil
}
livreurs[i] = l
}
log.Printf("✅ [GET_LIVREURS] Trouvés: %d livreurs disponibles", len(livreurs))
c.JSON(http.StatusOK, gin.H{