Documentation
¶
Index ¶
- Variables
- type Ceiling
- func (c *Ceiling) AnyTainted(ids []int64) bool
- func (c *Ceiling) Apply(userExpr search.Expr) search.Expr
- func (c *Ceiling) ExcludedTagIDs() []int64
- func (c *Ceiling) IsActive() bool
- func (c *Ceiling) Level() string
- func (c *Ceiling) TaintedImageIDs() (map[int64]bool, error)
- func (c *Ceiling) WhereGroupClean(membersTable, groupCol string) (string, []any)
- func (c *Ceiling) WhereOne(col string) (string, []any)
- func (c *Ceiling) WhereTwo(leftCol, rightCol string) (string, []any)
- type ScheduleStatus
- type Server
- func (s *Server) Active() *galleryCtx
- func (s *Server) AddGallery(name, galleryPath string) error
- func (s *Server) CSRFMiddleware(next http.Handler) http.Handler
- func (s *Server) Close()
- func (s *Server) ContextMiddleware(next http.Handler) http.Handler
- func (s *Server) ExportGalleryArchive(name, format string, w io.Writer) error
- func (s *Server) ExportGalleryDB(name string, w io.Writer) error
- func (s *Server) ExportGalleryJSON(name string, w io.Writer) error
- func (s *Server) ExportGalleryLight(name string, w io.Writer) error
- func (s *Server) ExportGalleryLightManifest(name string, w io.Writer) error
- func (s *Server) Get(name string) *galleryCtx
- func (s *Server) Handler() http.Handler
- func (s *Server) ImportGallery(name, format string, upload io.Reader) error
- func (s *Server) MergeGallery(name, format string, upload io.Reader) error
- func (s *Server) RemoveGallery(name string, removeFolder bool) error
- func (s *Server) RenameGallery(oldName, newName string) error
- func (s *Server) ScheduleStatus() ScheduleStatus
- func (s *Server) SessionMiddleware(next http.Handler) http.Handler
- func (s *Server) SetDefault(name string) error
- func (s *Server) StartWatchers()
- func (s *Server) SwitchGallery(name string) error
- type Session
- type SessionStore
Constants ¶
This section is empty.
Variables ¶
var RepoURL = "https://github.com/leqwin/monbooru"
RepoURL is the canonical git repository URL, set at build time via -ldflags.
var Variant = ""
Variant identifies the build flavour (e.g. "cuda") and is injected at build time via -ldflags from the CUDA Dockerfile. Empty for the default CPU build; rendered in parentheses in the footer when non-empty.
var Version = "dev"
Version is set at build time via -ldflags, or read from VERSION.md.
Functions ¶
This section is empty.
Types ¶
type Ceiling ¶ added in v1.8.2
type Ceiling struct {
// contains filtered or unexported fields
}
Ceiling carries the resolved rating-ceiling state for one request. Construct via resolveCeiling so callers share the per-request cache of excluded tag ids and the optional tainted-image set.
A Ceiling is safe to share across goroutines for one request. The sidebar handlers fan out to 6 worker goroutines that all consult the same *Ceiling; the mutex below guards the lazy caches against the resulting concurrent first-access. The hot path (cache hit) reads the cached slice / map directly under a single sync.Mutex acquire.
func (*Ceiling) AnyTainted ¶ added in v1.8.2
AnyTainted reports whether any id in ids is tainted under c. A nil map (inactive ceiling) makes the check a no-op so call sites can treat the helper as policy-aware without an extra IsActive guard.
func (*Ceiling) Apply ¶ added in v1.8.2
Apply AND-chains a NotExpr per rating level above the ceiling onto userExpr. The emitted AST shape is the contract fastCountCeiling recognises - keep this function as the sole producer. An empty or "explicit" ceiling returns userExpr unchanged.
func (*Ceiling) ExcludedTagIDs ¶ added in v1.8.2
ExcludedTagIDs returns the tag ids whose rating rank is strictly above the ceiling. Memoised per Ceiling so multiple call sites in one request pay the SELECT once. Returns nil when the ceiling is inactive or the active gallery isn't available.
func (*Ceiling) IsActive ¶ added in v1.8.2
IsActive reports whether a ceiling will actually filter anything. The no-cookie state and explicit-cookie state are both inactive: an explicit cookie is a no-op in the same way the empty cookie is, since the rating vocabulary tops out at explicit.
func (*Ceiling) Level ¶ added in v1.8.2
Level returns the raw cookie value. Empty string and "explicit" both mean "no ceiling"; callers that care about that distinction should use IsActive instead.
func (*Ceiling) TaintedImageIDs ¶ added in v1.8.2
TaintedImageIDs returns the set of image ids whose tag list intersects the excluded rating ids. Used to drop whole relation chains / trees when any member exceeds the ceiling. Lazy - the SELECT runs only on first call, then is cached for the rest of the request. Returns nil when the ceiling is inactive.
The mutex is held only around the cache-slot read and the result commit - the SELECT runs unlocked so a sidebar fan-out's six goroutines don't serialise behind it on a cache miss. A race that runs the SELECT twice is harmless (last writer wins, both reads see the same DB state).
func (*Ceiling) WhereGroupClean ¶ added in v1.8.2
WhereGroupClean returns a NOT EXISTS predicate that drops a group row when any of its members carries a rating above the ceiling. The predicate is meant to be ANDed onto a `... FROM <groups_table> g` scan: callers wire `groupCol` to the group-id column (e.g. `dup_groups.id`) and `membersTable` to the per-member join table (`dup_group_members`).
Returns ("", nil) when the ceiling is inactive so the caller can skip the predicate entirely and keep the covering scan.
func (*Ceiling) WhereOne ¶ added in v1.8.2
WhereOne returns a NOT EXISTS predicate gating col on the absence of any rating tag above the ceiling. Returns ("", nil) when the ceiling is inactive so the caller can omit the WHERE entirely and keep the covering scan.
type ScheduleStatus ¶ added in v1.2.1
type ScheduleStatus struct {
LastRun time.Time // zero value when no run has happened yet
LastDur time.Duration // zero when LastRun is zero
LastInfo string // "OK" or a short failure summary; empty when never run
NextRun time.Time // zero when no schedule action is enabled
}
ScheduleStatus reports the last recorded scheduler run plus the next fire time. Used by the Schedule settings section.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server holds all shared state for the HTTP server.
func NewServer ¶
NewServer creates the HTTP server with all routes wired. One *db.DB is opened per configured gallery.
func (*Server) Active ¶ added in v1.1.0
func (s *Server) Active() *galleryCtx
Active returns the currently-active gallery context.
func (*Server) AddGallery ¶ added in v1.1.0
AddGallery opens a new gallery and appends it to the config. DB and thumbnails directories are created under paths.data_path/<name>/.
func (*Server) CSRFMiddleware ¶
CSRFMiddleware validates the CSRF token on mutating requests. /api/v1/ routes are exempt (bearer token serves as CSRF mitigation).
func (*Server) Close ¶
func (s *Server) Close()
Close stops background goroutines and closes every gallery's database.
func (*Server) ContextMiddleware ¶ added in v1.1.0
ContextMiddleware RLocks ctxMu for the request so a concurrent swap can't tear state out under it. Mutation endpoints bypass it because they take the write lock themselves.
func (*Server) ExportGalleryArchive ¶ added in v1.3.0
ExportGalleryArchive packs the chosen export format together with every source file under the gallery root into a ZIP archive. The inner DB/JSON file is at the root; images live under `gallery/<relative_path>` so an import restores them into the same subfolder layout.
func (*Server) ExportGalleryDB ¶ added in v1.3.0
ExportGalleryDB produces a clean, WAL-consolidated SQLite snapshot via VACUUM INTO and streams it to w. Safe to call while the source gallery is being read/written; VACUUM INTO sees a consistent point-in-time view.
func (*Server) ExportGalleryJSON ¶ added in v1.3.0
ExportGalleryJSON streams every table of the gallery as a single JSON document. Streams array-by-array so memory stays proportional to the largest single table (image_tags on a big library).
func (*Server) ExportGalleryLight ¶ added in v1.3.0
ExportGalleryLight streams a zip containing gallery/<rel> image files plus a tags.json manifest listing {sha256, path, tags} for each non-missing image. The archive omits monbooru-specific data (SD/ComfyUI metadata, saved searches, tag attribution), keeping it useful as a portable bundle that other software can read or produce.
func (*Server) ExportGalleryLightManifest ¶ added in v1.3.0
ExportGalleryLightManifest streams the same tags.json document as ExportGalleryLight but without the surrounding zip and without the gallery files. Used by the export handler when the user picks the light format without "Include image files".
func (*Server) ImportGallery ¶ added in v1.3.0
ImportGallery replaces the target gallery's database (and optionally its source files) with the contents of the uploaded archive/file. Destructive; the caller's UI is responsible for confirming intent.
format is one of "db", "json", "zip". For "zip" the inner format is detected from the archive. importOver is rejected when the target is the active or default gallery (mirrors RemoveGallery's guard).
func (*Server) MergeGallery ¶ added in v1.3.0
MergeGallery additively brings images and tags from the uploaded file into the named gallery. Unlike ImportGallery it does not wipe anything and is permitted on the active and default galleries. db and json uploads apply tags to existing images matched by SHA; zip uploads (full or light) also ingest new images when the archive carries their files.
func (*Server) RemoveGallery ¶ added in v1.1.0
RemoveGallery drops a gallery and deletes its DB + thumbnails on disk. When removeFolder is true, the gallery's source folder is also removed (best-effort). Refuses to remove the active, default, or last gallery.
func (*Server) RenameGallery ¶ added in v1.1.0
RenameGallery moves the in-memory key and rewrites the TOML. The data directory is also renamed so the derived paths stay consistent.
func (*Server) ScheduleStatus ¶ added in v1.2.1
func (s *Server) ScheduleStatus() ScheduleStatus
ScheduleStatus returns the current scheduler status for the settings page.
func (*Server) SessionMiddleware ¶
SessionMiddleware validates the session cookie and redirects to /login if absent. When authEnabled is false, it passes through with a synthetic session ID.
func (*Server) SetDefault ¶ added in v1.1.0
SetDefault persists cfg.DefaultGallery so the given gallery loads on startup. Doesn't change the runtime-active gallery.
func (*Server) StartWatchers ¶ added in v1.2.1
func (s *Server) StartWatchers()
StartWatchers starts a watcher on every configured gallery at startup. Each gallery owns its own watcher for the lifetime of the process so file drops into any gallery are picked up in real time, not just the active one.
Also spawns a pre-warm goroutine per gallery that populates the FolderTree, SourceCounts, and VisibleCount caches. The first user request then hits warm caches instead of paying a cold aggregation scan against every visible image - on libraries with tens of thousands of images that walk was the dominant contributor to first-sidebar latency.
func (*Server) SwitchGallery ¶ added in v1.1.0
SwitchGallery changes the runtime-active gallery. The change is ephemeral: the persisted default_gallery in monbooru.toml is only touched by SetDefault. Every gallery runs its own watcher for the whole process lifetime, so the swap does not stop/start watchers or trigger a sync.
type SessionStore ¶
type SessionStore struct {
// contains filtered or unexported fields
}
SessionStore is an in-memory session store.
func NewSessionStore ¶
func NewSessionStore() *SessionStore
NewSessionStore creates an empty session store.
func (*SessionStore) Clear ¶
func (s *SessionStore) Clear()
Clear removes all sessions (e.g. when password auth is disabled).
func (*SessionStore) DeleteSession ¶
func (s *SessionStore) DeleteSession(id string)
DeleteSession removes a session.
func (*SessionStore) GetSession ¶
func (s *SessionStore) GetSession(id string) (Session, bool)
GetSession returns the session for the given ID, or false if invalid/expired.
func (*SessionStore) NewSession ¶
func (s *SessionStore) NewSession(lifetimeDays int) (string, error)
NewSession creates a new session and returns its ID.
func (*SessionStore) SweepExpired ¶
func (s *SessionStore) SweepExpired()
SweepExpired removes all expired sessions.
Source Files
¶
- auth.go
- back_context.go
- ceiling.go
- csrf.go
- flash.go
- gallery_compat.go
- gallery_ctx.go
- gallery_io.go
- gallery_merge.go
- gallery_ops.go
- handlers.go
- handlers_auth.go
- handlers_autotag.go
- handlers_batch.go
- handlers_categories.go
- handlers_detail.go
- handlers_duplicates_walker.go
- handlers_gallery.go
- handlers_image_actions.go
- handlers_image_tags.go
- handlers_implications.go
- handlers_jobs.go
- handlers_maintenance.go
- handlers_manga.go
- handlers_relations.go
- handlers_relations_jobs.go
- handlers_relations_page.go
- handlers_saved_search.go
- handlers_session.go
- handlers_settings.go
- handlers_settings_tagger.go
- handlers_suggest.go
- handlers_tags.go
- jobs_runner.go
- parse.go
- router.go
- scheduler.go
- stats.go
- stats_linux.go
Directories
¶
| Path | Synopsis |
|---|---|
|
Package compatibility translates foreign gallery exports (zipped Hydrus exports, ...) into the same in-memory shape the monbooru-native light import consumes.
|
Package compatibility translates foreign gallery exports (zipped Hydrus exports, ...) into the same in-memory shape the monbooru-native light import consumes. |