chore: update

This commit is contained in:
2026-03-17 09:18:23 +01:00
parent 008aeab231
commit af74b39b22
10 changed files with 149 additions and 103 deletions
+23 -4
View File
@@ -735,7 +735,25 @@ func GetClientCommandsHistory(c *gin.Context) {
"count": len(commands),
}
if err == nil && client != nil { // ✅ VÉRIFIE AUSSI que client != nil
if err == nil && client != nil {
// Récupérer les pools configurés par l'admin
poolNames := []string{}
poolKeys := []string{}
if settings, sErr := database.GetSettings(); sErr == nil && len(settings.PointsPools) > 0 {
for _, p := range settings.PointsPools {
poolNames = append(poolNames, p.Name)
poolKeys = append(poolKeys, p.Key)
}
}
// Construire pool_points depuis points_extra[pool.Key] (stockage dynamique)
poolPoints := make([]int, len(poolKeys))
for i, key := range poolKeys {
if key != "" {
poolPoints[i] = client.PointsExtra[key]
}
}
resp["client_stats"] = gin.H{
"username": client.Username,
"nom": client.Nom,
@@ -743,12 +761,13 @@ func GetClientCommandsHistory(c *gin.Context) {
"telephone": client.Telephone,
"total_commands": client.Command,
"points": client.Point,
"points_zipette": client.PointZipette,
"pool_points": poolPoints,
"pool_names": poolNames,
"penalties": client.Amende,
}
log.Printf(" [HISTORY] Stats client: point=%d, point_zipette=%d",
client.Point, client.PointZipette)
log.Printf("📊 [HISTORY] pool_names=%v pool_keys=%v pool_points=%v extra=%v",
poolNames, poolKeys, poolPoints, client.PointsExtra)
} else {
log.Printf("⚠️ [HISTORY] client_stats NON ajouté - err=%v, client=%v", err, client)
}
+13 -8
View File
@@ -50,12 +50,15 @@ func GetMyCompletedOrders(c *gin.Context) {
// ✅ Récupérer les infos client pour statistiques
client, err := database.GetClientByUsername(usernameStr)
// ✅ Récupérer les noms des pools de points
// ✅ Récupérer les noms et clés des pools de points
poolNames := []string{"Pool 1", "Pool 2"}
var poolKeys []string
if settings, sErr := database.GetSettings(); sErr == nil && len(settings.PointsPools) > 0 {
poolNames = make([]string, len(settings.PointsPools))
poolKeys = make([]string, len(settings.PointsPools))
for i, p := range settings.PointsPools {
poolNames[i] = p.Name
poolKeys[i] = p.Key
}
}
@@ -66,15 +69,17 @@ func GetMyCompletedOrders(c *gin.Context) {
}
if err == nil && client != nil {
// Construire le tableau générique des valeurs par pool
poolPoints := make([]int, len(poolNames))
if len(poolPoints) > 0 {
poolPoints[0] = client.Point
}
if len(poolPoints) > 1 {
poolPoints[1] = client.PointZipette
// Construire le tableau depuis points_extra[poolKey] pour tous les pools (stockage dynamique)
poolPoints := make([]int, len(poolKeys))
for i, key := range poolKeys {
if key != "" {
poolPoints[i] = client.PointsExtra[key]
}
}
log.Printf("📊 [HISTORY] pool_names=%v pool_keys=%v pool_points=%v extra=%v",
poolNames, poolKeys, poolPoints, client.PointsExtra)
response["client_stats"] = gin.H{
"username": client.Username,
"total_commands": client.Command,
+6 -14
View File
@@ -814,29 +814,21 @@ func UploadMedia(c *gin.Context) {
}
// ✅ VÉRIFIER LE TYPE MIME RÉEL
fileHeader, err := file.Open()
detectedMime, err := validateFileMimeType(file)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "Erreur lecture fichier"})
return
}
defer fileHeader.Close()
buffer := make([]byte, 512)
_, err = fileHeader.Read(buffer)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "Erreur lecture fichier"})
log.Printf("❌ [UploadMedia] Type MIME invalide: %v", err)
c.JSON(http.StatusBadRequest, gin.H{"error": "Type de fichier non autorisé"})
return
}
mimeType := http.DetectContentType(buffer)
log.Printf("📋 [UploadMedia] Type MIME détecté: %s", mimeType)
log.Printf("📋 [UploadMedia] Type MIME détecté: %s", detectedMime)
// Vérifier que le MIME correspond au type déclaré
if fileType == "image" && !strings.HasPrefix(mimeType, "image/") {
if fileType == "image" && !strings.HasPrefix(detectedMime, "image/") {
c.JSON(http.StatusBadRequest, gin.H{"error": "Le fichier n'est pas une image valide"})
return
}
if fileType == "video" && !strings.HasPrefix(mimeType, "video/") {
if fileType == "video" && !strings.HasPrefix(detectedMime, "video/") {
c.JSON(http.StatusBadRequest, gin.H{"error": "Le fichier n'est pas une vidéo valide"})
return
}