common

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package common provides shared types and constants used across the warpdl client-server communication layer.

Package common provides shared types and constants used across the warpdl client-server communication layer.

Index

Constants

View Source
const (
	// DefaultTCPPort is the default port for TCP fallback connections.
	// Both daemon (server) and CLI (client) must use the same port.
	DefaultTCPPort = 3849

	// TCPHost is the hostname for TCP connections. This is intentionally
	// hardcoded to localhost for security - the daemon has no authentication
	// and must not be exposed to external interfaces.
	TCPHost = "localhost"

	// MaxMessageSize caps socket payloads to protect against oversized requests.
	MaxMessageSize = 16 * 1024 * 1024

	// DefaultDialTimeout is the default timeout for establishing connections.
	DefaultDialTimeout = 2 * time.Second

	// ShutdownTimeout is the timeout for graceful server shutdown.
	ShutdownTimeout = 5 * time.Second
)
View Source
const (
	// SocketPathEnv is the environment variable for custom socket path.
	SocketPathEnv = "WARPDL_SOCKET_PATH"

	// TCPPortEnv is the environment variable for custom TCP port.
	TCPPortEnv = "WARPDL_TCP_PORT"

	// ForceTCPEnv is the environment variable to force TCP connections.
	ForceTCPEnv = "WARPDL_FORCE_TCP"

	// DebugEnv is the environment variable to enable debug logging.
	DebugEnv = "WARPDL_DEBUG"

	// PipeNameEnv is the environment variable for custom Windows named pipe name.
	// When set, the value is used as the pipe name (e.g., "custom" becomes "\\.\pipe\custom").
	// If the value already contains the full pipe path prefix, it's used as-is.
	PipeNameEnv = "WARPDL_PIPE_NAME"

	// DefaultDlDirEnv is the environment variable for the default download directory.
	// When set, it provides the default directory for downloads when -l flag is not specified.
	DefaultDlDirEnv = "WARPDL_DEFAULT_DL_DIR"

	// DaemonURIEnv is the environment variable for daemon URI.
	// Format: unix:///path/to/socket, tcp://host:port, or pipe://name
	DaemonURIEnv = "WARPDL_DAEMON_URI"
)

Environment variable names for configuration.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddExtensionParams

type AddExtensionParams struct {
	// Path is the filesystem path to the extension to install.
	Path string `json:"path"`
}

AddExtensionParams contains parameters for adding a new extension.

type DownloadParams

type DownloadParams struct {
	// Url is the source URL to download from.
	Url string `json:"url"`
	// DownloadDirectory is the target directory where the file will be saved.
	DownloadDirectory string `json:"download_directory"`
	// FileName is the desired name for the downloaded file.
	FileName string `json:"file_name"`
	// Headers contains optional HTTP headers to include in the download request.
	Headers warplib.Headers `json:"headers,omitempty"`
	// ForceParts forces the download to use multiple parts even if the server
	// does not advertise support for range requests.
	ForceParts bool `json:"force_parts,omitempty"`
	// MaxConnections limits the maximum number of concurrent HTTP connections.
	MaxConnections int32 `json:"max_connections,omitempty"`
	// MaxSegments limits the maximum number of download segments.
	MaxSegments int32 `json:"max_segments,omitempty"`
	// ChildHash is the hash identifier for child downloads in a multi-file scenario.
	ChildHash string `json:"child_hash,omitempty"`
	// IsHidden indicates whether this download should be hidden from listing.
	IsHidden bool `json:"is_hidden,omitempty"`
	// IsChildren indicates whether this download is a child of another download.
	IsChildren bool `json:"is_children,omitempty"`
	// Overwrite allows replacing an existing file at the destination path.
	Overwrite bool `json:"overwrite,omitempty"`
	// Proxy specifies the proxy server URL (http, https, or socks5) for the download.
	Proxy string `json:"proxy,omitempty"`
	// Timeout specifies the per-request timeout in seconds.
	Timeout int `json:"timeout,omitempty"`
	// MaxRetries specifies maximum retry attempts for transient errors.
	MaxRetries int `json:"max_retries,omitempty"`
	// RetryDelay specifies the base delay between retries in milliseconds.
	RetryDelay int `json:"retry_delay,omitempty"`
	// SpeedLimit specifies the maximum download speed (e.g., "1MB", "512KB", or raw bytes).
	// If empty or "0", no limit is applied.
	SpeedLimit string `json:"speed_limit,omitempty"`
	// DisableWorkStealing disables dynamic work stealing where fast parts
	// take over remaining work from slow adjacent parts.
	DisableWorkStealing bool `json:"disable_work_stealing,omitempty"`
	// Priority specifies the queue priority (0=low, 1=normal, 2=high).
	// Defaults to normal (1) if not specified.
	Priority int `json:"priority,omitempty"`
	// SSHKeyPath specifies a custom SSH private key file path for SFTP downloads.
	// If empty, default SSH key paths (~/.ssh/id_ed25519, ~/.ssh/id_rsa) are tried.
	SSHKeyPath string `json:"ssh_key_path,omitempty"`
	// StartAt specifies an absolute start time in "YYYY-MM-DD HH:MM" format.
	// Mutually exclusive with StartIn. Empty means start immediately.
	StartAt string `json:"start_at,omitempty"`
	// StartIn specifies a relative delay using Go duration syntax (e.g., "2h", "30m").
	// Mutually exclusive with StartAt. "0s" or empty means start immediately.
	StartIn string `json:"start_in,omitempty"`
	// Schedule specifies a 5-field cron expression for recurring downloads (e.g., "0 2 * * *").
	// May be combined with StartAt or StartIn to delay the first occurrence.
	Schedule string `json:"schedule,omitempty"`
	// CookiesFrom specifies the cookie source: file path, "auto", or "".
	// Empty means no cookie import. "auto" triggers browser auto-detection.
	CookiesFrom string `json:"cookies_from,omitempty"`
}

DownloadParams contains parameters for initiating a new download request.

type DownloadResponse

type DownloadResponse struct {
	// DownloadId is the unique identifier assigned to this download.
	DownloadId string `json:"download_id"`
	// FileName is the resolved name of the file being downloaded.
	FileName string `json:"file_name"`
	// SavePath is the full path where the file is being saved.
	SavePath string `json:"save_path"`
	// DownloadDirectory is the directory containing the downloaded file.
	DownloadDirectory string `json:"download_directory"`
	// ContentLength is the total size of the file in bytes.
	ContentLength warplib.ContentLength `json:"content_length"`
	// Downloaded is the number of bytes already downloaded.
	Downloaded warplib.ContentLength `json:"downloaded,omitempty"`
	// MaxConnections is the number of concurrent connections being used.
	MaxConnections int32 `json:"max_connections"`
	// MaxSegments is the number of segments the download is split into.
	MaxSegments int32 `json:"max_segments"`
}

DownloadResponse contains the server response after initiating a download.

type DownloadingAction

type DownloadingAction string

DownloadingAction represents the current state or action occurring during a download operation, used for progress reporting and state transitions.

const (
	// ResumeProgress indicates progress updates during download resumption.
	ResumeProgress DownloadingAction = "resume_progress"
	// DownloadProgress indicates progress updates during active downloading.
	DownloadProgress DownloadingAction = "download_progress"
	// DownloadComplete indicates the download has finished successfully.
	DownloadComplete DownloadingAction = "download_complete"
	// DownloadStopped indicates the download was stopped by the user.
	DownloadStopped DownloadingAction = "download_stopped"
	// CompileStart indicates the beginning of segment compilation into the final file.
	CompileStart DownloadingAction = "compile_start"
	// CompileProgress indicates progress during segment compilation.
	CompileProgress DownloadingAction = "compile_progress"
	// CompileComplete indicates segment compilation has finished successfully.
	CompileComplete DownloadingAction = "compile_complete"
)

type DownloadingResponse

type DownloadingResponse struct {
	// DownloadId is the unique identifier for this download.
	DownloadId string `json:"download_id"`
	// Action indicates the current state or action of the download.
	Action DownloadingAction `json:"action"`
	// Hash is the segment or part identifier for progress tracking.
	Hash string `json:"hash"`
	// Value contains the progress value, typically bytes downloaded.
	Value int64 `json:"value,omitempty"`
}

DownloadingResponse contains progress information for an active download.

type ExtensionInfo

type ExtensionInfo struct {
	// ExtensionId is the unique identifier for the extension.
	ExtensionId string `json:"extension_id"`
	// Name is the human-readable name of the extension.
	Name string `json:"name"`
	// Version is the semantic version string of the extension.
	Version string `json:"version"`
	// Description provides a brief summary of the extension's purpose.
	Description string `json:"description"`
	// Matches contains URL patterns that this extension handles.
	Matches []string `json:"matches"`
}

ExtensionInfo contains detailed information about an installed extension.

type ExtensionInfoShort

type ExtensionInfoShort struct {
	// ExtensionId is the unique identifier for the extension.
	ExtensionId string `json:"extension_id"`
	// Name is the human-readable name of the extension.
	Name string `json:"name"`
	// Activated indicates whether the extension is currently active.
	Activated bool `json:"activated"`
}

ExtensionInfoShort contains abbreviated information about an extension for use in listing operations.

type ExtensionName

type ExtensionName struct {
	// Name is the human-readable name of the extension.
	Name string `json:"name"`
}

ExtensionName contains the name of an extension.

type FlushParams

type FlushParams struct {
	// DownloadId optionally specifies a single download to flush.
	// If empty, all completed downloads are flushed.
	DownloadId string `json:"download_id,omitempty"`
}

FlushParams contains parameters for flushing downloads from the manager.

type InputDownloadId

type InputDownloadId struct {
	// DownloadId is the unique identifier for the download.
	DownloadId string `json:"download_id"`
}

InputDownloadId contains the identifier for a specific download operation. It is used as input for operations that target a single download.

type InputExtension

type InputExtension struct {
	// ExtensionId is the unique identifier for the extension.
	ExtensionId string `json:"extension_id"`
}

InputExtension contains the identifier for a specific extension.

type ListExtensionsParams

type ListExtensionsParams struct {
	// All includes both active and inactive extensions when true.
	All bool `json:"all"`
}

ListExtensionsParams contains parameters for listing extensions.

type ListParams

type ListParams struct {
	// ShowCompleted includes completed downloads in the listing.
	ShowCompleted bool `json:"show_completed"`
	// ShowPending includes pending or in-progress downloads in the listing.
	ShowPending bool `json:"show_pending"`
}

ListParams contains parameters for listing downloads.

type ListResponse

type ListResponse struct {
	// Items contains the list of download items matching the query.
	Items []*warplib.Item `json:"items"`
}

ListResponse contains the response for a download listing request.

type QueueItemInfo added in v1.3.36

type QueueItemInfo struct {
	// Hash is the unique identifier for the queued download.
	Hash string `json:"hash"`
	// Priority is the priority level (0=Low, 1=Normal, 2=High).
	Priority int `json:"priority"`
	// Position is the 0-indexed position in the waiting queue.
	Position int `json:"position"`
}

QueueItemInfo represents a queued download item in the waiting queue.

type QueueMoveParams added in v1.3.36

type QueueMoveParams struct {
	// Hash is the unique identifier of the queued download to move.
	Hash string `json:"hash"`
	// Position is the target 0-indexed position in the queue.
	Position int `json:"position"`
}

QueueMoveParams holds parameters for moving a queue item to a new position.

type QueueStatusResponse added in v1.3.36

type QueueStatusResponse struct {
	// MaxConcurrent is the maximum number of concurrent downloads allowed.
	MaxConcurrent int `json:"max_concurrent"`
	// ActiveCount is the number of currently active downloads.
	ActiveCount int `json:"active_count"`
	// WaitingCount is the number of downloads waiting in the queue.
	WaitingCount int `json:"waiting_count"`
	// Paused indicates whether the queue is paused.
	Paused bool `json:"paused"`
	// Active contains the hashes of currently active downloads.
	Active []string `json:"active"`
	// Waiting contains information about queued downloads in priority order.
	Waiting []QueueItemInfo `json:"waiting"`
}

QueueStatusResponse is the response for queue status requests.

type ResumeParams

type ResumeParams struct {
	// DownloadId is the unique identifier of the download to resume.
	DownloadId string `json:"download_id"`
	// Headers contains optional HTTP headers to include in the resume request.
	Headers warplib.Headers `json:"headers,omitempty"`
	// ForceParts forces the download to use multiple parts on resume.
	ForceParts bool `json:"force_parts,omitempty"`
	// MaxConnections limits the maximum number of concurrent HTTP connections.
	MaxConnections int32 `json:"max_connections,omitempty"`
	// MaxSegments limits the maximum number of download segments.
	MaxSegments int32 `json:"max_segments,omitempty"`
	// Proxy specifies the proxy server URL (http, https, or socks5) for the resume.
	Proxy string `json:"proxy,omitempty"`
	// Timeout specifies the per-request timeout in seconds.
	Timeout int `json:"timeout,omitempty"`
	// MaxRetries specifies maximum retry attempts for transient errors.
	MaxRetries int `json:"max_retries,omitempty"`
	// RetryDelay specifies the base delay between retries in milliseconds.
	RetryDelay int `json:"retry_delay,omitempty"`
	// SpeedLimit specifies the maximum download speed (e.g., "1MB", "512KB", or raw bytes).
	// If empty or "0", no limit is applied.
	SpeedLimit string `json:"speed_limit,omitempty"`
}

ResumeParams contains parameters for resuming a paused or interrupted download.

type ResumeResponse

type ResumeResponse struct {
	// ChildHash is the hash identifier for child downloads if applicable.
	ChildHash string `json:"child_hash,omitempty"`
	// FileName is the name of the file being resumed.
	FileName string `json:"file_name"`
	// SavePath is the full path where the file is being saved.
	SavePath string `json:"save_path"`
	// DownloadDirectory is the directory containing the downloaded file.
	DownloadDirectory string `json:"download_directory"`
	// AbsoluteLocation is the absolute filesystem path to the download.
	AbsoluteLocation string `json:"absolute_location"`
	// ContentLength is the total size of the file in bytes.
	ContentLength warplib.ContentLength `json:"content_length"`
	// Downloaded is the number of bytes already downloaded (for progress bar initialization).
	Downloaded warplib.ContentLength `json:"downloaded,omitempty"`
	// MaxConnections is the number of concurrent connections being used.
	MaxConnections int32 `json:"max_connections"`
	// MaxSegments is the number of segments the download is split into.
	MaxSegments int32 `json:"max_segments"`
}

ResumeResponse contains the server response after resuming a download.

type UpdateType

type UpdateType string

UpdateType represents the type of update message sent between the CLI client and the daemon server over the Unix socket connection.

const (
	// UPDATE_DOWNLOAD initiates a new download request.
	UPDATE_DOWNLOAD UpdateType = "download"
	// UPDATE_DOWNLOADING indicates an ongoing download progress update.
	UPDATE_DOWNLOADING UpdateType = "downloading"
	// UPDATE_ATTACH attaches the client to an existing download session.
	UPDATE_ATTACH UpdateType = "attach"
	// UPDATE_RESUME resumes a previously paused or interrupted download.
	UPDATE_RESUME UpdateType = "resume"
	// UPDATE_FLUSH removes completed or cancelled downloads from the manager.
	UPDATE_FLUSH UpdateType = "flush"
	// UPDATE_STOP stops an active download.
	UPDATE_STOP UpdateType = "stop"
	// UPDATE_LIST requests a list of downloads from the manager.
	UPDATE_LIST UpdateType = "list"
	// UPDATE_ADD_EXT adds a new extension to the extension engine.
	UPDATE_ADD_EXT UpdateType = "add_extension"
	// UPDATE_LIST_EXT requests a list of installed extensions.
	UPDATE_LIST_EXT UpdateType = "list_extensions"
	// UPDATE_GET_EXT retrieves detailed information about a specific extension.
	UPDATE_GET_EXT UpdateType = "get_extension"
	// UPDATE_DELETE_EXT removes an extension from the system.
	UPDATE_DELETE_EXT UpdateType = "delete_extension"
	// UPDATE_ACTIVATE_EXT activates a previously deactivated extension.
	UPDATE_ACTIVATE_EXT UpdateType = "activate_extension"
	// UPDATE_DEACTIVATE_EXT deactivates an active extension without removing it.
	UPDATE_DEACTIVATE_EXT UpdateType = "deactivate_extension"
	// UPDATE_UNLOAD_EXT unloads an extension from memory.
	UPDATE_UNLOAD_EXT UpdateType = "unload_extension"
	// UPDATE_VERSION requests the daemon's version information.
	UPDATE_VERSION UpdateType = "version"
	// UPDATE_QUEUE_STATUS requests the current queue status.
	UPDATE_QUEUE_STATUS UpdateType = "queue_status"
	// UPDATE_QUEUE_PAUSE pauses the download queue (stops auto-starting new downloads).
	UPDATE_QUEUE_PAUSE UpdateType = "queue_pause"
	// UPDATE_QUEUE_RESUME resumes the download queue (allows auto-starting downloads).
	UPDATE_QUEUE_RESUME UpdateType = "queue_resume"
	// UPDATE_QUEUE_MOVE moves a queued item to a new position.
	UPDATE_QUEUE_MOVE UpdateType = "queue_move"
)

type VersionResponse added in v1.3.1

type VersionResponse struct {
	// Version is the semantic version of the daemon (e.g., "1.2.0").
	Version string `json:"version"`
	// Commit is the git commit hash from which the daemon was built.
	Commit string `json:"commit,omitempty"`
	// BuildType indicates the build variant (e.g., "stable", "dev").
	BuildType string `json:"build_type,omitempty"`
}

VersionResponse contains the daemon's version information. It is returned in response to UPDATE_VERSION requests.

Jump to

Keyboard shortcuts

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