downloads

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: 32 Imported by: 0

Documentation

Overview

Package downloads downloads chapters into the shared library: one file per chapter, stored once for everyone, as a CBZ with ComicInfo.xml, on the default storage. Downloads are tasks: de-duplicated across users, retried with back-off, and capped per source across all users.

Index

Constants

View Source
const (
	KindDownload = "download.chapter"
	KindMove     = "storage.move"
)

Task kinds.

View Source
const DefaultTemplate = "{work} [{work_id}]/{volume} {chapter} - {title} [{group}].cbz"

DefaultTemplate names downloaded chapters: one folder per work (the ID keeps two works with the same title apart and survives renames).

Variables

View Source
var (
	ErrNotFound   = errors.New("downloads: not found")
	ErrNotStored  = errors.New("downloads: the chapter isn't downloaded")
	ErrSameTarget = errors.New("downloads: the files are on that storage already")
)

Errors callers map to responses.

Functions

func Render

func Render(template string, p NameParts) string

Render fills a template and makes every path segment safe for common filesystems (including SMB/NTFS shares). Empty parts leave no stray separators or brackets behind.

Types

type File

type File struct {
	db.ChapterFile
	Archive *cbz.Archive
	io.Closer
}

File is an open downloaded chapter.

type Item

type Item struct {
	Task          db.Task
	ChapterID     uuid.UUID
	WorkID        uuid.UUID
	WorkTitle     string
	ChapterNumber *float64
	ChapterTitle  string
}

Item is a download task with its chapter and work.

type NameParts

type NameParts struct {
	Work    string
	WorkID  string
	Volume  string
	Number  *float64
	Title   string
	Group   string
	Lang    string
	ExtraID string
}

NameParts are what a file name is made of.

type Queued

type Queued struct {
	Queued      int
	Downloaded  int
	Unavailable int
}

Queued is the outcome of asking for downloads.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service downloads chapters.

func NewService

func NewService(st *store.Store, host *plugins.Host, storages *storage.Manager, m *meta.Service, q *queue.Queue,
	lim *limits.Registry, hub *events.Hub, tmpDir string, log *slog.Logger,
) *Service

NewService returns the service and registers its task kinds on q.

func (*Service) DeleteFile

func (s *Service) DeleteFile(ctx context.Context, chapterID uuid.UUID) error

DeleteFile deletes a chapter's downloaded file (an admin's action).

func (*Service) Downloaded

func (s *Service) Downloaded(ctx context.Context, workID uuid.UUID) (map[uuid.UUID]bool, error)

Downloaded returns which of a work's chapters have files.

func (*Service) List

func (s *Service) List(ctx context.Context, userID *uuid.UUID, state string, before *db.Task, limit int) ([]Item, error)

List returns download tasks, newest first: all for admins, otherwise the ones userID asked for.

func (*Service) Move

func (s *Service) Move(ctx context.Context, by uuid.UUID, from, to string) (db.Task, error)

Move queues moving every file from one storage to another.

func (*Service) NewChapters

func (s *Service) NewChapters(ctx context.Context, workID uuid.UUID, chapterIDs []uuid.UUID)

NewChapters queues downloads of a work's new chapters for followers who asked for them and may download.

func (*Service) Open

func (s *Service) Open(ctx context.Context, chapterID uuid.UUID) (*File, error)

Open opens a chapter's downloaded file, or ErrNotStored.

func (*Service) Queue

func (s *Service) Queue(ctx context.Context, by uuid.UUID, workID uuid.UUID, chapterIDs []uuid.UUID) (Queued, error)

Queue asks for chapters of a work to be downloaded. Chapters that are downloaded or queued already (by anyone) aren't queued again.

func (*Service) SetAutoDownload

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

SetAutoDownload turns "download new chapters" on or off for a user's library entry.

Jump to

Keyboard shortcuts

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