settings

package
v0.0.49 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsValidEpubFlow added in v0.0.35

func IsValidEpubFlow(flow string) bool

IsValidEpubFlow returns true if the flow is a supported EPUB flow mode.

func IsValidEpubTheme added in v0.0.35

func IsValidEpubTheme(theme string) bool

IsValidEpubTheme returns true if the theme is a supported EPUB theme.

func IsValidFitMode

func IsValidFitMode(mode string) bool

IsValidFitMode returns true if the fit mode is valid.

func IsValidGallerySize added in v0.0.39

func IsValidGallerySize(size string) bool

IsValidGallerySize returns true if the size is a supported gallery size.

func IsValidPlaybackSpeed added in v0.0.47

func IsValidPlaybackSpeed(speed float64) bool

IsValidPlaybackSpeed returns true if the speed is one of the allowed discrete playback speed steps. Exact float comparison is safe here: every allowed step is a multiple of 0.25, which is exactly representable in binary floating point, so a JSON-decoded step compares equal to the constant.

func RegisterRoutes

func RegisterRoutes(e *echo.Echo, db *bun.DB, authMiddleware *auth.Middleware)

func ValidFitModes

func ValidFitModes() []string

ValidFitModes returns all valid fit mode values.

Types

type LibrarySettingsResponse added in v0.0.32

type LibrarySettingsResponse struct {
	SortSpec *string `json:"sort_spec" tstype:"string | null"`
}

LibrarySettingsResponse is the response for GET/PUT /settings/libraries/:library_id.

type PutReviewCriteriaPayload added in v0.0.47

type PutReviewCriteriaPayload struct {
	BookFields     []string `json:"book_fields" validate:"required"`
	AudioFields    []string `json:"audio_fields" validate:"required"`
	ClearOverrides bool     `json:"clear_overrides"`
}

PutReviewCriteriaPayload is the request body for PUT /settings/review-criteria.

type ReviewCriteriaResponse added in v0.0.47

type ReviewCriteriaResponse struct {
	BookFields          []string `json:"book_fields"`
	AudioFields         []string `json:"audio_fields"`
	UniversalCandidates []string `json:"universal_candidates"`
	AudioCandidates     []string `json:"audio_candidates"`
	OverrideCount       int      `json:"override_count"`
	MainFileCount       int      `json:"main_file_count"`
}

ReviewCriteriaResponse is the response for GET /settings/review-criteria.

type Service

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

func NewService

func NewService(db *bun.DB) *Service

func (*Service) GetLibrarySettings added in v0.0.32

func (svc *Service) GetLibrarySettings(ctx context.Context, userID, libraryID int) (*models.UserLibrarySettings, error)

GetLibrarySettings returns the (user, library) settings row, or nil when no row exists. The nil-return form (rather than a zero-valued struct) makes callers' "no preference" checks explicit.

func (*Service) GetUserSettings added in v0.0.39

func (svc *Service) GetUserSettings(ctx context.Context, userID int) (*models.UserSettings, error)

GetUserSettings retrieves user settings for a user, returning defaults if none exist.

func (*Service) UpdateUserSettings added in v0.0.39

func (svc *Service) UpdateUserSettings(
	ctx context.Context,
	userID int,
	update UserSettingsUpdate,
) (*models.UserSettings, error)

UpdateUserSettings applies a partial update to a user's settings, creating a row if none exists. Runs in a transaction so that the read-current-then-write-merged sequence is atomic — otherwise two concurrent updates from the same user (rapid toggles in one tab, or two tabs racing) could lose one of the writes.

func (*Service) UpsertLibrarySort added in v0.0.32

func (svc *Service) UpsertLibrarySort(ctx context.Context, userID, libraryID int, sortSpec *string) (*models.UserLibrarySettings, error)

UpsertLibrarySort writes just the sort_spec column for (userID, libraryID). sortSpec may be nil to clear the saved default. Other columns on the row (when they exist in a future version) are left untouched by the ON CONFLICT update.

type UpdateLibrarySettingsPayload added in v0.0.32

type UpdateLibrarySettingsPayload struct {
	SortSpec *string `json:"sort_spec" validate:"omitempty,max=200" tstype:"string | null"`
}

UpdateLibrarySettingsPayload is the request body for PUT /settings/libraries/:library_id.

SortSpec is a pointer so the client can distinguish "unset" (omit field from JSON) from "clear the saved default" (send null). A null body clears the saved sort; omitting the field leaves it untouched.

max=200 caps the input length defensively at bind time. The longest possible legitimate spec — every field at the longest direction — fits comfortably under 200 chars (sortspec.MaxLevels=10), so 200 is a generous upper bound that still rejects pathological input before it reaches sortspec.Parse.

type UserSettingsPayload added in v0.0.39

type UserSettingsPayload struct {
	PreloadCount  *int     `json:"preload_count,omitempty"`
	FitMode       *string  `json:"fit_mode,omitempty" tstype:"FitMode"`
	EpubFontSize  *int     `json:"viewer_epub_font_size,omitempty"`
	EpubTheme     *string  `json:"viewer_epub_theme,omitempty" tstype:"EpubTheme"`
	EpubFlow      *string  `json:"viewer_epub_flow,omitempty" tstype:"EpubFlow"`
	GallerySize   *string  `json:"gallery_size,omitempty" tstype:"GallerySize"`
	HideChrome    *bool    `json:"viewer_hide_chrome,omitempty"`
	PlaybackSpeed *float64 `json:"viewer_playback_speed,omitempty" tstype:"PlaybackSpeed"`
}

UserSettingsPayload is the request body for updating user settings.

All fields are pointers so clients can send partial updates. Omitting a field (or sending it as null) leaves the current value untouched; sending a value updates just that field.

Field shape must stay identical to UserSettingsUpdate (same field names, same types, same order) — the handler converts between them with `UserSettingsUpdate(payload)`. Drifting either one breaks that cast.

type UserSettingsResponse added in v0.0.39

type UserSettingsResponse struct {
	PreloadCount  int     `json:"preload_count"`
	FitMode       string  `json:"fit_mode" tstype:"FitMode"`
	EpubFontSize  int     `json:"viewer_epub_font_size"`
	EpubTheme     string  `json:"viewer_epub_theme" tstype:"EpubTheme"`
	EpubFlow      string  `json:"viewer_epub_flow" tstype:"EpubFlow"`
	GallerySize   string  `json:"gallery_size" tstype:"GallerySize"`
	HideChrome    bool    `json:"viewer_hide_chrome"`
	PlaybackSpeed float64 `json:"viewer_playback_speed" tstype:"PlaybackSpeed"`
}

UserSettingsResponse is the response for user settings.

type UserSettingsUpdate added in v0.0.39

type UserSettingsUpdate struct {
	PreloadCount  *int
	FitMode       *string
	EpubFontSize  *int
	EpubTheme     *string
	EpubFlow      *string
	GallerySize   *string
	HideChrome    *bool
	PlaybackSpeed *float64
}

UserSettingsUpdate describes a partial update to user settings. Any field left nil is left untouched; fields set to a non-nil value are persisted. This lets clients change one setting without having to read and echo every other setting first.

Jump to

Keyboard shortcuts

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