Documentation
¶
Overview ¶
Package config loads shelf's TOML configuration and resolves the XDG directories shelf reads and writes.
Index ¶
- Constants
- type Config
- type Convert
- type Device
- type Duration
- type Kosync
- type OPDS
- type Paths
- func (p Paths) ConfigFile() string
- func (p Paths) DeviceStateDir() string
- func (p Paths) DeviceStateFile(uuid string) string
- func (p Paths) EnsureDirs() error
- func (p Paths) IndexFile() string
- func (p Paths) LogFile() string
- func (p Paths) OptimizedDir() string
- func (p Paths) ProgressFile() string
- func (p Paths) ShelvesFile() string
- type Sync
- type Transport
- type UI
Constants ¶
const ( MinChunkSize = 4 * 1024 MaxChunkSize = 15 * 1024 DefaultChunkSize = 8 * 1024 )
Chunk size bounds. The device runs on an ESP32-C3 with roughly 380 KB of usable RAM and a 4 KB write buffer, so oversized chunks are a real failure mode rather than a tuning inefficiency.
These mirror internal/device: the device refuses frames above ~15 KB, so a config that validated a larger value would pass here and fail at upload.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
LibraryRoot string `toml:"library_root"`
Inbox string `toml:"inbox"`
NamingTemplate string `toml:"naming_template"`
UI UI `toml:"ui"`
Kosync Kosync `toml:"kosync"`
OPDS OPDS `toml:"opds"`
Devices []Device `toml:"device"`
Convert Convert `toml:"convert"`
Sync Sync `toml:"sync"`
// Paths is resolved at load time, not read from the file.
Paths Paths `toml:"-"`
}
Config is the parsed contents of config.toml.
func Default ¶
func Default() Config
Default returns the configuration shelf uses when no file exists.
func Load ¶
Load reads config.toml from the standard location. A missing file is not an error: shelf works out of the box against ~/Books.
func LoadFile ¶
LoadFile reads a specific config file. Exported so tests and --config can point at an arbitrary path.
func (*Config) DeviceByName ¶
DeviceByName returns the named device, or the only configured device when name is empty. Ambiguity is an error rather than a silent guess: picking the wrong device means writing books to hardware the user did not mean.
func (*Config) DeviceNames ¶
DeviceNames lists configured device nicknames in file order.
type Device ¶
type Device struct {
Nickname string `toml:"nickname"`
Host string `toml:"host"` // empty triggers discovery
Root string `toml:"root"` // device-side path, always forward-slash
Transport Transport `toml:"transport"`
ChunkSize int `toml:"chunk_size"`
Optimize bool `toml:"optimize"`
Profile string `toml:"profile"`
Mount string `toml:"mount"` // SD transport only
}
Device describes one configured e-reader.
type Duration ¶
Duration wraps time.Duration so TOML can carry human strings like "150ms".
func (Duration) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*Duration) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler for TOML decoding.
type Kosync ¶
type Kosync struct {
// User is whose progress the library table shows. Empty disables the
// percentage column rather than guessing between accounts.
User string `toml:"user"`
// Listen is the default address for `shelf serve`.
Listen string `toml:"listen"`
}
Kosync configures reading-progress sync.
The device pushes progress to a kosync server; shelf runs one with `shelf serve` and reads from the same store to show percentages.
type OPDS ¶
type OPDS struct {
// Title names the catalog in the reader's server list and in every feed.
Title string `toml:"title"`
// PageSize is how many entries a feed carries. Clamped to what the
// firmware's parser will actually read; see internal/opds/compat.go.
PageSize int `toml:"page_size"`
// Anonymous serves the catalog without a password. Off by default: the
// listener binds to every interface, and the accounts already exist.
Anonymous bool `toml:"anonymous"`
// Disabled turns the catalog off, leaving progress sync running.
Disabled bool `toml:"disabled"`
}
OPDS configures the catalog served by `shelf serve`.
type Paths ¶
type Paths struct {
Config string // config.toml, shelves.toml
Data string // index.db
State string // devices/<uuid>.json, shelf.log
Cache string // optimized/, cover thumbnails
}
Paths resolves every directory shelf writes to.
func DefaultPaths ¶
DefaultPaths resolves the standard locations for the current user.
func (Paths) DeviceStateDir ¶
DeviceStateDir holds per-device sync manifests, one JSON file per device UUID.
func (Paths) DeviceStateFile ¶
DeviceStateFile is the local manifest for a single device.
func (Paths) EnsureDirs ¶
EnsureDirs creates every directory shelf writes to.
func (Paths) OptimizedDir ¶
OptimizedDir caches device-targeted EPUB builds, keyed by (sha256, profile).
func (Paths) ProgressFile ¶
ProgressFile is the reading-progress store.
Under Data rather than Cache deliberately: unlike index.db, this cannot be rebuilt from anything. The device pushes reading positions here and keeps no synchronised copy, so deleting it loses where you are in every book.
func (Paths) ShelvesFile ¶
ShelvesFile is the authoritative, human-editable record of shelf definitions. The SQLite index is a cache and may be deleted at any time; this file is the one piece of state that cannot be reconstructed by rescanning the library.
type Sync ¶
type Sync struct {
InterOpDelay Duration `toml:"inter_op_delay"`
MaxRetries int `toml:"max_retries"`
Prune bool `toml:"prune"`
}
Sync tunes the transfer executor.