Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming. Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
109 lines
2.5 KiB
Go
109 lines
2.5 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
|
|
}
|
|
|
|
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,
|
|
},
|
|
)
|
|
}
|