close #71; fix bugs
This commit is contained in:
@@ -21,13 +21,13 @@ type response struct {
|
||||
func ServeHTTP(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) {
|
||||
conf = c
|
||||
// Removes the page main path from the URL
|
||||
r.URL.Path = strings.Replace(r.URL.Path, "/admin/browse", "", 1)
|
||||
r.URL.Path = strings.Replace(r.URL.Path, c.Admin+"/browse", "", 1)
|
||||
|
||||
switch r.Method {
|
||||
case "DELETE":
|
||||
return DELETE(w, r)
|
||||
case "POST":
|
||||
return POST(w, r)
|
||||
return POST(w, r, c)
|
||||
case "GET":
|
||||
return GET(w, r)
|
||||
case "PUT":
|
||||
|
||||
@@ -10,13 +10,14 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/hacdias/caddy-hugo/config"
|
||||
"github.com/hacdias/caddy-hugo/tools/commands"
|
||||
s "github.com/hacdias/caddy-hugo/tools/server"
|
||||
)
|
||||
|
||||
// POST handles the POST method on browse page. It's used to create new files,
|
||||
// folders and upload content.
|
||||
func POST(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||
func POST(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) {
|
||||
// Remove prefix slash
|
||||
r.URL.Path = strings.TrimPrefix(r.URL.Path, "/")
|
||||
|
||||
@@ -47,7 +48,7 @@ func POST(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||
filename := info["filename"].(string)
|
||||
filename = strings.TrimPrefix(filename, "/")
|
||||
filename = strings.TrimSuffix(filename, "/")
|
||||
url := "/admin/edit/" + r.URL.Path + filename
|
||||
url := c.Admin + "/edit/" + r.URL.Path + filename
|
||||
filename = conf.Path + r.URL.Path + filename
|
||||
|
||||
if strings.HasPrefix(filename, conf.Path+"content/") &&
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"github.com/hacdias/caddy-hugo/tools/server"
|
||||
)
|
||||
|
||||
// PUT handles the HTTP PUT request for all /admin/browse related requests.
|
||||
// PUT handles the HTTP PUT request for all /{admin}/browse related requests.
|
||||
// Renames a file and/or a folder.
|
||||
func PUT(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||
// Remove both beginning and trailing slashes
|
||||
|
||||
Reference in New Issue
Block a user