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) ⇒ Hash{Symbol => String}

Builds display metadata for a download URL.

Parameters:

  • url (String, #to_s)

    the download URL to present

Returns:

  • (Hash{Symbol => String})

    { url:, filename:, worker: } -- always
    a Hash, never nil; falls back to the URL basename + "Download" for
    non-upload URLs (zip exports, tempfile results, etc.)



25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/concerns/file_download_presenter.rb', line 25

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