Documentation
¶
Overview ¶
Package chapters builds each work's unified chapter list. Every attached series' chapters are kept as the source lists them (the per-source view); chapters with the same number across sources become one canonical chapter with a chosen variant, so gaps in one source are filled from another. Update checks refresh the lists on a schedule and on demand.
Index ¶
- Constants
- Variables
- func DisplayTitle(name string) string
- func Label(number *float64, volume, name string) string
- func NumberOf(number *float64, name string) *float64
- func VolumeOf(volume, name string) string
- type Chapter
- type CheckState
- type Choice
- type Detail
- type Group
- type Parsed
- type Service
- func (s *Service) ChecksOf(ctx context.Context, workIDs []uuid.UUID) (CheckState, error)
- func (s *Service) Get(ctx context.Context, workID, chapterID, userID uuid.UUID) (Detail, error)
- func (s *Service) List(ctx context.Context, workID, userID uuid.UUID) ([]Chapter, error)
- func (s *Service) MarkSeen(ctx context.Context, userID, workID uuid.UUID) (bool, error)
- func (s *Service) NewCounts(ctx context.Context, userID uuid.UUID, workIDs []uuid.UUID) (map[uuid.UUID]int64, error)
- func (s *Service) OnNewChapters(f func(ctx context.Context, workID uuid.UUID, chapterIDs []uuid.UUID))
- func (s *Service) Pin(ctx context.Context, chapterID uuid.UUID, variantID *uuid.UUID) (db.Chapter, error)
- func (s *Service) QueueUpdate(ctx context.Context, se db.SourceSeries, by uuid.UUID, priority int32, ...) (db.Task, error)
- func (s *Service) Refresh(ctx context.Context, workID, by uuid.UUID) (int, error)
- func (s *Service) RefreshWorks(ctx context.Context, workIDs []uuid.UUID, by uuid.UUID) (int, error)
- func (s *Service) ScheduleAll(ctx context.Context, spread time.Duration) (int, error)
- func (s *Service) SeriesAttached(ctx context.Context, se db.SourceSeries)
- func (s *Service) SeriesChapters(ctx context.Context, workID, seriesID uuid.UUID) (db.SourceSeries, []db.SourceChapter, error)
- func (s *Service) SourcesChanged(ctx context.Context, sourceIDs []string)
- func (s *Service) Unify(ctx context.Context, workID uuid.UUID) (int, error)
- func (s *Service) UnifyAll(ctx context.Context) (int, error)
- func (s *Service) Updates(ctx context.Context, userID uuid.UUID, workIDs []uuid.UUID, ...) ([]Update, error)
- func (s *Service) WorkChanged(ctx context.Context, workID uuid.UUID)
- type Update
- type UpdateCursor
- type Variant
- type VariantView
Constants ¶
const ( ReasonPinned = "pinned" ReasonOnlySource = "only_source" ReasonLanguage = "language" ReasonHealthier = "healthier_source" ReasonPriority = "priority" ReasonNewest = "newest_upload" ReasonFirstListed = "first_listed" )
Reasons a variant was chosen.
const KindUpdateSeries = "update.series"
KindUpdateSeries checks one attached series for chapters.
Variables ¶
var ( ErrNotFound = errors.New("chapters: not found") ErrNotThisChapter = errors.New("chapters: the variant isn't a copy of this chapter") )
Errors callers map to responses.
Functions ¶
func DisplayTitle ¶
DisplayTitle is a chapter's own name for showing, without its number, volume or scanlator noise; empty when the name has nothing else.
func Label ¶
Label names a chapter for showing on its own: "Vol. 2 Chapter 15: Rain", "Chapter 3", or an extra's own name.
func NumberOf ¶
NumberOf is a variant's chapter number: the source's, or one read from its name ("Chapter 12.5", "Ch. 3", "#7", "12"; see Parse). Negative numbers mean unknown. Extras (a name starting with "Side Story", "Special", "Extra", "Notice", …) have none: they stand apart from the numbered run, whatever number the source gives them.
Types ¶
type Chapter ¶
type Chapter struct {
db.Chapter
Chosen *VariantView
Variants int
// New: found after the user last looked at the work.
New bool
}
Chapter is a canonical chapter as a user sees it.
type CheckState ¶
type CheckState struct {
// LastCheckedAt is the latest check of any of their series; nil when
// none was checked yet.
LastCheckedAt *time.Time
// Checking counts checks running or due now; Failing, series whose
// last check failed.
Checking, Failing int
}
CheckState is how the chapter checks of some works stand.
type Choice ¶
Choice is the variant chosen for a chapter and why.
func Choose ¶
Choose picks a group's preferred variant: a pinned one that still exists and is on a usable source (or nothing else is); else a usable source over an unusable one (turned off, no longer listed), then by preferred language (languages, in order; others after), a healthy source over a failing one, the series' priority, the newest upload, then the source's own order. The reason is the first of these that set the winner apart from the runner-up (an unusable source losing counts as healthier_source).
type Detail ¶
type Detail struct {
Chapter
All []VariantView
}
Detail is one chapter with all its variants.
type Group ¶
Group is one canonical chapter: a number (or, for chapters without one, the single variant it came from) and its variants.
func GroupVariants ¶
GroupVariants groups variants into canonical chapters by number; each variant without a number is a chapter of its own. Groups come in number order, extras last.
type Parsed ¶
type Parsed struct {
// Number is the chapter number, or nil; NumberEnd ends a range
// ("Chapter 10-11").
Number, NumberEnd *float64
// Volume, without leading zeros; empty when the name doesn't say.
Volume string
// Title is the chapter's own name with number, volume and scanlator
// noise taken out; empty when there's nothing else ("Chapter 12").
Title string
// Extra is a side story, special, extra, notice or hiatus: not part of
// the numbered run, even if it carries a number.
Extra bool
}
Parsed is what a chapter's name says.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service keeps the works' chapters.
func NewService ¶
func NewService(st *store.Store, host *plugins.Host, q *queue.Queue, lim *limits.Registry, hub *events.Hub, log *slog.Logger) *Service
NewService returns the service and registers its task kind on q.
func (*Service) List ¶
List returns a work's chapters in reading order (numbered ones by number, extras after), with the chosen variant and whether each is new for userID.
func (*Service) NewCounts ¶
func (s *Service) NewCounts(ctx context.Context, userID uuid.UUID, workIDs []uuid.UUID) (map[uuid.UUID]int64, error)
NewCounts returns how many new chapters each of a user's works has.
func (*Service) OnNewChapters ¶
func (s *Service) OnNewChapters(f func(ctx context.Context, workID uuid.UUID, chapterIDs []uuid.UUID))
OnNewChapters sets what happens when a work gains chapters (e.g. automatic downloads).
func (*Service) Pin ¶
func (s *Service) Pin(ctx context.Context, chapterID uuid.UUID, variantID *uuid.UUID) (db.Chapter, error)
Pin forces a variant for a chapter (nil unpins), then re-chooses.
func (*Service) QueueUpdate ¶
func (s *Service) QueueUpdate(ctx context.Context, se db.SourceSeries, by uuid.UUID, priority int32, runAfter time.Time) (db.Task, error)
QueueUpdate queues a chapter check of an attached series.
func (*Service) Refresh ¶
Refresh queues chapter checks of every attached series of a work, ahead of scheduled ones.
func (*Service) RefreshWorks ¶
RefreshWorks queues chapter checks of every attached series of these works, ahead of scheduled ones, and returns how many series it queued.
func (*Service) ScheduleAll ¶
ScheduleAll queues chapter checks of every attached series of works someone follows, spread over spread so sources aren't hit at once.
func (*Service) SeriesAttached ¶
func (s *Service) SeriesAttached(ctx context.Context, se db.SourceSeries)
SeriesAttached checks a newly attached series' chapters soon.
func (*Service) SeriesChapters ¶
func (s *Service) SeriesChapters(ctx context.Context, workID, seriesID uuid.UUID) (db.SourceSeries, []db.SourceChapter, error)
SeriesChapters returns a series' chapters exactly as its source lists them (the per-source view), including ones it no longer lists.
func (*Service) SourcesChanged ¶
SourcesChanged chooses the chapter copies again of every work with a series on these sources, after they became usable or stopped being usable: copies on an unusable source give way, and come back with it.
func (*Service) Unify ¶
Unify rebuilds a work's canonical chapters from its attached series and returns how many chapters are new.
func (*Service) UnifyAll ¶
UnifyAll rebuilds every work's chapters from the chapters stored, without asking any source: after a change to how chapter names are read. It returns how many works it went through.
type UpdateCursor ¶
UpdateCursor is where a feed page ends.
type Variant ¶
type Variant struct {
ID uuid.UUID
SeriesID uuid.UUID
SourceID string
Key string
Name string
Number *float64
Volume string
Scanlator string
Lang string
UploadedAt *time.Time
Position int32
// Priority is the series' priority for the work.
Priority int32
// Health is the source's: ok, failing or unknown.
Health string
// Unusable is a source that is turned off, no longer listed by its
// plugin, or whose plugin is turned off.
Unusable bool
// Announce is a variant a later check of its series found: a chapter
// made for it appears in the updates feed.
Announce bool
}
Variant is one source's copy of a chapter.
type VariantView ¶
VariantView is a variant with its source's name.