Sambex.HotFolder.Config (sambex v0.3.0)
View SourceConfiguration structure and validation for Sambex HotFolder.
The HotFolder configuration defines how files are monitored and processed, including connection details, folder structure, filtering rules, and processing behavior.
Configuration Options
Connection Settings
You can either provide connection details directly or reference an existing connection:
# Direct connection
%Config{
url: "smb://server/share",
username: "user",
password: "pass"
}
# Use existing connection
%Config{
connection: :my_connection
}
Folder Structure
All folder names are relative to the base_path within the SMB share:
%Config{
base_path: "print-queue",
folders: %{
incoming: "inbox",
processing: "working",
success: "completed",
errors: "failed"
}
}
File Filtering
Control which files are processed using various filter criteria:
%Config{
filters: %{
name_patterns: [~r/.pdf$/i, ~r/job_\d+\.txt$/],
exclude_patterns: [~r/^\./], # Skip hidden files
min_size: 1024, # 1KB minimum
max_size: 50_000_000, # 50MB maximum
mime_types: ["application/pdf"]
}
}
Summary
Functions
Returns all folder paths as a map.
Returns the full path for a given folder type.
Creates and validates a HotFolder configuration.
Creates and validates a HotFolder configuration, raising on error.
Validates a HotFolder configuration.
Types
@type filter_config() :: %{ name_patterns: [Regex.t()], exclude_patterns: [Regex.t()], min_size: non_neg_integer(), max_size: non_neg_integer() | :infinity, mime_types: [String.t()] }
@type poll_config() :: %{ initial: pos_integer(), max: pos_integer(), backoff_factor: float() }
@type t() :: %Sambex.HotFolder.Config{ base_path: String.t(), connection: atom() | nil, create_folders: boolean(), filters: filter_config(), folders: folder_config(), handler: handler_spec() | nil, handler_timeout: pos_integer(), max_retries: non_neg_integer(), password: String.t() | nil, poll_interval: poll_config(), url: String.t() | nil, username: String.t() | nil }
Functions
Returns all folder paths as a map.
Examples
iex> config = %Sambex.HotFolder.Config{base_path: "queue"}
iex> Sambex.HotFolder.Config.all_folder_paths(config)
%{
incoming: "queue/incoming",
processing: "queue/processing",
success: "queue/success",
errors: "queue/errors"
}
Returns the full path for a given folder type.
Examples
iex> config = %Sambex.HotFolder.Config{base_path: "queue", folders: %{incoming: "inbox"}}
iex> Sambex.HotFolder.Config.folder_path(config, :incoming)
"queue/inbox"
iex> config = %Sambex.HotFolder.Config{base_path: "", folders: %{success: "done"}}
iex> Sambex.HotFolder.Config.folder_path(config, :success)
"done"
Creates and validates a HotFolder configuration.
Examples
iex> {:ok, config} = Sambex.HotFolder.Config.new(%{
...> url: "smb://server/share",
...> username: "user",
...> password: "pass",
...> handler: &IO.inspect/1
...> })
iex> config.url
"smb://server/share"
iex> Sambex.HotFolder.Config.new(%{handler: &IO.inspect/1})
{:error, "Must provide either connection name or url+username+password"}
Creates and validates a HotFolder configuration, raising on error.
Examples
iex> config = Sambex.HotFolder.Config.new!(%{
...> connection: :my_connection,
...> handler: &IO.inspect/1
...> })
iex> config.connection
:my_connection
Validates a HotFolder configuration.
Returns {:ok, config}
if valid, {:error, reason}
otherwise.