simplify some stuff
This commit is contained in:
@@ -7,18 +7,17 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/hacdias/caddy-hugo/config"
|
||||
"github.com/hacdias/caddy-hugo/tools/server"
|
||||
)
|
||||
|
||||
// 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, c *config.Config) (int, error) {
|
||||
func PUT(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||
// Remove both beginning and trailing slashes
|
||||
old := r.URL.Path
|
||||
old = strings.TrimPrefix(old, "/")
|
||||
old = strings.TrimSuffix(old, "/")
|
||||
old = c.Path + old
|
||||
old = conf.Path + old
|
||||
|
||||
// Get the JSON information sent using a buffer
|
||||
buffer := new(bytes.Buffer)
|
||||
@@ -40,7 +39,7 @@ func PUT(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error)
|
||||
new := info["filename"].(string)
|
||||
new = strings.TrimPrefix(new, "/")
|
||||
new = strings.TrimSuffix(new, "/")
|
||||
new = c.Path + new
|
||||
new = conf.Path + new
|
||||
|
||||
// Renames the file/folder
|
||||
if err := os.Rename(old, new); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user