Class: Slk::Services::FileDownloader
- Inherits:
-
Object
- Object
- Slk::Services::FileDownloader
- Defined in:
- lib/slk/services/file_downloader.rb
Overview
Downloads Slack message files and attachment images to XDG cache dir. Authed files (url_private_download) require workspace headers. Public attachment images (image_url) are fetched without auth. rubocop:disable Metrics/ClassLength
Constant Summary collapse
- NETWORK_ERRORS =
[ SocketError, Errno::ECONNREFUSED, Errno::ETIMEDOUT, Net::OpenTimeout, Net::ReadTimeout, URI::InvalidURIError, OpenSSL::SSL::SSLError ].freeze
- IMAGE_TYPES =
%w[png jpg jpeg gif bmp webp svg].freeze
- MAX_REDIRECTS =
3
Instance Method Summary collapse
-
#download_message_files(messages, workspace) ⇒ Object
Download all files from a list of messages, returning a hash of file_id => local_path for files and attachment index => local_path for attachments.
-
#initialize(cache_dir:, on_debug: nil) ⇒ FileDownloader
constructor
A new instance of FileDownloader.
Constructor Details
#initialize(cache_dir:, on_debug: nil) ⇒ FileDownloader
Returns a new instance of FileDownloader.
23 24 25 26 |
# File 'lib/slk/services/file_downloader.rb', line 23 def initialize(cache_dir:, on_debug: nil) @cache_dir = cache_dir @on_debug = on_debug end |
Instance Method Details
#download_message_files(messages, workspace) ⇒ Object
Download all files from a list of messages, returning a hash of file_id => local_path for files and attachment index => local_path for attachments.
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/slk/services/file_downloader.rb', line 30 def (, workspace) files_dir = ensure_workspace_dir(workspace.name) file_paths = {} .each do || download_files(.files, files_dir, workspace, file_paths) (., .ts, files_dir, file_paths) end file_paths end |