Files
pages/internal/server/browser_handler.go
T

53 lines
771 B
Go

package server
import (
"net/http"
"strings"
)
func (s *Server) handleBrowser(
w http.ResponseWriter,
r *http.Request,
) {
currentPath :=
strings.TrimPrefix(
r.URL.Path,
"/v/browser",
)
if currentPath == "" || currentPath == "/" {
currentPath = "/"
}
if !strings.HasPrefix(currentPath, "/") {
currentPath = "/" + currentPath
}
entries, err :=
s.store.ListBrowserEntries(
currentPath,
)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
s.render(
w,
"browser.gohtml",
map[string]any{
"NavItems": resolveNavItems(
s.getSystemNavItems(),
NavContext{
Path: currentPath,
},
),
"Path": currentPath,
"Breadcrumbs": buildBreadcrumbs(currentPath),
"Entries": entries,
},
)
}