[ci skip] updates on restructuring stuff
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/hacdias/caddy-hugo/config"
|
||||
"github.com/hacdias/caddy-hugo/utils"
|
||||
)
|
||||
|
||||
// DELETE handles the delete requests on browse pages
|
||||
@@ -16,25 +17,26 @@ func DELETE(w http.ResponseWriter, r *http.Request, c *config.Config) (int, erro
|
||||
path = strings.TrimSuffix(path, "/")
|
||||
path = c.Path + path
|
||||
|
||||
message := "File deleted."
|
||||
|
||||
// Check if the file or directory exists
|
||||
if stat, err := os.Stat(path); err == nil {
|
||||
var err error
|
||||
// If it's dir, remove all of the content inside
|
||||
if stat.IsDir() {
|
||||
err = os.RemoveAll(path)
|
||||
message = "Folder deleted."
|
||||
} else {
|
||||
err = os.Remove(path)
|
||||
}
|
||||
|
||||
// Check for errors
|
||||
if err != nil {
|
||||
return 500, err
|
||||
return utils.RespondJSON(w, "Something went wrong.", 500, nil)
|
||||
}
|
||||
} else {
|
||||
return 404, nil
|
||||
return utils.RespondJSON(w, "File not found.", 404, nil)
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Write([]byte("{}"))
|
||||
return 200, nil
|
||||
return utils.RespondJSON(w, message, 200, nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user