up
This commit is contained in:
parent
1a9e755b11
commit
662d7b7fcb
@ -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 {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user