config

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: May 20, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Save

func Save(cfg *Config, path string) error

Save marshals cfg to TOML and writes atomically to path.

func ValidateGalleryName added in v1.1.0

func ValidateGalleryName(name string) error

ValidateGalleryName rejects empty names or characters unsafe in a filename.

func ValidateScheduleTime added in v1.1.0

func ValidateScheduleTime(v string) error

ValidateScheduleTime accepts "HH:MM" in 24-hour form.

Types

type AuthConfig

type AuthConfig struct {
	EnablePassword      bool   `toml:"enable_password"`
	PasswordHash        string `toml:"password_hash"`
	SessionLifetimeDays int    `toml:"session_lifetime_days"`
	APIToken            string `toml:"api_token"`
}

type Config

type Config struct {
	DefaultGallery string          `toml:"default_gallery"`
	Galleries      []Gallery       `toml:"galleries"`
	Server         ServerConfig    `toml:"server"`
	Paths          PathsConfig     `toml:"paths"`
	Gallery        GalleryConfig   `toml:"gallery"`
	Tagger         TaggerConfig    `toml:"tagger"`
	Auth           AuthConfig      `toml:"auth"`
	UI             UIConfig        `toml:"ui"`
	Log            LogConfig       `toml:"log"`
	Schedule       ScheduleConfig  `toml:"schedule"`
	Relations      RelationsConfig `toml:"relations"`
}

Config holds all application configuration.

func Default

func Default() *Config

Default returns a fully populated config with all spec defaults.

func Load

func Load(path string) (*Config, error)

Load reads and decodes a TOML config file. If absent, creates it with defaults.

func (*Config) DerivePaths added in v1.1.0

func (cfg *Config) DerivePaths(name string) (dbPath, thumbnailsPath string)

DerivePaths returns the canonical DB and thumbnails paths for a gallery. Each gallery lives under <data_path>/<name>/.

func (*Config) FindGallery added in v1.1.0

func (cfg *Config) FindGallery(name string) *Gallery

FindGallery returns the gallery with the given name, or nil.

type Gallery struct {
	Name           string `toml:"name"`
	GalleryPath    string `toml:"gallery_path"`
	DBPath         string `toml:"-"`
	ThumbnailsPath string `toml:"-"`
}

Gallery is one named gallery. Only Name and GalleryPath persist; DBPath and ThumbnailsPath are derived at Load time.

type GalleryConfig

type GalleryConfig struct {
	WatchEnabled  bool `toml:"watch_enabled"`
	MaxFileSizeMB int  `toml:"max_file_size_mb"`
}

type LogConfig

type LogConfig struct {
	Level string `toml:"level"`
}

LogConfig controls log verbosity: "warn" (default), "info", "debug".

type PathsConfig

type PathsConfig struct {
	DataPath  string `toml:"data_path"`
	ModelPath string `toml:"model_path"`
}

PathsConfig holds process-wide paths. Per-gallery DB and thumbnails paths are derived from DataPath + the gallery name.

type RelationsConfig added in v1.8.0

type RelationsConfig struct {
	DefaultDistance     int    `toml:"default_distance"`
	DefaultSessionOrder string `toml:"default_session_order"`
	IncrementalOnIngest bool   `toml:"incremental_on_ingest"`
}

RelationsConfig drives the relations feature's runtime knobs. default_distance is the Hamming-distance default for find-pairs and the bare phash:<hex>~ form; default_session_order picks which mode the Start-session CTA preselects; incremental_on_ingest toggles the on-ingest BK-tree probe that fans new pairs into the queue.

type ScheduleConfig added in v1.1.0

type ScheduleConfig struct {
	Time              string `toml:"time"` // "HH:MM" 24h, default "01:00"
	SyncGallery       bool   `toml:"sync_gallery"`
	RemoveOrphans     bool   `toml:"remove_orphans"`
	RunAutoTaggers    bool   `toml:"run_auto_taggers"`
	FindRelationPairs bool   `toml:"find_relation_pairs"`
}

ScheduleConfig drives the once-per-day maintenance run at HH:MM on every configured gallery.

type ServerConfig

type ServerConfig struct {
	BindAddress string `toml:"bind_address"`
	BaseURL     string `toml:"base_url"`
	// CustomCSS is an optional absolute path to a stylesheet that the
	// operator drops next to monbooru.toml. When set, it is served at
	// /custom.css and linked from the layout after the bundled main.css
	// so :root overrides win the cascade.
	CustomCSS string `toml:"custom_css"`
}

type TaggerAggregationCfg added in v1.7.0

type TaggerAggregationCfg struct {
	MinHitFraction float64 `toml:"min_hit_fraction"`
}

TaggerAggregationCfg holds the frame-merge knob shared across every configured tagger. MinHitFraction is the fraction of frames a label must score above the pre-floor on to survive the per-row merge. Resolves to min_hits = clamp(ceil(MinHitFraction * frame_count), 2, 10), degrading to 1 when frame_count == 1 (single image). MinHitFraction = 0 reverts to the legacy max-only behaviour (one hit is enough, stored confidence is the peak score).

type TaggerConfig

type TaggerConfig struct {
	UseCUDA  bool `toml:"use_cuda"`
	Parallel int  `toml:"parallel"`
	// IdleReleaseAfterMinutes is how long the cached ORT session may sit
	// idle before the reclaim loop tears it down. 0 disables caching, so
	// every run loads the model fresh. Default 30.
	IdleReleaseAfterMinutes int                  `toml:"idle_release_after_minutes"`
	Aggregation             TaggerAggregationCfg `toml:"aggregation"`
	Taggers                 []TaggerInstance     `toml:"taggers"`
}

type TaggerInstance

type TaggerInstance struct {
	Name                string  `toml:"name"`
	Enabled             bool    `toml:"enabled"`
	ConfidenceThreshold float64 `toml:"confidence_threshold"`
	ModelFile           string  `toml:"model_file"`
	TagsFile            string  `toml:"tags_file"`
	// CategoryThresholds overrides ConfidenceThreshold per destination
	// category. A label whose resolved category name appears as a key
	// uses that threshold; missing keys fall back to the global one.
	// Operator-managed via Settings → Auto-Tagger → Configure.
	CategoryThresholds map[string]float64 `toml:"category_thresholds,omitempty"`
	// PerCategoryTopK caps the number of tags this tagger may emit per
	// category after thresholding. Map key is the category name; value
	// 0 disables the cap for that category on this tagger. Missing
	// keys fall back to the built-in default table (character=8,
	// copyright=4, artist=4, general=25, rating=1, other=10).
	// Operator-managed via Settings → Auto-Tagger → Configure.
	PerCategoryTopK map[string]int `toml:"per_category_top_k,omitempty"`
	// Galleries restricts this tagger to a named subset of galleries.
	// Three persisted shapes:
	//   - missing in TOML (decodes to nil) - applies to every gallery,
	//     including ones added later. The legacy default.
	//   - galleries = []                  - applies to no gallery; the
	//     tagger stays configured but dormant.
	//   - galleries = [...]               - applies only to those names.
	// `omitempty` is intentionally absent so an explicit empty slice
	// survives a write/read round-trip; without it BurntSushi collapses
	// nil and empty into the same wire shape.
	// Operator-managed via Settings → Auto-Tagger → Galleries.
	Galleries []string `toml:"galleries"`
}

func (TaggerInstance) AppliesToGallery added in v1.5.1

func (t TaggerInstance) AppliesToGallery(name string) bool

AppliesToGallery reports whether this tagger should run on the named gallery. Nil Galleries means "every gallery" (matches the pre-feature behaviour); a non-nil slice gates by exact name match - including the explicit-empty case, which means "no gallery".

type UIConfig

type UIConfig struct {
	PageSize int `toml:"page_size"`
}

Jump to

Keyboard shortcuts

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