Extract Grammaratur, Dregarnuhr, Geduldh, Mestionora, Ordoschnellic, Schutzaria, Kunstzeal and Seheweit behind compatible application contracts. Include accumulated editor resilience, navigation and theme UX, remote CLI, storage/schema and DR groundwork, tests and design/operations documentation. Verified: uncached full Go suite; go vet ./...; race tests for all eight components; 11 targeted Chromium tests; Node suites; 19 Python CLI tests; reproducible editor build. No push, release tag or deployment in this checkpoint.
117 lines
2.8 KiB
Go
117 lines
2.8 KiB
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"pageswiki/internal/store"
|
|
)
|
|
|
|
type browserEntryView struct {
|
|
store.BrowserEntry
|
|
ThumbnailURL string
|
|
}
|
|
|
|
func (s *Server) browserEntryViews(entries []store.BrowserEntry) []browserEntryView {
|
|
views := make([]browserEntryView, 0, len(entries))
|
|
for _, entry := range entries {
|
|
view := browserEntryView{BrowserEntry: entry}
|
|
if !entry.IsDir && entry.RevisionUUID != "" {
|
|
filename := entry.Filename
|
|
if filename == "" {
|
|
filename = filepath.Base(entry.Path)
|
|
}
|
|
adapter := selectProjectionAdapter(contentDescriptor{
|
|
MediaType: strings.ToLower(strings.Split(entry.ContentType, ";")[0]),
|
|
Filename: filename,
|
|
SizeBytes: int64(entry.Size),
|
|
})
|
|
if adapter.ID == "image" {
|
|
if cachedURL, cached := s.entryPreviewState(entry, "image", false); cached {
|
|
view.ThumbnailURL = cachedURL
|
|
} else {
|
|
view.ThumbnailURL = rawProjectionURL("rev:"+entry.RevisionUUID) + "?preview=1"
|
|
}
|
|
}
|
|
}
|
|
views = append(views, view)
|
|
}
|
|
return views
|
|
}
|
|
|
|
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
|
|
}
|
|
// Browser navigation is scoped to this semantic Path, not a Domain-wide
|
|
// read grant. Filter each child separately below as well.
|
|
if !s.requestCanReadPath(r, currentPath) {
|
|
http.Error(w, "forbidden", http.StatusForbidden)
|
|
return
|
|
}
|
|
w.Header().Set("Cache-Control", "private, no-store")
|
|
w.Header().Add("Vary", "Cookie, Authorization")
|
|
|
|
entries, err :=
|
|
s.store.ListBrowserEntriesInDomain(
|
|
s.domainUUIDForRequest(r),
|
|
currentPath,
|
|
)
|
|
|
|
if err != nil {
|
|
http.Error(w, err.Error(), 500)
|
|
return
|
|
}
|
|
visibleEntries := entries[:0]
|
|
for _, entry := range entries {
|
|
if s.requestCanReadPath(r, entry.Path) {
|
|
visibleEntries = append(visibleEntries, entry)
|
|
}
|
|
}
|
|
entries = visibleEntries
|
|
var navigatorLinks []store.BrowserNavigationLink
|
|
if principal := s.requestPrincipal(r); principal != nil {
|
|
if links, linkErr := s.store.ListBrowserNavigationLinks(s.domainUUIDForRequest(r), principal.UUID); linkErr == nil {
|
|
for _, link := range links {
|
|
if s.requestCanReadPath(r, link.Path) {
|
|
navigatorLinks = append(navigatorLinks, link)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
s.renderWithContext(
|
|
w,
|
|
r,
|
|
"browser.gohtml",
|
|
map[string]any{
|
|
"NavItems": resolveNavItems(
|
|
s.getSystemNavItems(s.domainUUIDForRequest(r)),
|
|
NavContext{
|
|
Path: currentPath,
|
|
},
|
|
),
|
|
"Path": currentPath,
|
|
"Breadcrumbs": buildBreadcrumbs(currentPath),
|
|
"Entries": s.browserEntryViews(entries),
|
|
"NavigatorLinks": navigatorLinks,
|
|
"CanEditNavigator": s.requestPrincipal(r) != nil,
|
|
},
|
|
)
|
|
}
|