progresses on #23
This commit is contained in:
@@ -15,9 +15,9 @@ func ServeHTTP(w http.ResponseWriter, r *http.Request, c *config.Config) (int, e
|
||||
|
||||
switch r.Method {
|
||||
case "DELETE":
|
||||
return DELETE(w, r)
|
||||
return DELETE(w, r, c)
|
||||
case "POST":
|
||||
return POST(w, r)
|
||||
return POST(w, r, c)
|
||||
case "GET":
|
||||
return GET(w, r, c)
|
||||
default:
|
||||
|
||||
@@ -4,22 +4,26 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/hacdias/caddy-cms/config"
|
||||
)
|
||||
|
||||
// DELETE handles the DELETE method on browse page
|
||||
func DELETE(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||
func DELETE(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) {
|
||||
// Remove both beginning and trailing slashes
|
||||
r.URL.Path = strings.TrimPrefix(r.URL.Path, "/")
|
||||
r.URL.Path = strings.TrimSuffix(r.URL.Path, "/")
|
||||
path := r.URL.Path
|
||||
path = strings.TrimPrefix(path, "/")
|
||||
path = strings.TrimSuffix(path, "/")
|
||||
path = c.Path + path
|
||||
|
||||
// Check if the file or directory exists
|
||||
if stat, err := os.Stat(r.URL.Path); err == nil {
|
||||
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(r.URL.Path)
|
||||
err = os.RemoveAll(path)
|
||||
} else {
|
||||
err = os.Remove(r.URL.Path)
|
||||
err = os.Remove(path)
|
||||
}
|
||||
|
||||
// Check for errors
|
||||
|
||||
@@ -27,7 +27,7 @@ func GET(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error)
|
||||
Next: middleware.HandlerFunc(func(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||
return 404, nil
|
||||
}),
|
||||
Root: "./",
|
||||
Root: c.Path,
|
||||
Configs: []browse.Config{
|
||||
{
|
||||
PathScope: "/",
|
||||
|
||||
@@ -10,11 +10,12 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/hacdias/caddy-cms/config"
|
||||
"github.com/hacdias/caddy-cms/utils"
|
||||
)
|
||||
|
||||
// POST handles the POST method on browse page
|
||||
func POST(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||
func POST(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) {
|
||||
// Remove both beginning slashes
|
||||
r.URL.Path = strings.TrimPrefix(r.URL.Path, "/")
|
||||
|
||||
@@ -45,7 +46,7 @@ func POST(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||
filename := info["filename"].(string)
|
||||
filename = strings.TrimPrefix(filename, "/")
|
||||
filename = strings.TrimSuffix(filename, "/")
|
||||
filename = r.URL.Path + filename
|
||||
filename = c.Path + r.URL.Path + filename
|
||||
|
||||
// Check if the archetype is defined
|
||||
if info["archetype"] != "" {
|
||||
|
||||
Reference in New Issue
Block a user