core

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SpeedSmoothingAlpha = 0.3
	ReportInterval      = 150 * time.Millisecond
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DownloadService

type DownloadService interface {
	// List returns the status of all active and completed downloads.
	List() ([]types.DownloadStatus, error)

	// History returns completed downloads
	History() ([]types.DownloadEntry, error)

	// Add queues a new download.
	Add(url string, path string, filename string, mirrors []string, headers map[string]string, isExplicitCategory bool, totalSize int64, supportsRange bool) (string, error)

	// AddWithID queues a new download with a caller-provided ID.
	AddWithID(url string, path string, filename string, mirrors []string, headers map[string]string, id string, totalSize int64, supportsRange bool) (string, error)

	// Pause pauses an active download.
	Pause(id string) error

	// Resume resumes a paused download.
	Resume(id string) error

	// ResumeBatch resumes multiple paused downloads efficiently.
	ResumeBatch(ids []string) []error

	// UpdateURL updates the URL of a paused or errored download
	UpdateURL(id string, newURL string) error

	// Delete cancels and removes a download.
	Delete(id string) error

	// StreamEvents returns a channel that receives real-time download events.
	// For local mode, this is a direct channel.
	// For remote mode, this is sourced from SSE.
	StreamEvents(ctx context.Context) (<-chan interface{}, func(), error)

	// Publish emits an event into the service's event stream.
	Publish(msg interface{}) error

	// GetStatus returns a status for a single download by id.
	GetStatus(id string) (*types.DownloadStatus, error)

	// Shutdown handles graceful shutdown of the service
	Shutdown() error
}

DownloadService defines the interface for interacting with the download engine. This abstraction allows the TUI to switch between a local embedded backend and a remote daemon connection.

type LifecycleHooks added in v0.7.8

type LifecycleHooks struct {
	Pause       func(id string) error
	Resume      func(id string) error
	ResumeBatch func(ids []string) []error
	Cancel      func(id string) error
	UpdateURL   func(id, newURL string) error
}

LifecycleHooks routes service-level management calls through the LifecycleManager.

type LocalDownloadService

type LocalDownloadService struct {
	Pool    *download.WorkerPool
	InputCh chan interface{}
	// contains filtered or unexported fields
}

LocalDownloadService implements DownloadService for the local embedded engine.

func NewLocalDownloadService

func NewLocalDownloadService(pool *download.WorkerPool) *LocalDownloadService

NewLocalDownloadService creates a new specific service instance.

func NewLocalDownloadServiceWithInput

func NewLocalDownloadServiceWithInput(pool *download.WorkerPool, inputCh chan interface{}) *LocalDownloadService

NewLocalDownloadServiceWithInput creates a service using a provided input channel. If inputCh is nil, a new buffered channel is created.

func (*LocalDownloadService) Add

func (s *LocalDownloadService) Add(url string, path string, filename string, mirrors []string, headers map[string]string, isExplicitCategory bool, totalSize int64, supportsRange bool) (string, error)

Add queues a new download on the local pool without TUI confirmation.

func (*LocalDownloadService) AddWithID

func (s *LocalDownloadService) AddWithID(url string, path string, filename string, mirrors []string, headers map[string]string, id string, totalSize int64, supportsRange bool) (string, error)

AddWithID queues a new download using a caller-provided id when non-empty.

func (*LocalDownloadService) Delete

func (s *LocalDownloadService) Delete(id string) error

Delete cancels and removes a download.

func (*LocalDownloadService) GetStatus

func (s *LocalDownloadService) GetStatus(id string) (*types.DownloadStatus, error)

GetStatus returns a status for a single download by id.

func (*LocalDownloadService) History

func (s *LocalDownloadService) History() ([]types.DownloadEntry, error)

History returns completed downloads

func (*LocalDownloadService) List

List returns the status of all active and completed downloads.

func (*LocalDownloadService) Pause

func (s *LocalDownloadService) Pause(id string) error

Pause pauses an active download.

func (*LocalDownloadService) Publish

func (s *LocalDownloadService) Publish(msg interface{}) error

Publish emits an event into the service's event stream.

func (*LocalDownloadService) ReloadSettings

func (s *LocalDownloadService) ReloadSettings() error

ReloadSettings reloads settings from disk

func (*LocalDownloadService) Resume

func (s *LocalDownloadService) Resume(id string) error

Resume resumes a paused download.

func (*LocalDownloadService) ResumeBatch

func (s *LocalDownloadService) ResumeBatch(ids []string) []error

ResumeBatch resumes multiple paused downloads efficiently.

func (*LocalDownloadService) SetLifecycleHooks

func (s *LocalDownloadService) SetLifecycleHooks(hooks LifecycleHooks)

SetLifecycleHooks wires the processing layer into the service so pause/resume/cancel/updateURL calls are routed through the lifecycle manager.

func (*LocalDownloadService) Shutdown

func (s *LocalDownloadService) Shutdown() error

Shutdown stops the service.

func (*LocalDownloadService) StreamEvents

func (s *LocalDownloadService) StreamEvents(ctx context.Context) (<-chan interface{}, func(), error)

StreamEvents returns a channel that receives real-time download events.

func (*LocalDownloadService) UpdateURL

func (s *LocalDownloadService) UpdateURL(id string, newURL string) error

UpdateURL updates the URL of a paused or errored download

type RemoteDownloadService

type RemoteDownloadService struct {
	BaseURL   string
	Token     string
	Client    *http.Client
	SSEClient *http.Client
	// contains filtered or unexported fields
}

RemoteDownloadService implements DownloadService for a remote daemon.

func NewRemoteDownloadService

func NewRemoteDownloadService(baseURL string, token string) *RemoteDownloadService

NewRemoteDownloadService creates a new remote service instance.

func (*RemoteDownloadService) Add

func (s *RemoteDownloadService) Add(url string, path string, filename string, mirrors []string, headers map[string]string, isExplicitCategory bool, totalSize int64, supportsRange bool) (string, error)

Add queues a new download.

func (*RemoteDownloadService) AddWithID

func (s *RemoteDownloadService) AddWithID(url string, path string, filename string, mirrors []string, headers map[string]string, id string, totalSize int64, supportsRange bool) (string, error)

AddWithID queues a new download with a caller-provided id.

func (*RemoteDownloadService) Delete

func (s *RemoteDownloadService) Delete(id string) error

Delete cancels and removes a download.

func (*RemoteDownloadService) GetStatus

func (s *RemoteDownloadService) GetStatus(id string) (*types.DownloadStatus, error)

GetStatus returns a status for a single download by id.

func (*RemoteDownloadService) History

func (s *RemoteDownloadService) History() ([]types.DownloadEntry, error)

History returns completed downloads

func (*RemoteDownloadService) List

List returns the status of all active and completed downloads.

func (*RemoteDownloadService) Pause

func (s *RemoteDownloadService) Pause(id string) error

Pause pauses an active download.

func (*RemoteDownloadService) Publish

func (s *RemoteDownloadService) Publish(msg interface{}) error

Publish emits an event into the service's event stream. Remote services do not accept client-side event injection.

func (*RemoteDownloadService) Resume

func (s *RemoteDownloadService) Resume(id string) error

Resume resumes a paused download.

func (*RemoteDownloadService) ResumeBatch

func (s *RemoteDownloadService) ResumeBatch(ids []string) []error

ResumeBatch resumes multiple paused downloads efficiently.

func (*RemoteDownloadService) Shutdown

func (s *RemoteDownloadService) Shutdown() error

Shutdown stops the service.

func (*RemoteDownloadService) StreamEvents

func (s *RemoteDownloadService) StreamEvents(ctx context.Context) (<-chan interface{}, func(), error)

StreamEvents returns a channel that receives real-time download events via SSE.

func (*RemoteDownloadService) UpdateURL

func (s *RemoteDownloadService) UpdateURL(id string, newURL string) error

UpdateURL updates the URL of a paused or errored download via the remote API.

Jump to

Keyboard shortcuts

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