Documentation
¶
Index ¶
- func IsValidEpubFlow(flow string) bool
- func IsValidEpubTheme(theme string) bool
- func IsValidFitMode(mode string) bool
- func RegisterRoutes(e *echo.Echo, db *bun.DB, authMiddleware *auth.Middleware)
- func ValidFitModes() []string
- type LibrarySettingsResponse
- type Service
- func (svc *Service) GetLibrarySettings(ctx context.Context, userID, libraryID int) (*models.UserLibrarySettings, error)
- func (svc *Service) GetViewerSettings(ctx context.Context, userID int) (*models.UserSettings, error)
- func (svc *Service) UpdateViewerSettings(ctx context.Context, userID int, update ViewerSettingsUpdate) (*models.UserSettings, error)
- func (svc *Service) UpsertLibrarySort(ctx context.Context, userID, libraryID int, sortSpec *string) (*models.UserLibrarySettings, error)
- type UpdateLibrarySettingsPayload
- type ViewerSettingsPayload
- type ViewerSettingsResponse
- type ViewerSettingsUpdate
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsValidEpubFlow ¶ added in v0.0.35
IsValidEpubFlow returns true if the flow is a supported EPUB flow mode.
func IsValidEpubTheme ¶ added in v0.0.35
IsValidEpubTheme returns true if the theme is a supported EPUB theme.
func IsValidFitMode ¶
IsValidFitMode returns true if the fit mode is valid.
func RegisterRoutes ¶
Types ¶
type LibrarySettingsResponse ¶ added in v0.0.32
type LibrarySettingsResponse struct {
SortSpec *string `json:"sort_spec"`
}
LibrarySettingsResponse is the response for GET/PUT /settings/libraries/:library_id.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
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) GetViewerSettings ¶
func (svc *Service) GetViewerSettings(ctx context.Context, userID int) (*models.UserSettings, error)
GetViewerSettings retrieves viewer settings for a user, returning defaults if none exist.
func (*Service) UpdateViewerSettings ¶
func (svc *Service) UpdateViewerSettings( ctx context.Context, userID int, update ViewerSettingsUpdate, ) (*models.UserSettings, error)
UpdateViewerSettings applies a partial update to a user's viewer 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"`
}
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 ViewerSettingsPayload ¶
type ViewerSettingsPayload struct {
PreloadCount *int `json:"preload_count,omitempty"`
FitMode *string `json:"fit_mode,omitempty"`
EpubFontSize *int `json:"viewer_epub_font_size,omitempty"`
EpubTheme *string `json:"viewer_epub_theme,omitempty"`
EpubFlow *string `json:"viewer_epub_flow,omitempty"`
}
ViewerSettingsPayload is the request body for updating viewer 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 ViewerSettingsUpdate (same field names, same types, same order) — the handler converts between them with `ViewerSettingsUpdate(payload)`. Drifting either one breaks that cast.
type ViewerSettingsResponse ¶
type ViewerSettingsResponse struct {
PreloadCount int `json:"preload_count"`
FitMode string `json:"fit_mode"`
EpubFontSize int `json:"viewer_epub_font_size"`
EpubTheme string `json:"viewer_epub_theme"`
EpubFlow string `json:"viewer_epub_flow"`
}
ViewerSettingsResponse is the response for viewer settings.
type ViewerSettingsUpdate ¶ added in v0.0.35
type ViewerSettingsUpdate struct {
PreloadCount *int
FitMode *string
EpubFontSize *int
EpubTheme *string
EpubFlow *string
}
ViewerSettingsUpdate describes a partial update to viewer 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.