This commit is contained in:
julien 2025-06-19 16:41:41 +02:00
parent 1a9e755b11
commit 662d7b7fcb

View File

@ -183,24 +183,26 @@ func DeleteSavePath(db *gorm.DB) http.HandlerFunc {
} }
} }
func IsPathValid(subPath string) error { func IsPathValid(pathName string) error {
if subPath == "" { if pathName == "" {
return errors.New("path is empty") return errors.New("PathName cannot be empty")
} }
fullPath := "/app/upload/" + subPath if strings.Contains(pathName, "/") || strings.Contains(pathName, "\\") {
info, err := os.Stat(fullPath) return errors.New("PathName cannot contain '/' or '\\'")
if os.IsNotExist(err) {
return errors.New("path does not exist")
} }
if err != nil {
return errors.New("unable to access path: " + err.Error()) fullPath := "/app/upload/" + pathName
}
if !info.IsDir() { if _, err := os.Stat(fullPath); err == nil {
return errors.New("path is not a directory") return errors.New("Path already exists")
} }
// os.Stat() retourne une erreur si le dossier n'existe pas, on ignore cette erreur ici
return nil return nil
} }
// PathValidationHandler handles HTTP requests to validate a path // PathValidationHandler handles HTTP requests to validate a path
func PathValidationHandler(w http.ResponseWriter, r *http.Request) { func PathValidationHandler(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost { if r.Method != http.MethodPost {