web

package
v0.1.108 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: Apache-2.0 Imports: 42 Imported by: 0

Documentation

Overview

Package web serves the local management UI (gomponents templates + htmx + embedded Tailwind) and its JSON-free HTML fragment endpoints. All static assets are embedded, so the server is fully self-contained and offline.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	BaseURL             string
	DefaultPollInterval time.Duration
	// Addr is the server's listen address (host:port). It decides whether the
	// arbitrary extra-scan-path capability is exposed: only a loopback bind is
	// treated as single-user-local (see extraPathsAllowed).
	Addr string
	// Library-management config (used by the library page + quarantine).
	ModelRoot    string
	TrashDir     string
	LibraryPaths []string
	Extensions   []string
	// WebScanTimeout bounds a web-triggered "Scan now"; WebScanMaxFiles caps how
	// many model files that scan will walk. Both bound the arbitrary-path walk the
	// endpoint exposes. Zero falls back to the config package defaults.
	WebScanTimeout  time.Duration
	WebScanMaxFiles int
	// ComfyURL is the local ComfyUI server base URL for workflow runs/preflight. It
	// is config-only (never a per-request parameter). Empty disables local run.
	ComfyURL string
	// ComfyToken is an optional bearer token for a login-fronted ComfyUI. Secret —
	// never rendered/logged.
	ComfyToken string
	// ComfyModelPath is the local ComfyUI models/ directory root used by the
	// "Download & run" action to write a missing model into the correct per-type
	// subfolder. Empty (or a non-loopback ComfyUI) disables the download flow — the
	// missing-models panel then degrades to CivitAI-link-only. Validated at config
	// load (existing writable dir when set).
	ComfyModelPath string
	// ComfyRoot is the local ComfyUI INSTALL root (the folder holding
	// custom_nodes/). It is used ONLY by the explicit, user-triggered install of
	// the civitai-manager ComfyUI helper extension. Empty disables that action.
	// Resolved by config (explicit comfy_root, else the comfy_model_path parent
	// when it looks like a ComfyUI install).
	ComfyRoot string
	// OutputsDir is the civitai-manager-owned directory the output gallery copies
	// successful workflow-run images into (app-owned data next to the DB). Always
	// set by config resolution (defaults to <db-dir>/outputs). Capture is skipped
	// when empty (e.g. an unconfigured test server).
	OutputsDir string
	// OutputsMaxBytes is the TOTAL disk cap of the outputs tree, in bytes. After a
	// successful capture the oldest generations (rows + files) are evicted until the
	// total is back under it. 0 (or negative) means UNLIMITED — no eviction ever.
	// Resolved by config (default 20 GiB); an unset zero value in a test server is
	// therefore "unlimited", matching the pre-cap behaviour.
	OutputsMaxBytes int64
	// MaxFileSizeBytes caps a "Download & run" model download (0 = the built-in
	// safety guard). It reuses the poller's max_file_size setting so a single knob
	// bounds every download the app makes.
	MaxFileSizeBytes int64
	// ComfyCloud enables the "Run on CivitAI Cloud" feature (submit to the CivitAI
	// orchestration API, sending the graph + resource list to civitai.com and
	// spending Buzz). Default OFF → the cloud UI is shown but disabled with a note.
	//
	// It is a *bool carried straight through from config.Config: nil means the
	// config FILE said nothing, so the DB-stored web toggle governs (see
	// Server.cloudEnabled); non-nil means the file is authoritative and the web
	// toggle renders read-only. Read it through Server.cloudEnabled /
	// Server.cloudEnabledFromConfig, never directly.
	ComfyCloud *bool
	// Token is the CivitAI API token, reused as the bearer for the cloud
	// orchestration API — cloud auth introduces NO separate credential. Secret:
	// never rendered (config.RedactToken only) and never logged.
	Token string
	// HFToken is the optional HuggingFace token for the HF fallback resolver. Secret
	// — never rendered/logged; sent only to HuggingFace hosts.
	HFToken string
	// HFFallback enables the HuggingFace fallback (try HF when CivitAI resolution
	// misses). Default resolved from config (on unless explicitly disabled).
	HFFallback bool
	// ResolveNodePacks enables the ONLINE half of custom-node attribution (send the
	// class names ComfyUI-Manager could not place to api.comfy.org and
	// raw.githubusercontent.com). Default resolved from config (on unless explicitly
	// disabled). When false, attribution is local-Manager-only and NO request to
	// either host is made. Manager itself is loopback and is never gated by this.
	ResolveNodePacks bool
}

Config holds the web server's view of app configuration.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server wires the store, the CivitAI reader, and the subscriber into an http.Handler.

func NewServer

func NewServer(st *store.Store, reader civitai.Reader, sub Subscriber, cfg Config, log *slog.Logger) *Server

NewServer builds a Server.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler builds the routed http.Handler.

func (*Server) SetBaseContext added in v0.1.9

func (s *Server) SetBaseContext(ctx context.Context)

SetBaseContext sets the server's base context, from which background discovery crawls derive. Cancelling ctx (server shutdown) cancels any in-flight crawl. Call before Handler is served.

type Subscriber

type Subscriber interface {
	SubscribeModel(ctx context.Context, modelID int, opts poller.SubscribeOptions) (int64, error)
	SubscribeCreator(ctx context.Context, username string, opts poller.SubscribeOptions) (int64, error)
}

Subscriber is the subscription-management surface the UI needs (satisfied by *poller.Poller).

Jump to

Keyboard shortcuts

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