mirror of
https://tangled.org/evan.jarrett.net/at-container-registry
synced 2026-08-31 05:07:09 +00:00
40 lines
1.3 KiB
Go
40 lines
1.3 KiB
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
|
|
"atcr.io/pkg/appview/db"
|
|
"atcr.io/pkg/appview/middleware"
|
|
)
|
|
|
|
// PageData contains common fields shared across all page templates
|
|
type PageData struct {
|
|
User *db.User // Logged-in user (nil if not logged in)
|
|
Query string // Search query from URL parameter
|
|
RegistryURL string // Docker registry domain (e.g., "buoy.cr")
|
|
SiteURL string // Website domain (e.g., "seamark.dev")
|
|
ClientName string // Brand name for templates (e.g., "AT Container Registry")
|
|
ClientShortName string // Brand name for templates (e.g., "ATCR")
|
|
}
|
|
|
|
// NewPageData creates a PageData struct with common fields populated from the request
|
|
func NewPageData(r *http.Request, h *BaseUIHandler) PageData {
|
|
return PageData{
|
|
User: middleware.GetUser(r),
|
|
Query: r.URL.Query().Get("q"),
|
|
RegistryURL: h.RegistryURL,
|
|
SiteURL: h.SiteURL,
|
|
ClientName: h.ClientName,
|
|
ClientShortName: h.ClientShortName,
|
|
}
|
|
}
|
|
|
|
// TrimRegistryURL removes http:// or https:// prefix from a URL
|
|
// for use in Docker commands where only the host:port is needed
|
|
func TrimRegistryURL(url string) string {
|
|
url = strings.TrimPrefix(url, "https://")
|
|
url = strings.TrimPrefix(url, "http://")
|
|
return url
|
|
}
|