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 {