Documentation
¶
Overview ¶
Package reader serves what the reader needs: a chapter's pages (from the chosen copy's source, through its plugin), the neighbouring chapters, reading progress synced across devices, history, and each user's reader settings and app preferences.
Index ¶
- Constants
- Variables
- func Scope(sourceID string, workID *uuid.UUID) string
- func ValidScope(scope string) error
- type Files
- type HistoryItem
- type HistoryQuery
- type Page
- type Pages
- type ReadingStats
- type Service
- func (s *Service) BookmarkCounts(ctx context.Context, userID uuid.UUID, workIDs []uuid.UUID) (map[uuid.UUID]int64, error)
- func (s *Service) Bookmarks(ctx context.Context, userID, workID uuid.UUID) ([]uuid.UUID, error)
- func (s *Service) ClearHistory(ctx context.Context, userID uuid.UUID) error
- func (s *Service) DeleteSettings(ctx context.Context, userID uuid.UUID, scope string) error
- func (s *Service) GetSettings(ctx context.Context, userID uuid.UUID, sourceID string, workID *uuid.UUID) (Settings, error)
- func (s *Service) HideHistory(ctx context.Context, userID, workID uuid.UUID) error
- func (s *Service) History(ctx context.Context, userID uuid.UUID, q HistoryQuery, before *db.Progress, ...) ([]HistoryItem, error)
- func (s *Service) LibraryStats(ctx context.Context, userID uuid.UUID, workIDs []uuid.UUID) (map[uuid.UUID]ReadingStats, error)
- func (s *Service) Locate(ctx context.Context, v library.Viewer, chapterID uuid.UUID) (db.Work, db.Chapter, error)
- func (s *Service) MarkRead(ctx context.Context, v library.Viewer, workID uuid.UUID, ...) error
- func (s *Service) Page(ctx context.Context, v library.Viewer, chapterID uuid.UUID, ...) (string, []byte, error)
- func (s *Service) Pages(ctx context.Context, v library.Viewer, chapterID uuid.UUID, ...) (Pages, error)
- func (s *Service) Preferences(ctx context.Context, userID uuid.UUID) (map[string]any, error)
- func (s *Service) PutSettings(ctx context.Context, userID uuid.UUID, scope string, settings map[string]any) error
- func (s *Service) SetBookmarks(ctx context.Context, v library.Viewer, workID uuid.UUID, ...) ([]uuid.UUID, error)
- func (s *Service) SetFiles(f Files)
- func (s *Service) SetPreferences(ctx context.Context, userID uuid.UUID, prefs map[string]any) error
- func (s *Service) SetProgress(ctx context.Context, v library.Viewer, chapterID uuid.UUID, page int32, ...) (db.Progress, error)
- func (s *Service) WorkProgress(ctx context.Context, v library.Viewer, workID uuid.UUID) ([]db.Progress, *uuid.UUID, error)
- type Settings
Constants ¶
const ( OriginSource = "source" OriginFile = "file" )
Origins of pages.
const MaxPageBytes = plugins.MaxImageBytes
MaxPageBytes caps one page image.
const MaxSettingsBytes = 16 << 10
MaxSettingsBytes caps one level of reader settings or the preferences.
Variables ¶
var ( ErrNotImage = errors.New("reader: the page isn't a supported image") ErrNotFound = errors.New("reader: not found") ErrNoCopy = errors.New("reader: no copy of this chapter on a source you may use") ErrPageNotFound = errors.New("reader: no such page") )
Errors callers map to responses.
var ErrBadScope = errors.New("reader: the level must be global, source:<id> or work:<id>")
ErrBadScope is a settings level that isn't global, source:<id> or work:<id>.
var ErrTooLarge = fmt.Errorf("reader: settings larger than %d bytes", MaxSettingsBytes)
ErrTooLarge is settings over MaxSettingsBytes.
Functions ¶
Types ¶
type HistoryItem ¶
type HistoryItem struct {
Progress db.Progress
Chapter db.Chapter
WorkTitle string
WorkCoverURL string
}
HistoryItem is a chapter a user read.
type HistoryQuery ¶
HistoryQuery narrows a user's history: one entry per series (the latest chapter read), one series, or series whose title has Title.
type Page ¶
type Page struct {
Index int
// contains filtered or unexported fields
}
Page is one page of a chapter.
type Pages ¶
type Pages struct {
WorkID uuid.UUID
Chapter chapters.Chapter
Variant chapters.VariantView
Origin string
Pages []Page
Prev *uuid.UUID
Next *uuid.UUID
// Progress is the viewer's, if they started the chapter.
Progress *db.Progress
}
Pages is what the reader shows for a chapter.
type ReadingStats ¶
type ReadingStats struct {
// Chapters and Unread count available chapters (all, and those not
// finished); Downloaded those stored.
Chapters, Unread, Downloaded int64
// Started: the user read some of it.
Started bool
// LastReadAt is when the user last read in it; LatestChapterAt when
// its newest chapter came out (or was first seen).
LastReadAt, LatestChapterAt *time.Time
// Continue is the chapter "Continue" opens.
Continue *uuid.UUID
}
ReadingStats is a user's reading of one work, for the library.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service serves the reader.
func NewService ¶
func NewService(st *store.Store, host *plugins.Host, lib *library.Service, chs *chapters.Service, lim *limits.Registry, hub *events.Hub, log *slog.Logger) *Service
NewService returns the reader service.
func (*Service) BookmarkCounts ¶
func (s *Service) BookmarkCounts(ctx context.Context, userID uuid.UUID, workIDs []uuid.UUID) (map[uuid.UUID]int64, error)
BookmarkCounts counts a user's bookmarks per work.
func (*Service) Bookmarks ¶
Bookmarks lists a user's bookmarked chapters of a work, oldest bookmark first.
func (*Service) ClearHistory ¶
ClearHistory takes everything a user read up to now out of their history (read marks stay).
func (*Service) DeleteSettings ¶
DeleteSettings removes one level (back to the less specific ones).
func (*Service) GetSettings ¶
func (s *Service) GetSettings(ctx context.Context, userID uuid.UUID, sourceID string, workID *uuid.UUID) (Settings, error)
GetSettings returns the settings that apply to reading a work from a source (both optional).
func (*Service) HideHistory ¶
HideHistory takes a series out of a user's history up to now (its read marks stay); reading it again brings it back.
func (*Service) History ¶
func (s *Service) History(ctx context.Context, userID uuid.UUID, q HistoryQuery, before *db.Progress, limit int) ([]HistoryItem, error)
History returns a user's recently read chapters, newest first, before a cursor.
func (*Service) LibraryStats ¶
func (s *Service) LibraryStats(ctx context.Context, userID uuid.UUID, workIDs []uuid.UUID) (map[uuid.UUID]ReadingStats, error)
LibraryStats is a user's reading of some works, in a few queries.
func (*Service) Locate ¶
func (s *Service) Locate(ctx context.Context, v library.Viewer, chapterID uuid.UUID) (db.Work, db.Chapter, error)
Locate returns a chapter v may see and its work: what a reader that couldn't load the chapter offers to go back to.
func (*Service) MarkRead ¶
func (s *Service) MarkRead(ctx context.Context, v library.Viewer, workID uuid.UUID, chapterIDs []uuid.UUID, read bool) error
MarkRead marks chapters of a work read (or unread: forgets progress).
func (*Service) Page ¶
func (s *Service) Page(ctx context.Context, v library.Viewer, chapterID uuid.UUID, variantID *uuid.UUID, index int) (string, []byte, error)
Page returns one page image: from the downloaded file when there is one (unless a copy is asked for), else through the copy's source.
func (*Service) Pages ¶
func (s *Service) Pages(ctx context.Context, v library.Viewer, chapterID uuid.UUID, variantID *uuid.UUID) (Pages, error)
Pages returns what the reader shows for a chapter: from its downloaded file when there is one (unless a copy is asked for), else from a source.
func (*Service) Preferences ¶
Preferences returns a user's app preferences ({} when none).
func (*Service) PutSettings ¶
func (s *Service) PutSettings(ctx context.Context, userID uuid.UUID, scope string, settings map[string]any) error
PutSettings replaces one level.
func (*Service) SetBookmarks ¶
func (s *Service) SetBookmarks(ctx context.Context, v library.Viewer, workID uuid.UUID, chapterIDs []uuid.UUID, on bool) ([]uuid.UUID, error)
SetBookmarks bookmarks chapters of a work for v, or removes their bookmarks, and returns the work's bookmarked chapters.
func (*Service) SetPreferences ¶
SetPreferences replaces a user's app preferences.