chore: build
Frontend Admin - EAS Build / build (push) Canceled after 0s
Frontend Client - EAS Build / build (push) Canceled after 0s
Backend - Build & Lint / build (push) Failing after 25m18s
Frontend Web - Build & Lint / build (push) Failing after 9m58s

This commit is contained in:
Xor290
2026-08-06 12:06:05 +02:00
parent c034088bee
commit 22a8d5026c
174 changed files with 30315 additions and 16120 deletions
+28 -17
View File
@@ -3,25 +3,16 @@ package utils
import (
"crypto/rand"
"fmt"
"gestion/db"
"gestion/models"
"math/big"
"os"
"path/filepath"
"strings"
"unicode"
"golang.org/x/text/runes"
"golang.org/x/text/transform"
"golang.org/x/text/unicode/norm"
)
// --------------------------------------------
// MEDIA
// --------------------------------------------
func GetMediaForProduct(productID int) ([]models.Media, error) {
return db.DB.GetMediaByProductID(productID)
}
// --------------------------------------------
// FILES NAMES
// --------------------------------------------
func GenerateUniqueFileName(productName string, originalFileName string) string {
n, _ := rand.Int(rand.Reader, big.NewInt(1000000))
randomString := fmt.Sprintf("%d", n.Int64())
@@ -29,6 +20,26 @@ func GenerateUniqueFileName(productName string, originalFileName string) string
return fmt.Sprintf("%s_%s%s", productName, randomString, ext)
}
func DeleteOldFile(filePath string) error {
return os.Remove(filePath)
// SanitizeFilePath valide qu'un chemin de fichier local reste bien dans le
// dossier uploads/ et ne contient pas de tentative de path traversal.
func SanitizeFilePath(path string) (string, error) {
cleaned := filepath.Clean(path)
if strings.Contains(cleaned, "..") {
return "", fmt.Errorf("path traversal détecté")
}
if !strings.HasPrefix(cleaned, "uploads/") && !strings.HasPrefix(cleaned, "uploads\\") {
return "", fmt.Errorf("chemin invalide")
}
return cleaned, nil
}
// NormalizeAddress supprime les accents et normalise les espaces, pour
// comparer deux adresses saisies différemment (casse/accents/espaces).
func NormalizeAddress(s string) string {
t := transform.Chain(norm.NFD, runes.Remove(runes.In(unicode.Mn)), norm.NFC)
result, _, _ := transform.String(t, s)
return strings.Join(strings.Fields(result), " ")
}