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 {
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 {