reader

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: GPL-3.0 Imports: 23 Imported by: 0

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

View Source
const (
	OriginSource = "source"
	OriginFile   = "file"
)

Origins of pages.

View Source
const MaxPageBytes = plugins.MaxImageBytes

MaxPageBytes caps one page image.

View Source
const MaxSettingsBytes = 16 << 10

MaxSettingsBytes caps one level of reader settings or the preferences.

Variables

View Source
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.

View Source
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>.

View Source
var ErrTooLarge = fmt.Errorf("reader: settings larger than %d bytes", MaxSettingsBytes)

ErrTooLarge is settings over MaxSettingsBytes.

Functions

func Scope

func Scope(sourceID string, workID *uuid.UUID) string

Scope names a settings level.

func ValidScope

func ValidScope(scope string) error

ValidScope checks a settings level's name.

Types

type Files

type Files interface {
	Open(ctx context.Context, chapterID uuid.UUID) (*downloads.File, error)
}

Files opens downloaded chapters.

type HistoryItem

type HistoryItem struct {
	Progress     db.Progress
	Chapter      db.Chapter
	WorkTitle    string
	WorkCoverURL string
}

HistoryItem is a chapter a user read.

type HistoryQuery

type HistoryQuery struct {
	PerSeries bool
	WorkID    uuid.UUID
	Title     string
}

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

func (s *Service) Bookmarks(ctx context.Context, userID, workID uuid.UUID) ([]uuid.UUID, error)

Bookmarks lists a user's bookmarked chapters of a work, oldest bookmark first.

func (*Service) ClearHistory

func (s *Service) ClearHistory(ctx context.Context, userID uuid.UUID) error

ClearHistory takes everything a user read up to now out of their history (read marks stay).

func (*Service) DeleteSettings

func (s *Service) DeleteSettings(ctx context.Context, userID uuid.UUID, scope string) error

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

func (s *Service) HideHistory(ctx context.Context, userID, workID uuid.UUID) error

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

func (s *Service) Preferences(ctx context.Context, userID uuid.UUID) (map[string]any, error)

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) SetFiles

func (s *Service) SetFiles(f Files)

SetFiles lets the reader serve downloaded chapters from their files.

func (*Service) SetPreferences

func (s *Service) SetPreferences(ctx context.Context, userID uuid.UUID, prefs map[string]any) error

SetPreferences replaces a user's app preferences.

func (*Service) SetProgress

func (s *Service) SetProgress(ctx context.Context, v library.Viewer, chapterID uuid.UUID, page int32, pages *int32, completed *bool) (db.Progress, error)

SetProgress records where v is in a chapter. Reaching the last page (when the page count is known) marks it read.

func (*Service) WorkProgress

func (s *Service) WorkProgress(ctx context.Context, v library.Viewer, workID uuid.UUID) ([]db.Progress, *uuid.UUID, error)

WorkProgress returns v's progress in a work, and where to continue: the chapter last read, or the next one when that was finished.

type Settings

type Settings struct {
	Global, Source, Work map[string]any
	Effective            map[string]any
}

Settings are a user's reader settings for one place: each level, and the effective result (global, then the source's, then the work's, each key of a more specific level winning).

Jump to

Keyboard shortcuts

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