structure changes

This commit is contained in:
Henrique Dias
2016-03-06 20:37:49 +00:00
parent 3f36200862
commit 1375038a66
43 changed files with 405 additions and 392 deletions

View File

@@ -6,7 +6,7 @@ import (
"strings"
"github.com/hacdias/caddy-hugo/config"
"github.com/hacdias/caddy-hugo/tools/utils"
"github.com/hacdias/caddy-hugo/tools/server"
)
// DELETE handles the delete requests on browse pages
@@ -32,17 +32,17 @@ func DELETE(w http.ResponseWriter, r *http.Request, c *config.Config) (int, erro
// Check for errors
if err != nil {
return utils.RespondJSON(w, map[string]string{
return server.RespondJSON(w, map[string]string{
"message": "Something went wrong.",
}, 500, nil)
}
} else {
return utils.RespondJSON(w, map[string]string{
return server.RespondJSON(w, map[string]string{
"message": "File not found.",
}, 404, nil)
}
return utils.RespondJSON(w, map[string]string{
return server.RespondJSON(w, map[string]string{
"message": message,
}, 200, nil)
}

View File

@@ -6,6 +6,7 @@ import (
"github.com/hacdias/caddy-hugo/config"
"github.com/hacdias/caddy-hugo/tools/templates"
"github.com/hacdias/caddy-hugo/tools/variables"
"github.com/mholt/caddy/middleware"
"github.com/mholt/caddy/middleware/browse"
)
@@ -15,7 +16,7 @@ import (
func GET(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) {
functions := template.FuncMap{
"CanBeEdited": templates.CanBeEdited,
"Defined": templates.Defined,
"Defined": variables.Defined,
}
tpl, err := templates.Get(r, functions, "browse")

View File

@@ -12,7 +12,7 @@ import (
"github.com/hacdias/caddy-hugo/config"
"github.com/hacdias/caddy-hugo/tools/commands"
"github.com/hacdias/caddy-hugo/tools/utils"
"github.com/hacdias/caddy-hugo/tools/server"
)
// POST handles the POST method on browse page. It's used to create new files,
@@ -37,13 +37,13 @@ func POST(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error)
// Check if filename and archetype are specified in
// the request
if _, ok := info["filename"]; !ok {
return utils.RespondJSON(w, map[string]string{
return server.RespondJSON(w, map[string]string{
"message": "Filename not specified.",
}, 500, nil)
}
if _, ok := info["archetype"]; !ok {
return utils.RespondJSON(w, map[string]string{
return server.RespondJSON(w, map[string]string{
"message": "Archtype not specified.",
}, 500, nil)
}
@@ -67,7 +67,7 @@ func POST(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error)
}
if err := commands.Run(c.Hugo, args, c.Path); err != nil {
return utils.RespondJSON(w, map[string]string{
return server.RespondJSON(w, map[string]string{
"message": "Something went wrong.",
}, 500, err)
}
@@ -84,14 +84,14 @@ func POST(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error)
}
if err != nil {
return utils.RespondJSON(w, map[string]string{
return server.RespondJSON(w, map[string]string{
"message": "Something went wrong.",
}, 500, err)
}
}
return utils.RespondJSON(w, map[string]string{
return server.RespondJSON(w, map[string]string{
"location": url,
"message": "File created.",
}, 200, nil)
@@ -101,7 +101,7 @@ func upload(w http.ResponseWriter, r *http.Request, c *config.Config) (int, erro
// Parse the multipart form in the request
err := r.ParseMultipartForm(100000)
if err != nil {
return utils.RespondJSON(w, map[string]string{
return server.RespondJSON(w, map[string]string{
"message": "Something went wrong.",
}, 500, err)
}
@@ -113,7 +113,7 @@ func upload(w http.ResponseWriter, r *http.Request, c *config.Config) (int, erro
// Open the first file
var infile multipart.File
if infile, err = hdr.Open(); nil != err {
return utils.RespondJSON(w, map[string]string{
return server.RespondJSON(w, map[string]string{
"message": "Something went wrong.",
}, 500, err)
}
@@ -121,14 +121,14 @@ func upload(w http.ResponseWriter, r *http.Request, c *config.Config) (int, erro
// Create the file
var outfile *os.File
if outfile, err = os.Create(c.Path + r.URL.Path + hdr.Filename); nil != err {
return utils.RespondJSON(w, map[string]string{
return server.RespondJSON(w, map[string]string{
"message": "Something went wrong.",
}, 500, err)
}
// Copy the file content
if _, err = io.Copy(outfile, infile); nil != err {
return utils.RespondJSON(w, map[string]string{
return server.RespondJSON(w, map[string]string{
"message": "Something went wrong.",
}, 500, err)
}
@@ -137,5 +137,5 @@ func upload(w http.ResponseWriter, r *http.Request, c *config.Config) (int, erro
}
}
return utils.RespondJSON(w, nil, 200, nil)
return server.RespondJSON(w, nil, 200, nil)
}

View File

@@ -8,7 +8,7 @@ import (
"strings"
"github.com/hacdias/caddy-hugo/config"
"github.com/hacdias/caddy-hugo/tools/utils"
"github.com/hacdias/caddy-hugo/tools/server"
)
// PUT handles the HTTP PUT request for all /admin/browse related requests.
@@ -31,7 +31,7 @@ func PUT(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error)
// Check if filename and archetype are specified in
// the request
if _, ok := info["filename"]; !ok {
return utils.RespondJSON(w, map[string]string{
return server.RespondJSON(w, map[string]string{
"message": "Filename not specified.",
}, 400, nil)
}
@@ -44,12 +44,12 @@ func PUT(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error)
// Renames the file/folder
if err := os.Rename(old, new); err != nil {
return utils.RespondJSON(w, map[string]string{
return server.RespondJSON(w, map[string]string{
"message": "Something went wrong.",
}, 500, err)
}
return utils.RespondJSON(w, map[string]string{
return server.RespondJSON(w, map[string]string{
"message": "File renamed.",
}, 200, nil)
}