mirror of
https://github.com/filebrowser/filebrowser.git
synced 2024-06-07 23:00:43 +00:00
GET req with Accept JSON header now returns JSON File Info
Former-commit-id: 49499ad674
This commit is contained in:
parent
70924d4f13
commit
1f6f759d70
@ -113,6 +113,8 @@ func (i Info) CanBeEdited() bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the type isn't text (and is blob for example), it will check some
|
||||||
|
// common types that are mistaken not to be text.
|
||||||
extensions := [...]string{
|
extensions := [...]string{
|
||||||
".md", ".markdown", ".mdown", ".mmark",
|
".md", ".markdown", ".mdown", ".mmark",
|
||||||
".asciidoc", ".adoc", ".ad",
|
".asciidoc", ".adoc", ".ad",
|
||||||
|
@ -2,6 +2,7 @@ package handlers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/hacdias/caddy-filemanager/config"
|
"github.com/hacdias/caddy-filemanager/config"
|
||||||
"github.com/hacdias/caddy-filemanager/file"
|
"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
|
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{
|
p := &page.Page{
|
||||||
Info: &page.Info{
|
Info: &page.Info{
|
||||||
Name: i.Name,
|
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 {
|
if i.CanBeEdited() && u.AllowEdit {
|
||||||
p.Data, err = GetEditor(r, i)
|
p.Data, err = GetEditor(r, i)
|
||||||
p.Editor = true
|
p.Editor = true
|
||||||
|
Loading…
Reference in New Issue
Block a user