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.
83 lines
2.2 KiB
Go
83 lines
2.2 KiB
Go
package server
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"net/http"
|
|
"net/url"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
const defaultHomeGlassTransparency = 42
|
|
|
|
func normalizeHomeGlassTransparency(raw string) (int, error) {
|
|
value, err := strconv.Atoi(strings.TrimSpace(raw))
|
|
if err != nil || value < 0 || value > 85 {
|
|
return 0, errors.New("invalid home glass transparency")
|
|
}
|
|
return value, nil
|
|
}
|
|
|
|
func (s *Server) homeGlassTransparency(domainUUID string) int {
|
|
value, err := normalizeHomeGlassTransparency(s.getDomainConfig("home_glass_transparency", domainUUID))
|
|
if err != nil {
|
|
return defaultHomeGlassTransparency
|
|
}
|
|
return value
|
|
}
|
|
|
|
func (s *Server) homeLayout(domainUUID string) string {
|
|
switch value := s.getDomainConfig("home_layout", domainUUID); value {
|
|
case "search", "directory", "diary", "blog":
|
|
return value
|
|
default:
|
|
return "classic"
|
|
}
|
|
}
|
|
|
|
func parseHomeBookmarks(raw string) ([]NavItem, error) {
|
|
items := []NavItem{}
|
|
for _, line := range strings.Split(raw, "\n") {
|
|
if strings.TrimSpace(line) == "" {
|
|
continue
|
|
}
|
|
label, href, ok := strings.Cut(line, "|")
|
|
label, href = strings.TrimSpace(label), strings.TrimSpace(href)
|
|
if !ok || label == "" || !validHomeBookmarkURL(href) || len(items) >= 64 {
|
|
return nil, errors.New("invalid home bookmark")
|
|
}
|
|
items = append(items, NavItem{Label: label, Href: href})
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
func validHomeBookmarkURL(href string) bool {
|
|
u, err := url.Parse(href)
|
|
if err != nil || strings.ContainsAny(href, "\\\r\n") || u.User != nil {
|
|
return false
|
|
}
|
|
if u.Scheme == "http" || u.Scheme == "https" {
|
|
return u.Hostname() != ""
|
|
}
|
|
return u.Scheme == "" && u.Host == "" && strings.HasPrefix(href, "/") && !strings.HasPrefix(href, "//")
|
|
}
|
|
|
|
func (s *Server) homeBookmarks(domainUUID string) []NavItem {
|
|
var items []NavItem
|
|
_ = json.Unmarshal([]byte(s.getDomainConfig("home_bookmarks", domainUUID)), &items)
|
|
return items
|
|
}
|
|
|
|
func (s *Server) homeBookmarksText(domainUUID string) string {
|
|
var lines []string
|
|
for _, item := range s.homeBookmarks(domainUUID) {
|
|
lines = append(lines, item.Label+" | "+item.Href)
|
|
}
|
|
return strings.Join(lines, "\n")
|
|
}
|
|
|
|
func (s *Server) renderSearchHome(w http.ResponseWriter, r *http.Request, layout string) {
|
|
s.renderWithContext(w, r, "search_home.gohtml", map[string]any{"HomeLayout": layout})
|
|
}
|