Documentation
¶
Index ¶
- Variables
- type DownloadProgress
- type Downloader
- func (d *Downloader) ActiveDownloads() []DownloadProgress
- func (d *Downloader) Cancel(fileID string) error
- func (d *Downloader) CancelByProduct(productID string) int
- func (d *Downloader) Download(ctx context.Context, fileID string) error
- func (d *Downloader) GetProgress(fileID string) *DownloadProgress
- func (d *Downloader) IsActive(fileID string) bool
- func (d *Downloader) StatusVersion() uint64
- type ProgressTracker
- func (pt *ProgressTracker) Complete(fileID string)
- func (pt *ProgressTracker) Get(fileID string) *DownloadProgress
- func (pt *ProgressTracker) GetAll() []DownloadProgress
- func (pt *ProgressTracker) IncrementStatusVersion()
- func (pt *ProgressTracker) Start(fileID, fileName string, totalBytes int64)
- func (pt *ProgressTracker) StatusVersion() uint64
- func (pt *ProgressTracker) Update(fileID string, bytesWritten, totalBytes int64)
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type DownloadProgress ¶
type DownloadProgress struct {
FileID string `json:"fileId"`
FileName string `json:"fileName"`
BytesWritten int64 `json:"bytesWritten"`
TotalBytes int64 `json:"totalBytes"`
StartedAt time.Time `json:"startedAt"`
Speed float64 `json:"speed"` // bytes per second
}
DownloadProgress represents the progress of a single download
func (*DownloadProgress) ETA ¶
func (p *DownloadProgress) ETA() time.Duration
ETA returns the estimated time remaining
func (*DownloadProgress) Percent ¶
func (p *DownloadProgress) Percent() float64
Percent returns the download progress as a percentage
type Downloader ¶
type Downloader struct {
// contains filtered or unexported fields
}
Downloader manages file downloads
func New ¶
func New(db *database.DB, registry *sources.Registry, hooks *hooks.Manager, cfg *config.Config) *Downloader
New creates a new downloader
func (*Downloader) ActiveDownloads ¶
func (d *Downloader) ActiveDownloads() []DownloadProgress
ActiveDownloads returns progress for all active downloads
func (*Downloader) Cancel ¶
func (d *Downloader) Cancel(fileID string) error
Cancel cancels an in-progress download
func (*Downloader) CancelByProduct ¶ added in v0.1.5
func (d *Downloader) CancelByProduct(productID string) int
CancelByProduct cancels all in-progress downloads for a product. Returns the number of downloads cancelled.
func (*Downloader) Download ¶
func (d *Downloader) Download(ctx context.Context, fileID string) error
Download starts downloading a file
func (*Downloader) GetProgress ¶
func (d *Downloader) GetProgress(fileID string) *DownloadProgress
GetProgress returns progress for a specific download
func (*Downloader) IsActive ¶ added in v0.2.0
func (d *Downloader) IsActive(fileID string) bool
IsActive returns true if a download is currently in progress for the given file.
func (*Downloader) StatusVersion ¶ added in v0.2.0
func (d *Downloader) StatusVersion() uint64
StatusVersion returns a counter that increments on every download status change.
type ProgressTracker ¶
type ProgressTracker struct {
// contains filtered or unexported fields
}
ProgressTracker tracks download progress for multiple files
func NewProgressTracker ¶
func NewProgressTracker() *ProgressTracker
NewProgressTracker creates a new progress tracker
func (*ProgressTracker) Complete ¶
func (pt *ProgressTracker) Complete(fileID string)
Complete removes a download from tracking
func (*ProgressTracker) Get ¶
func (pt *ProgressTracker) Get(fileID string) *DownloadProgress
Get returns progress for a specific download
func (*ProgressTracker) GetAll ¶
func (pt *ProgressTracker) GetAll() []DownloadProgress
GetAll returns progress for all active downloads, sorted by start time.
func (*ProgressTracker) IncrementStatusVersion ¶ added in v0.2.0
func (pt *ProgressTracker) IncrementStatusVersion()
IncrementStatusVersion bumps the status version counter. Called whenever a download changes status (started, completed, failed, cancelled).
func (*ProgressTracker) Start ¶
func (pt *ProgressTracker) Start(fileID, fileName string, totalBytes int64)
Start registers a new download
func (*ProgressTracker) StatusVersion ¶ added in v0.2.0
func (pt *ProgressTracker) StatusVersion() uint64
StatusVersion returns the current status version counter.
func (*ProgressTracker) Update ¶
func (pt *ProgressTracker) Update(fileID string, bytesWritten, totalBytes int64)
Update updates progress for a download