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) 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{})
- 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 func(id string) bool
Resume func(id string) bool
GetStatus func(id string) *types.DownloadStatus
// AddConfig enqueues a download config. Implementations must ensure cfg.ProgressCh
// is set; pool.Add fills it from p.progressCh when nil.
AddConfig func(cfg types.DownloadConfig)
PublishEvent func(msg interface{}) error
}
EngineHooks defines the minimal callbacks Processing needs to orchestrate the worker pool.
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) 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.
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.