Module: FileDownloadPresenter

Included in:
Controllers::WarehouseStreamActions, FileDownloadsHelper
Defined in:
app/concerns/file_download_presenter.rb

Overview

Resolves a download URL into display metadata for the global Jobs offcanvas.

Without this, URLs that point to /uploads/:id surface in the offcanvas as
their bare numeric ID (the URL path basename) under a generic "Download"
header -- useless for telling apart "Carton Label SSCC123" from
"Pick Slip Pdf for SO718463". When the URL matches a known Upload, we
substitute the Upload's attachment_name (real filename) and humanized
category (worker label) so the offcanvas card carries real context.

Falls back to URL basename + "Download" for non-upload URLs (zip exports,
tempfile results, etc.) so callers don't have to special-case anything.

Mixed into:

  • Controllers::WarehouseStreamActions (Turbo-Stream interception path)
  • FileDownloadsHelper (HTML render path)

Instance Method Summary collapse

Instance Method Details

#file_download_entry(url) ⇒ Object

Returns { url:, filename:, worker: } -- always a Hash, never nil.



20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/concerns/file_download_presenter.rb', line 20

def file_download_entry(url)
  upload = lookup_upload(url)
  if upload
    {
      url: url,
      filename: upload.attachment_name.presence || "Upload #{upload.id}",
      worker: upload.title.presence || 'Download'
    }
  else
    { url: url, filename: derive_filename_from_url(url), worker: 'Download' }
  end
end