Documentation
¶
Overview ¶
Package reach decides what a reading app reaches through the channels that browse a library, OPDS and the eReader browser: the Delivery Rules that pick each book's Files, the Device's scope, and which entries (libraries, a library's series and authors, a list) have anything to deliver, so both channels show the same books and leave out the same empty entries.
Index ¶
- Constants
- func DeliveredAs(rules []delivery.Rule, fileType string) []books.MainFileMatch
- func RegisterRoutes(e *echo.Group, db *bun.DB, bookService *books.Service, ...)
- type BookDelivery
- type BookDevice
- type DeliveryPreviewQuery
- type DeliveryPreviewResponse
- type EditionMove
- type LibrarySections
- type NotReceivedCount
- type Reach
- func (r *Reach) Closed() bool
- func (r *Reach) Deliverable() *lists.DeliverableBooks
- func (r *Reach) HoldsLibrary(libraryID int) bool
- func (r *Reach) LibraryIDs() []int
- func (r *Reach) LibraryScoped() bool
- func (r *Reach) ListID() *int
- func (r *Reach) ReaderID() *int
- func (r *Reach) SourceFileTypes() []string
- type Service
- func (s *Service) BookDevices(ctx context.Context, user *models.User, book *models.Book) ([]BookDevice, error)
- func (s *Service) DeliveredFileTypesWithBooks(ctx context.Context, r *Reach, opts books.ListBooksOptions) ([]string, error)
- func (s *Service) HasBooks(ctx context.Context, r *Reach, opts books.ListBooksOptions) (bool, error)
- func (s *Service) HoldsBook(ctx context.Context, r *Reach, libraryID, bookID int) (bool, error)
- func (s *Service) Libraries(ctx context.Context, r *Reach) ([]*models.Library, error)
- func (s *Service) ListBooks(ctx context.Context, r *Reach, opts books.ListBooksOptions) ([]*models.Book, int, error)
- func (s *Service) Preview(ctx context.Context, user *models.User, device *devices.Device, ...) (*DeliveryPreviewResponse, error)
- func (s *Service) Resolve(ctx context.Context, user *models.User, device *devices.Device) (*Reach, error)
- func (s *Service) Scope(ctx context.Context, user *models.User, device *devices.Device) (*Reach, error)
- func (s *Service) Sections(ctx context.Context, r *Reach, libraryID int) (LibrarySections, error)
- type TypeSwitch
Constants ¶
const ( //tygo:emit export type NotDeliveredReason = typeof NotDeliveredOutsideScope | typeof NotDeliveredNoRule; // NotDeliveredOutsideScope is a book outside the Device's scope. NotDeliveredOutsideScope = "outside_scope" // NotDeliveredNoRule is a book in scope none of whose main Files the // Device's Delivery Rules deliver. NotDeliveredNoRule = "no_rule" )
Variables ¶
This section is empty.
Functions ¶
func DeliveredAs ¶
func DeliveredAs(rules []delivery.Rule, fileType string) []books.MainFileMatch
DeliveredAs returns the book filter matching the books the rules deliver some File of as fileType (delivery.DeliveredAs).
func RegisterRoutes ¶
func RegisterRoutes(e *echo.Group, db *bun.DB, bookService *books.Service, authMiddleware *auth.Middleware)
RegisterRoutes registers the routes that show what the current user's Devices get: a book page's Devices tab, which needs books:read like the book page, and a Device's delivery preview, which like the rest of a user's own Devices needs no permission. Both are GETs, so Demo Mode lets them through.
Types ¶
type BookDelivery ¶
type BookDelivery struct {
FileID int `json:"file_id"`
SourceFileType string `json:"source_file_type" tstype:"FileType"`
DeliveredFileType string `json:"delivered_file_type" tstype:"DeliveredFileType"`
}
BookDelivery is one File a Device gets, and the File Type it gets it as.
type BookDevice ¶
type BookDevice struct {
DeviceID string `json:"device_id"`
DeviceName string `json:"device_name"`
DeviceType string `json:"device_type" tstype:"DeviceType"`
// Deliveries are the book's Files the Device gets, each with the File
// Type it gets it as. Empty when it gets none, and NotDeliveredReason
// says why.
Deliveries []BookDelivery `json:"deliveries"`
NotDeliveredReason string `json:"not_delivered_reason,omitempty" tstype:"NotDeliveredReason"`
// EditionMoves are, on a Kobo, the books on it that its next sync moves
// to another of this book's Files. The Kobo may reopen the book at the
// start.
EditionMoves []EditionMove `json:"edition_moves"`
// TypeSwitch is set, on a Kobo, when its next sync switches the book on
// it to another File Type, such as KePub to EPUB. The Kobo adds it again
// as a new book, without its reading position or highlights.
TypeSwitch *TypeSwitch `json:"type_switch,omitempty"`
}
BookDevice is what one of the current user's Devices gets of a book, for the book page's Devices tab, which lists every Device.
type DeliveryPreviewQuery ¶
type DeliveryPreviewQuery struct {
Mode string `query:"mode" json:"mode,omitempty" tstype:"DeliveryRulesMode"`
Rules string `query:"rules" json:"rules,omitempty"`
}
DeliveryPreviewQuery is the query for GET /user/devices/:id/delivery-preview. With no Mode, it previews the rules the Device follows now; with one, the rules it would follow in that mode, and Rules, read only for a custom list, are "source:delivered" pairs separated by commas, in order ("epub:kepub,cbz:epub"). It is a GET so it stays read-only in Demo Mode.
type DeliveryPreviewResponse ¶
type DeliveryPreviewResponse struct {
// ReceivedBooks counts the books it gets something of.
ReceivedBooks int `json:"received_books"`
// NotReceived counts the books it gets nothing of, by the File Types of
// their main Files, in the built-in rules' order. A book with Files of
// two types counts under both.
NotReceived []NotReceivedCount `json:"not_received"`
// MovedBooks counts, on a Kobo, the books on it the change moves to
// another edition, which may reopen at the start.
MovedBooks int `json:"moved_books"`
// RetypedBooks counts, on a Kobo, the books on it the change switches
// to another File Type, such as KePub to EPUB. They lose their reading
// position and highlights.
RetypedBooks int `json:"retyped_books"`
}
DeliveryPreviewResponse is what a Device would receive within its scope.
type EditionMove ¶
type EditionMove struct {
FromFileID *int `json:"from_file_id" tstype:"number | null"`
ToFileID int `json:"to_file_id"`
}
EditionMove is a book on a Kobo that its next sync moves from one File to another. FromFileID is null when the File it held was deleted.
type LibrarySections ¶
LibrarySections says which of a library's browsing sections have something to deliver.
type NotReceivedCount ¶
type NotReceivedCount struct {
SourceFileType string `json:"source_file_type" tstype:"FileType"`
Books int `json:"books"`
}
NotReceivedCount is how many books a Device gets nothing of that have a main File of SourceFileType.
type Reach ¶
type Reach struct {
User *models.User
// Device is nil for a request signed in without one.
Device *devices.Device
// Rules are the Delivery Rules the request follows. Scope leaves them
// nil; Resolve loads them.
Rules []delivery.Rule
// contains filtered or unexported fields
}
Reach is what one request reaches. Without a Device (OPDS signed in with the account password) that is every library the user can access, delivered by the user's default Delivery Rules. With a Device, it is the Device's rules and scope: all the owner's books, one library, or the books on one list. A scope whose library or list is gone, or that the owner can no longer see, reaches nothing, as on Kobo sync.
func (*Reach) Deliverable ¶
func (r *Reach) Deliverable() *lists.DeliverableBooks
Deliverable returns the filter that keeps lists holding a book in reach with something to deliver.
func (*Reach) HoldsLibrary ¶
HoldsLibrary reports whether books from libraryID can be in reach. A list-scoped Device holds every library the owner can access, but only the books on its list.
func (*Reach) LibraryIDs ¶
LibraryIDs returns the libraries books can come from: nil for every library, and empty for none.
func (*Reach) LibraryScoped ¶
LibraryScoped reports whether the Device is scoped to one library, even one that is gone.
func (*Reach) ReaderID ¶ added in v0.6.0
ReaderID is the id of r's user, whose reading data the reading sorts and filters read, or nil without one.
func (*Reach) SourceFileTypes ¶
SourceFileTypes returns the source File Types the rules deliver, the filter listings apply in SQL before paging so books with nothing to deliver are left out. A Reach from Scope, with no Rules loaded, returns nil, which filters nothing; rules that deliver nothing return an empty list, which matches no book.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service resolves Reaches and answers what is in them.
func NewService ¶
NewService returns a Service. bookService is the shared books service.
func (*Service) BookDevices ¶
func (s *Service) BookDevices(ctx context.Context, user *models.User, book *models.Book) ([]BookDevice, error)
BookDevices returns what each of user's Devices gets of book, which must be loaded with its Files. The caller checks the user's library access.
func (*Service) DeliveredFileTypesWithBooks ¶
func (s *Service) DeliveredFileTypesWithBooks(ctx context.Context, r *Reach, opts books.ListBooksOptions) ([]string, error)
DeliveredFileTypesWithBooks returns the File Types, in rule order, that the rules deliver some book opts matches in reach as, so a type filter offers only types that match something. It runs one query per distinct delivered File Type, a handful at most, rather than one query that resolves every book.
func (*Service) HasBooks ¶
func (s *Service) HasBooks(ctx context.Context, r *Reach, opts books.ListBooksOptions) (bool, error)
HasBooks reports whether opts, narrowed to what r reaches, matches a book with something to deliver.
func (*Service) HoldsBook ¶
HoldsBook reports whether bookID, in libraryID, is in reach. The caller checks the user's own library access first.
func (*Service) Libraries ¶
Libraries returns the libraries in reach that have a book with something to deliver, so a channel never lists one that opens empty. One query finds them, however many libraries there are.
func (*Service) ListBooks ¶ added in v0.6.0
func (s *Service) ListBooks(ctx context.Context, r *Reach, opts books.ListBooksOptions) ([]*models.Book, int, error)
ListBooks returns a page of the books opts matches, narrowed to what r reaches, and how many there are in all.
func (*Service) Preview ¶
func (s *Service) Preview(ctx context.Context, user *models.User, device *devices.Device, rules []delivery.Rule) (*DeliveryPreviewResponse, error)
Preview returns what device would receive within its scope under rules: how many books it gets something of, how many it gets nothing of by File Type, and, on a Kobo, how many books already on it would move to another edition or File Type.
func (*Service) Resolve ¶
func (s *Service) Resolve(ctx context.Context, user *models.User, device *devices.Device) (*Reach, error)
Resolve returns what user reaches through device (nil for no Device), with the Delivery Rules it follows: the Device's, or the user's default.
type TypeSwitch ¶
type TypeSwitch struct {
FromFileType string `json:"from_file_type" tstype:"DeliveredFileType"`
ToFileType string `json:"to_file_type" tstype:"DeliveredFileType"`
}
TypeSwitch is a book on a Kobo moving from one delivered File Type to another.