Module: VenusMediaLibrary::ImagesHelper

Included in:
ImagesController, PickersController
Defined in:
app/helpers/venus_media_library/images_helper.rb

Overview

Shared image URL/payload logic. Included in the views (automatically) and in ImagesController so the HTML grid and the JSON response stay in sync.

Instance Method Summary collapse

Instance Method Details

#ml_blob_url(blob) ⇒ Object

Permanent URL to the original file. Active Storage route helpers live on the host app, so they are reached through the main_app proxy. With url_type = :proxy the URL streams through Rails (works for private buckets and external crawlers); the default :redirect 302s to the storage URL.



23
24
25
26
27
28
29
30
31
# File 'app/helpers/venus_media_library/images_helper.rb', line 23

def ml_blob_url(blob)
  if VenusMediaLibrary.configuration.url_type == :proxy
    main_app.rails_storage_proxy_url(blob)
  else
    main_app.rails_blob_url(blob)
  end
rescue StandardError
  main_app.rails_blob_path(blob)
end

#ml_image_payload(blob) ⇒ Object

A serializable description of a blob used by the JSON API and the tiles.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/helpers/venus_media_library/images_helper.rb', line 6

def ml_image_payload(blob)
  {
    id:           blob.id,
    signed_id:    blob.signed_id,
    filename:     blob.filename.to_s,
    content_type: blob.content_type,
    byte_size:    blob.byte_size,
    created_at:   blob.created_at,
    url:          ml_blob_url(blob),
    thumb_url:    ml_thumb_url(blob)
  }
end

#ml_thumb_url(blob) ⇒ Object

Small variant used for the grid thumbnail. Falls back to the original URL when the blob can't be variated (e.g. SVG).



35
36
37
38
39
40
41
42
43
44
# File 'app/helpers/venus_media_library/images_helper.rb', line 35

def ml_thumb_url(blob)
  if blob.variable?
    w, h = VenusMediaLibrary.configuration.thumbnail_size
    main_app.rails_representation_url(blob.variant(resize_to_limit: [ w, h ]))
  else
    ml_blob_url(blob)
  end
rescue StandardError
  ml_blob_url(blob)
end