api

package
v1.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 17 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
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

func DerivePreviewKey(jwtSecret string) []byte

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

func SetPreviewCookie(w http.ResponseWriter, value string, expiresAt time.Time, secure bool)

SetPreviewCookie writes the signed preview selection. Secure mirrors the site origin (HTTPS only).

func SignPreviewCookie

func SignPreviewCookie(name string, key []byte) (value string, expiresAt time.Time)

SignPreviewCookie mints an authenticated preview cookie value for name, valid for the preview TTL. It also returns the expiry for the response.

func VerifyPreviewCookie

func VerifyPreviewCookie(value string, key []byte) (string, bool)

VerifyPreviewCookie authenticates a preview cookie value and returns the theme name. Forged, malformed, or expired values report false.

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

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

type ThemeReloader interface {
	Reload(ctx context.Context) error
}

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

ThemeService is the generation orchestration seam the handler drives. It mirrors the domain Service's persistence-facing methods so mocks stay narrow.

type ThemeSnapshotter

type ThemeSnapshotter interface {
	SnapshotTheme(name string) (string, error)
}

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL