GET req with Accept JSON header now returns JSON File Info
Former-commit-id: 49499ad674d707034438bf85b749908ceb37fe12
This commit is contained in:
@@ -2,6 +2,7 @@ package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/hacdias/caddy-filemanager/config"
|
||||
"github.com/hacdias/caddy-filemanager/file"
|
||||
@@ -18,12 +19,6 @@ func ServeSingle(w http.ResponseWriter, r *http.Request, c *config.Config, u *co
|
||||
return errors.ErrorToHTTPCode(err, true), err
|
||||
}
|
||||
|
||||
if i.Type == "text" {
|
||||
if err = i.Read(); err != nil {
|
||||
return errors.ErrorToHTTPCode(err, true), err
|
||||
}
|
||||
}
|
||||
|
||||
p := &page.Page{
|
||||
Info: &page.Info{
|
||||
Name: i.Name,
|
||||
@@ -35,6 +30,17 @@ func ServeSingle(w http.ResponseWriter, r *http.Request, c *config.Config, u *co
|
||||
},
|
||||
}
|
||||
|
||||
// If the request accepts JSON, we send the file information.
|
||||
if strings.Contains(r.Header.Get("Accept"), "application/json") {
|
||||
return p.PrintAsJSON(w)
|
||||
}
|
||||
|
||||
if i.Type == "text" {
|
||||
if err = i.Read(); err != nil {
|
||||
return errors.ErrorToHTTPCode(err, true), err
|
||||
}
|
||||
}
|
||||
|
||||
if i.CanBeEdited() && u.AllowEdit {
|
||||
p.Data, err = GetEditor(r, i)
|
||||
p.Editor = true
|
||||
|
||||
Reference in New Issue
Block a user