instancesettings

package
v0.60.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package instancesettings is the one list of the instance's settings that lived in the environment alone until 0.57 and are now rows of the settings table, changed on the admin panel (task #258, the owner's grouping of 2026-10-15): the default language, the sync interval, the upload staging time, the file cache, the apps' size limits, co-editing, the thumbnail cache sweep, the webhooks' language and the notifications switch.

One resolution order

stored row (settings table)  →  the environment / config.yaml, on a start
where no row exists yet  →  the built-in default

It is package dbsetting's order (seed, never override), applied to values the CONFIGURATION already holds: config.Load has merged the variable over the config.yaml key over the default, so a start that has no row writes what the configuration says - only when it says something other than the default, so a row never pins a default a later release might change (dbsetting seedvalue.go). From then on the row wins and the variable is inert; `filex settings reseed` is the explicit way to write the configuration's value again (Reseed). A start whose configuration says something the row overrules says so in the log, once per setting (Drifts): the variable is not read again, and nothing else would tell the operator who changed it.

Read at start, said on the page

Every setting here is read where the server is wired (Boot writes the value in force into the Config every consumer is built from), so a change applies at the next start - except the few with a live hook (SetLive). The page is told which ones wait (`restart_pending`: the stored value differs from the one this process started with), the way the Protection page says it for the antivirus switch.

One list

The admin page draws a card per group from this list (GET/PATCH /api/admin/instance-settings), the panel's search finds every row, the docs list every variable: a setting added here is added everywhere.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Boot

func Boot(ctx context.Context, st dbsetting.Store, cfg *config.Config)

Boot seeds every setting the configuration sets, on a start where its row does not exist yet, then writes the value in force into cfg - the one place every consumer below reads it from. Call once, after the migrations and before anything is built from cfg.

⚠ A failed seed is not fatal (dbsetting.SeedAll's rule): the default, or the configuration's own value when the store cannot be read, stays in force.

func Drifts

func Drifts(ctx context.Context, g dbsetting.Getter, cfg *config.Config) []dbsetting.Drift

Drifts answers the settings whose configuration says something the stored row overrules: the variable (or the config.yaml key) is set, the row holds a value, and the two differ in the form the row stores. A variable set to the default counts too - an operator who wrote FILEX_SYNC_INTERVAL=15m expects 15 minutes whatever the row says.

func Reseed

func Reseed(ctx context.Context, st dbsetting.Store, cfg *config.Config, keys []string) ([]string, error)

Reseed writes the CONFIGURATION's value of the named settings (every one, when keys is empty) over whatever is stored - the explicit way back to what the environment or config.yaml says, since a start no longer does it on its own (`filex settings reseed`). A setting the configuration leaves at its default is reset to the default (its row removed in effect: written as empty, which every spec reads as "not set"). It answers what it wrote.

func SetLive

func SetLive(key string, fn func(context.Context, any))

SetLive registers what applies a new value of key at once. A setting with a live hook is never "waiting for a restart".

func Write

func Write(ctx context.Context, st dbsetting.Store, patch map[string]json.RawMessage) ([]string, error)

Write checks every value in patch, and stores them only when all of them are good: one bad field refuses the whole save, before anything is written. A setting with a live hook is applied at once. It answers the keys written.

Types

type FieldError

type FieldError struct {
	Key string
	// Code: "range" (an int outside Min..Max), "type" (not a number / not a
	// switch / not text), "language" (not a language tag), "unknown" (no such
	// setting).
	Code     string
	English  string
	Min, Max int
}

FieldError is a value the page sent that cannot be stored, with what the page needs to say why next to the field.

func (*FieldError) Error

func (e *FieldError) Error() string

type Group

type Group string

Group is the admin page whose card draws the setting.

const (
	// GroupGeneral: Admin → Settings → General.
	GroupGeneral Group = "general"
	// GroupProtection: Admin → Settings → Protection.
	GroupProtection Group = "protection"
	// GroupApps: Admin → Settings → Plugins (the apps' limits, co-editing).
	GroupApps Group = "apps"
	// GroupNotifications: Admin → Settings → Notifications.
	GroupNotifications Group = "notifications"
	// GroupWebhooks: Admin → Settings → Webhooks.
	GroupWebhooks Group = "webhooks"
	// GroupConnections: Admin → Settings → Login security, the card about the
	// protocols filex serves itself. Its own card: it was first drawn under
	// "Before a file is overwritten", where a TLS row reads as nonsense.
	GroupConnections Group = "connections"
)

type Item

type Item struct {
	Key     string `json:"key"`
	Group   Group  `json:"group"`
	Kind    Kind   `json:"kind"`
	Value   any    `json:"value"`
	Default any    `json:"default"`
	Min     *int   `json:"min,omitempty"`
	Max     *int   `json:"max,omitempty"`
	Unit    string `json:"unit,omitempty"`
	// Env is the variable that gave the setting its first value.
	Env string `json:"env,omitempty"`
	// Restart: a change applies at the next start; RestartPending: one is
	// waiting (the stored value is not the one this process started with).
	Restart        bool `json:"restart"`
	RestartPending bool `json:"restart_pending"`
	// SecurityOff: see Setting.SecurityOff.
	SecurityOff bool `json:"security_off,omitempty"`
}

Item is one setting as the page reads it.

func Items

func Items(ctx context.Context, g dbsetting.Getter, group string) []Item

Items reads the settings of one group ("" = every group), as in force.

type Kind

type Kind string

Kind is how the page draws the setting.

const (
	KindInt  Kind = "int"
	KindBool Kind = "bool"
	// KindLanguage: a language tag, or "" for the setting's own fallback
	// (the browser's language, the instance's default language).
	KindLanguage Kind = "language"
)

type Setting

type Setting struct {
	Key   string
	Group Group
	Kind  Kind
	// EnvVar and ConfigKey name where the first value came from - shown on
	// the page and in the docs.
	EnvVar    string
	ConfigKey string
	// Unit names what an int counts ("minutes", "hours", "days", "MB", "GB").
	Unit string
	// Restart: read where the server is wired; a change applies at the next
	// start unless a live hook is registered for the key (SetLive).
	Restart bool
	// SecurityOff: on, this takes a protection away. The page draws the one
	// warning under it, with the row's own `risk` text.
	SecurityOff bool
	// contains filtered or unexported fields
}

Setting is one row of the list.

func All

func All() []Setting

All is the list, in order.

func ByKey

func ByKey(key string) (Setting, bool)

ByKey finds one setting.

func (Setting) Bounds

func (s Setting) Bounds() (min, max int)

Bounds are an int's limits; zeros for the other kinds.

func (Setting) Canonical

func (s Setting) Canonical(raw json.RawMessage) (string, any, *FieldError)

Canonical checks one value the page sent and answers the text to store.

func (Setting) Default

func (s Setting) Default() any

Default is the built-in value, in the setting's type.

func (Setting) Resolve

func (s Setting) Resolve(ctx context.Context, g dbsetting.Getter) any

Resolve reads the value in force: the stored row, else the default.

Jump to

Keyboard shortcuts

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