From 662d7b7fcb1f5e5a632aca971cf22810d37e3ade Mon Sep 17 00:00:00 2001 From: julien Date: Thu, 19 Jun 2025 16:41:41 +0200 Subject: [PATCH] up --- internal/download/download.go | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/internal/download/download.go b/internal/download/download.go index 543a590..54666aa 100644 --- a/internal/download/download.go +++ b/internal/download/download.go @@ -183,24 +183,26 @@ func DeleteSavePath(db *gorm.DB) http.HandlerFunc { } } -func IsPathValid(subPath string) error { - if subPath == "" { - return errors.New("path is empty") +func IsPathValid(pathName string) error { + if pathName == "" { + return errors.New("PathName cannot be empty") } - fullPath := "/app/upload/" + subPath - info, err := os.Stat(fullPath) - if os.IsNotExist(err) { - return errors.New("path does not exist") + if strings.Contains(pathName, "/") || strings.Contains(pathName, "\\") { + return errors.New("PathName cannot contain '/' or '\\'") } - if err != nil { - return errors.New("unable to access path: " + err.Error()) - } - if !info.IsDir() { - return errors.New("path is not a directory") + + fullPath := "/app/upload/" + pathName + + if _, err := os.Stat(fullPath); err == nil { + return errors.New("Path already exists") } + + // os.Stat() retourne une erreur si le dossier n'existe pas, on ignore cette erreur ici + return nil } + // PathValidationHandler handles HTTP requests to validate a path func PathValidationHandler(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodPost {