Class: ActiveCanvas::Media

Inherits:
ApplicationRecord show all
Defined in:
app/models/active_canvas/media.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.public_uploads_warnedObject

Returns the value of attribute public_uploads_warned.



16
17
18
# File 'app/models/active_canvas/media.rb', line 16

def public_uploads_warned
  @public_uploads_warned
end

Instance Method Details

#as_json_for_editorObject



65
66
67
68
69
70
71
72
73
74
# File 'app/models/active_canvas/media.rb', line 65

def as_json_for_editor
  {
    id: id,
    src: url,
    name: filename,
    type: content_type,
    width: ["width"],
    height: ["height"]
  }
end

#metadataObject



31
32
33
# File 'app/models/active_canvas/media.rb', line 31

def 
  super || {}
end

#public_urlObject



53
54
55
56
57
58
59
60
61
62
63
# File 'app/models/active_canvas/media.rb', line 53

def public_url
  return nil unless file.attached?

  # Returns the direct public URL for cloud storage
  # or the rails blob URL for local storage
  if file.blob.service.respond_to?(:url)
    file.url(expires_in: nil) rescue file.url
  else
    url
  end
end

#urlObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/models/active_canvas/media.rb', line 35

def url
  return nil unless file.attached?

  if ActiveCanvas.config.public_uploads &&
     file.blob.service.respond_to?(:public?) &&
     file.blob.service.public?
    # NOTE: public services serve the blob directly; the SVG attachment
    # disposition (see #svg_disposition_option) is NOT applied here. For
    # public SVG serving, use a separate origin/bucket. See README "Media & storage".
    file.url
  else
    warn_if_public_uploads_misconfigured
    Rails.application.routes.url_helpers.rails_blob_url(file, **blob_url_options)
  end
rescue ArgumentError
  Rails.application.routes.url_helpers.rails_blob_url(file, only_path: true, **svg_disposition_option)
end