Documentation
¶
Index ¶
- func GetCategoryPath(filename, defaultDir string, settings *config.Settings) (string, error)
- func GetUniqueFilename(dir, filename string, isNameActive func(string, string) bool) string
- func InferFilenameFromURL(rawURL string) string
- func ProbeMirrors(ctx context.Context, mirrors []string) (valid []string, errs map[string]error)
- func ProbeMirrorsWithProxy(ctx context.Context, mirrors []string, proxyURL string) (valid []string, errs map[string]error)
- func RemoveIncompleteFile(destPath string) error
- func ResolveDestination(url, candidateFilename, defaultDir string, routeToCategory bool, ...) (string, string, error)
- type AddDownloadFunc
- type AddDownloadWithIDFunc
- type DownloadRequest
- type DuplicateResult
- type EngineHooks
- type IsNameActiveFunc
- type LifecycleManager
- func (m *LifecycleManager) ApplySettings(s *config.Settings)
- func (mgr *LifecycleManager) Cancel(id string) error
- func (mgr *LifecycleManager) Enqueue(ctx context.Context, req *DownloadRequest) (string, error)
- func (mgr *LifecycleManager) EnqueueWithID(ctx context.Context, req *DownloadRequest, requestID string) (string, error)
- func (m *LifecycleManager) GetSettings() *config.Settings
- func (mgr *LifecycleManager) IsNameActive(dir, name string) bool
- func (mgr *LifecycleManager) Pause(id string) error
- func (mgr *LifecycleManager) Resume(id string) error
- func (mgr *LifecycleManager) ResumeBatch(ids []string) []error
- func (m *LifecycleManager) SaveSettings(s *config.Settings) error
- func (mgr *LifecycleManager) SetEngineHooks(hooks EngineHooks)
- func (mgr *LifecycleManager) StartEventWorker(ch <-chan interface{})
- func (mgr *LifecycleManager) UpdateURL(id string, newURL string) error
- type ProbeResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetCategoryPath ¶
GetCategoryPath applies category routing only while the caller is still using the default destination, so explicit user paths are left untouched.
func GetUniqueFilename ¶
GetUniqueFilename keeps final files and .surge working files in the same collision namespace so concurrent or resumed downloads do not share a path.
func InferFilenameFromURL ¶
InferFilenameFromURL is the final naming fallback when neither the user nor the probe produced a trustworthy filename.
func ProbeMirrors ¶
ProbeMirrors is the convenience wrapper for callers that need mirror probing to honor the saved proxy setting but do not already hold a live settings snapshot.
func ProbeMirrorsWithProxy ¶
func ProbeMirrorsWithProxy(ctx context.Context, mirrors []string, proxyURL string) (valid []string, errs map[string]error)
ProbeMirrorsWithProxy preserves caller order so mirror priority remains stable.
func RemoveIncompleteFile ¶
RemoveIncompleteFile drops only the reserved working file, leaving any promoted final file untouched.
func ResolveDestination ¶
func ResolveDestination(url, candidateFilename, defaultDir string, routeToCategory bool, settings *config.Settings, probe *ProbeResult, isNameActive func(string, string) bool) (string, string, error)
ResolveDestination centralizes routing and naming so CLI, TUI, and API requests all land on the same final path before the engine starts downloading.
Types ¶
type AddDownloadFunc ¶
type AddDownloadFunc func(string, string, string, []string, map[string]string, bool, int64, bool) (string, error)
AddDownloadFunc is the lifecycle's handoff into the engine-facing queue layer.
type AddDownloadWithIDFunc ¶
type AddDownloadWithIDFunc func(string, string, string, []string, map[string]string, string, int64, bool) (string, error)
AddDownloadWithIDFunc preserves caller-chosen ids when a remote/UI layer already owns them.
type DownloadRequest ¶
type DownloadRequest struct {
URL string
Filename string
Path string
Mirrors []string
Headers map[string]string
IsExplicitCategory bool
SkipApproval bool
}
DownloadRequest carries the already-approved inputs needed to probe and reserve a file path.
type DuplicateResult ¶
DuplicateResult represents the outcome of a duplicate check
func CheckForDuplicate ¶
func CheckForDuplicate(url string, settings *config.Settings, activeDownloads func() map[string]*types.DownloadConfig) *DuplicateResult
CheckForDuplicate inspects active and persisted downloads for duplicate URLs.
type EngineHooks ¶
type EngineHooks struct {
// Pause signals the pool to mechanically pause a download (cancel context, set state).
Pause func(id string) bool
// ExtractPausedConfig atomically removes a paused download from the pool and returns
// its config so LifecycleManager can re-enqueue it after hydration from saved state.
// Returns nil when not found / not paused / still transitioning.
ExtractPausedConfig func(id string) *types.DownloadConfig
// GetStatus returns the in-memory status for a download.
GetStatus func(id string) *types.DownloadStatus
// AddConfig enqueues a DownloadConfig. The pool sets cfg.ProgressCh when nil.
AddConfig func(cfg types.DownloadConfig)
// Cancel mechanically removes a download from the pool and returns removal metadata.
Cancel func(id string) types.CancelResult
// UpdateURL updates the in-memory URL only; LifecycleManager persists to DB.
UpdateURL func(id, newURL string) error
// PublishEvent sends an event into the service's broadcast channel.
PublishEvent func(msg interface{}) error
}
EngineHooks defines the minimal callbacks Processing needs to orchestrate the worker pool. All management decisions (event emission, DB persistence, state loading) live here in LifecycleManager; the pool itself is a pure executor.
type IsNameActiveFunc ¶
IsNameActiveFunc lets routing treat in-flight downloads as filename conflicts within a directory.
type LifecycleManager ¶
type LifecycleManager struct {
// contains filtered or unexported fields
}
func NewLifecycleManager ¶
func NewLifecycleManager(addFunc AddDownloadFunc, addWithIDFunc AddDownloadWithIDFunc, isNameActive ...IsNameActiveFunc) *LifecycleManager
func (*LifecycleManager) ApplySettings ¶
func (m *LifecycleManager) ApplySettings(s *config.Settings)
ApplySettings swaps in a new routing snapshot for future enqueue calls.
func (*LifecycleManager) Cancel ¶ added in v0.7.8
func (mgr *LifecycleManager) Cancel(id string) error
Cancel stops a download (both pool in-memory and DB) and emits a removal event. The event worker handles file cleanup and DB removal via DownloadRemovedMsg.
func (*LifecycleManager) Enqueue ¶
func (mgr *LifecycleManager) Enqueue(ctx context.Context, req *DownloadRequest) (string, error)
Enqueue probes and reserves a stable destination before dispatching to the queue layer.
func (*LifecycleManager) EnqueueWithID ¶
func (mgr *LifecycleManager) EnqueueWithID(ctx context.Context, req *DownloadRequest, requestID string) (string, error)
EnqueueWithID does the same lifecycle work as Enqueue while preserving a caller-owned id.
func (*LifecycleManager) GetSettings ¶
func (m *LifecycleManager) GetSettings() *config.Settings
GetSettings reloads disk-backed routing rules opportunistically so a long-lived lifecycle manager picks up saved settings changes without a restart.
func (*LifecycleManager) IsNameActive ¶
func (mgr *LifecycleManager) IsNameActive(dir, name string) bool
IsNameActive reports whether the configured active-download callback would treat the given directory/name pair as an in-flight conflict.
func (*LifecycleManager) Pause ¶
func (mgr *LifecycleManager) Pause(id string) error
Pause pauses an active download.
func (*LifecycleManager) Resume ¶
func (mgr *LifecycleManager) Resume(id string) error
Resume resumes a paused download.
Hot path: download is still in pool memory (same session) — extract config directly. Cold path: download was paused in a prior session, only stored in DB.
func (*LifecycleManager) ResumeBatch ¶
func (mgr *LifecycleManager) ResumeBatch(ids []string) []error
ResumeBatch resumes multiple paused downloads efficiently.
func (*LifecycleManager) SaveSettings ¶
func (m *LifecycleManager) SaveSettings(s *config.Settings) error
SaveSettings persists and applies a new routing snapshot for future enqueue calls.
func (*LifecycleManager) SetEngineHooks ¶
func (mgr *LifecycleManager) SetEngineHooks(hooks EngineHooks)
SetEngineHooks injects dependencies the manager needs to interact with the broader system (like the download worker pool or the event system) without causing cyclic dependency graphs.
func (*LifecycleManager) StartEventWorker ¶
func (mgr *LifecycleManager) StartEventWorker(ch <-chan interface{})
StartEventWorker listens to engine events and handles database persistence and file cleanup, ensuring the core engine remains stateless.
type ProbeResult ¶
ProbeResult contains all metadata from server probe
func ProbeServer ¶
func ProbeServer(ctx context.Context, rawurl string, filenameHint string, headers map[string]string) (*ProbeResult, error)
ProbeServer is the convenience entry point for callers that do not already hold a settings snapshot; it reloads persisted settings so probe traffic can honor the saved proxy configuration.
func ProbeServerWithProxy ¶
func ProbeServerWithProxy(ctx context.Context, rawurl string, filenameHint string, headers map[string]string, proxyURL string) (*ProbeResult, error)
ProbeServerWithProxy is the hot-path variant for callers that already know the effective proxy and want probe traffic to match the eventual download path without re-reading settings from disk.