Documentation
¶
Index ¶
- Constants
- func ClearPreviewCookie(w http.ResponseWriter, secure bool)
- func DerivePreviewKey(jwtSecret string) []byte
- func SetPreviewCookie(w http.ResponseWriter, value string, expiresAt time.Time, secure bool)
- func SignPreviewCookie(name string, key []byte) (value string, expiresAt time.Time)
- func VerifyPreviewCookie(value string, key []byte) (string, bool)
- type ThemGenHandler
- func (h *ThemGenHandler) Activate(w http.ResponseWriter, r *http.Request)
- func (h *ThemGenHandler) Deactivate(w http.ResponseWriter, r *http.Request)
- func (h *ThemGenHandler) Delete(w http.ResponseWriter, r *http.Request)
- func (h *ThemGenHandler) Download(w http.ResponseWriter, r *http.Request)
- func (h *ThemGenHandler) Generate(w http.ResponseWriter, r *http.Request)
- func (h *ThemGenHandler) List(w http.ResponseWriter, r *http.Request)
- func (h *ThemGenHandler) Preview(w http.ResponseWriter, r *http.Request)
- func (h *ThemGenHandler) PreviewStatus(w http.ResponseWriter, r *http.Request)
- func (h *ThemGenHandler) SetPreviewKey(key []byte, secure bool)
- func (h *ThemGenHandler) SetSnapshotRenderer(snapshotter ThemeSnapshotter)
- func (h *ThemGenHandler) Snapshot(w http.ResponseWriter, r *http.Request)
- func (h *ThemGenHandler) StopPreview(w http.ResponseWriter, r *http.Request)
- type ThemeActivationStore
- type ThemeReloader
- type ThemeService
- type ThemeSnapshotter
Constants ¶
const ( // PreviewCookieName carries the signed theme preview selection. It must // stay on the NoCookie allowlist (internal/app) or the guard strips it // and preview silently never engages. PreviewCookieName = "lesstruct_theme_preview" )
Variables ¶
This section is empty.
Functions ¶
func ClearPreviewCookie ¶
func ClearPreviewCookie(w http.ResponseWriter, secure bool)
ClearPreviewCookie unsets the preview selection.
func DerivePreviewKey ¶
DerivePreviewKey derives the cookie-signing key from the server secret. Domain separation keeps a leaked preview cookie useless against the session and API-key schemes.
func SetPreviewCookie ¶
SetPreviewCookie writes the signed preview selection. Secure mirrors the site origin (HTTPS only).
func SignPreviewCookie ¶
SignPreviewCookie mints an authenticated preview cookie value for name, valid for the preview TTL. It also returns the expiry for the response.
Types ¶
type ThemGenHandler ¶
type ThemGenHandler struct {
// contains filtered or unexported fields
}
ThemGenHandler serves the AI theme generator surface: generate, list, download, activate, deactivate, delete, preview, preview status, and snapshot.
func NewThemGenHandler ¶
func NewThemGenHandler( service ThemeService, activations ThemeActivationStore, logger kernel.Logger, defaultEdition themegendomain.Edition, reloader ThemeReloader, ) *ThemGenHandler
NewThemGenHandler builds the theme generator handler. A nil logger degrades to a discard sink so the handler is safe in any context. A nil reloader keeps the restart-hint activation behavior.
func (*ThemGenHandler) Activate ¶
func (h *ThemGenHandler) Activate(w http.ResponseWriter, r *http.Request)
Activate validates the theme, writes [theme] active, and hot-reloads the content-site surfaces when a reloader is attached (restart to apply otherwise). A reload failure reverts the config write and reports an error so activation stays transactional.
func (*ThemGenHandler) Deactivate ¶
func (h *ThemGenHandler) Deactivate(w http.ResponseWriter, r *http.Request)
Deactivate clears [theme] active back to the embedded default and hot-reloads the content-site surfaces when a reloader is attached. A reload failure restores the previous value and reports an error.
func (*ThemGenHandler) Delete ¶
func (h *ThemGenHandler) Delete(w http.ResponseWriter, r *http.Request)
Delete removes an installed theme (409 while active).
func (*ThemGenHandler) Download ¶
func (h *ThemGenHandler) Download(w http.ResponseWriter, r *http.Request)
Download streams the theme zip with a THEME_DIR install README.
func (*ThemGenHandler) Generate ¶
func (h *ThemGenHandler) Generate(w http.ResponseWriter, r *http.Request)
Generate creates a theme from a natural-language brief, validates it, and auto-installs it as inactive.
func (*ThemGenHandler) List ¶
func (h *ThemGenHandler) List(w http.ResponseWriter, r *http.Request)
List returns the installed themes with active markers.
func (*ThemGenHandler) Preview ¶
func (h *ThemGenHandler) Preview(w http.ResponseWriter, r *http.Request)
Preview validates the theme and sets a short-lived signed preview cookie so the content site renders that theme for this browser only. It changes nothing server-side: activation still applies the theme to everyone.
func (*ThemGenHandler) PreviewStatus ¶
func (h *ThemGenHandler) PreviewStatus(w http.ResponseWriter, r *http.Request)
PreviewStatus reports whether this browser holds a valid preview cookie. The UI polls it on mount so the stop-preview affordance only renders while a preview is actually active; without a key every cookie is unverifiable and the answer is always false.
func (*ThemGenHandler) SetPreviewKey ¶
func (h *ThemGenHandler) SetPreviewKey(key []byte, secure bool)
SetPreviewKey installs the cookie-signing key for the preview endpoints. Without it Preview answers 503; StopPreview still clears the cookie.
func (*ThemGenHandler) SetSnapshotRenderer ¶
func (h *ThemGenHandler) SetSnapshotRenderer(snapshotter ThemeSnapshotter)
SetSnapshotRenderer installs the edition's snapshot closure for the snapshot endpoint. Without it Snapshot answers 503.
func (*ThemGenHandler) Snapshot ¶
func (h *ThemGenHandler) Snapshot(w http.ResponseWriter, r *http.Request)
Snapshot renders the installed theme's homepage to a standalone HTML document for the admin panel's snapshot frames. Unknown or broken themes degrade to a placeholder document; without a renderer the endpoint is unavailable.
func (*ThemGenHandler) StopPreview ¶
func (h *ThemGenHandler) StopPreview(w http.ResponseWriter, r *http.Request)
StopPreview clears the preview cookie so the content site renders the active theme again.
type ThemeActivationStore ¶
type ThemeActivationStore interface {
ActiveTheme(ctx context.Context) string
SaveActive(ctx context.Context, name string) error
ClearActive(ctx context.Context) error
}
ThemeActivationStore persists the active installed theme: the [theme] active value the edition composes over the embedded default.
type ThemeReloader ¶
ThemeReloader swaps the live content-site surfaces to the active theme without a restart. It is satisfied by the edition; a nil reloader keeps the restart-hint behavior.
type ThemeService ¶
type ThemeService interface {
Generate(ctx context.Context, brief themegendomain.Brief, edition themegendomain.Edition) (themegendomain.Theme, themegendomain.ValidationReport, error)
Validate(ctx context.Context, theme themegendomain.Theme) themegendomain.ValidationReport
List(ctx context.Context) ([]themegendomain.InstalledTheme, error)
Get(ctx context.Context, name string) (themegendomain.Theme, error)
Delete(ctx context.Context, name string) error
Zip(ctx context.Context, name string) ([]byte, error)
}
ThemeService is the generation orchestration seam the handler drives. It mirrors the domain Service's persistence-facing methods so mocks stay narrow.
type ThemeSnapshotter ¶
ThemeSnapshotter renders an installed theme's homepage to a standalone HTML document for admin snapshots. It is satisfied by the edition; a nil snapshotter keeps the snapshot endpoint unavailable.