mirror of
https://github.com/filebrowser/filebrowser.git
synced 2024-06-07 23:00:43 +00:00
updates
This commit is contained in:
parent
a3a4c8cb5e
commit
eef006d629
27
edit/edit.go
Normal file
27
edit/edit.go
Normal file
@ -0,0 +1,27 @@
|
||||
package edit
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Page struct {
|
||||
}
|
||||
|
||||
// Execute sth
|
||||
func Execute(w http.ResponseWriter, r *http.Request, file string) (int, error) {
|
||||
if r.Method == "POST" {
|
||||
// it's saving the post
|
||||
} else {
|
||||
// check if the file exists
|
||||
if _, err := os.Stat(file); os.IsNotExist(err) {
|
||||
return 404, nil
|
||||
}
|
||||
|
||||
file, _ := ioutil.ReadFile(file)
|
||||
w.Write([]byte(string(file)))
|
||||
}
|
||||
|
||||
return 200, nil
|
||||
}
|
18
hugo.go
18
hugo.go
@ -2,12 +2,13 @@ package hugo
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/hugo/commands"
|
||||
|
||||
"github.com/mholt/caddy/config/setup"
|
||||
"github.com/mholt/caddy/middleware"
|
||||
|
||||
"github.com/hacdias/caddy-hugo/routing"
|
||||
)
|
||||
|
||||
// Setup function
|
||||
@ -23,20 +24,7 @@ type handler struct{ Next middleware.Handler }
|
||||
|
||||
func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||
if middleware.Path(r.URL.Path).Matches("/admin") {
|
||||
|
||||
if middleware.Path(r.URL.Path).Matches("/admin/new") {
|
||||
w.Write([]byte("New"))
|
||||
} else if middleware.Path(r.URL.Path).Matches("/admin/edit") {
|
||||
var fileName string
|
||||
|
||||
fileName = strings.Replace(r.URL.Path, "/admin/edit", "", 1)
|
||||
|
||||
w.Write([]byte("Edit " + fileName))
|
||||
} else {
|
||||
w.Write([]byte("Admin"))
|
||||
}
|
||||
|
||||
return 200, nil
|
||||
return routing.Route(w, r)
|
||||
}
|
||||
|
||||
return h.Next.ServeHTTP(w, r)
|
||||
|
43
routing/routing.go
Normal file
43
routing/routing.go
Normal file
@ -0,0 +1,43 @@
|
||||
package routing
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/hacdias/caddy-hugo/edit"
|
||||
"github.com/mholt/caddy/middleware"
|
||||
)
|
||||
|
||||
const (
|
||||
mainURL string = "/admin"
|
||||
contentURL string = mainURL + "/content"
|
||||
dataURL string = mainURL + "/data"
|
||||
editURL string = mainURL + "/edit"
|
||||
newURL string = mainURL + "/new"
|
||||
settingsURL string = mainURL + "/settings"
|
||||
staticURL string = mainURL + "/static"
|
||||
)
|
||||
|
||||
// Route the admin path
|
||||
func Route(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||
if middleware.Path(r.URL.Path).Matches(contentURL) {
|
||||
w.Write([]byte("Show Content Folder"))
|
||||
} else if middleware.Path(r.URL.Path).Matches(dataURL) {
|
||||
w.Write([]byte("Show Data Folder"))
|
||||
} else if middleware.Path(r.URL.Path).Matches(editURL) {
|
||||
return edit.Execute(w, r, strings.Replace(r.URL.Path, editURL+"/", "", 1))
|
||||
} else if middleware.Path(r.URL.Path).Matches(newURL) {
|
||||
w.Write([]byte("New Thing Page"))
|
||||
} else if middleware.Path(r.URL.Path).Matches(settingsURL) {
|
||||
w.Write([]byte("Settings Page"))
|
||||
} else if middleware.Path(r.URL.Path).Matches(staticURL) {
|
||||
w.Write([]byte("Static things management"))
|
||||
} else if r.URL.Path == mainURL || r.URL.Path == mainURL+"/" {
|
||||
w.Write([]byte("Dashboard"))
|
||||
} else {
|
||||
return 404, nil
|
||||
}
|
||||
|
||||
return 200, nil
|
||||
|
||||
}
|
1
templates/edit_form.tpl
Normal file
1
templates/edit_form.tpl
Normal file
@ -0,0 +1 @@
|
||||
{{ .Content }}
|
Loading…
Reference in New Issue
Block a user