Skip to content
This repository has been archived by the owner on Aug 13, 2020. It is now read-only.

Cloudfront solution for ActiveStorage #115

Merged
merged 2 commits into from
Dec 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/lib/extensions/active_storage_blob.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,17 @@ def quote_column(name)
def set_indexed_metadata
self.indexed_metadata = metadata
end

def cloudfront_host
ENV["CLOUDFRONT_HOST"]
end

def cloudfront_url
return service_url unless cloudfront_host
return service_url unless service.is_a?(ActiveStorage::Service::S3Service)
uri = URI(service_url)
path = uri.path.gsub("/#{service.bucket.name}", "")
"https://#{cloudfront_host}#{path}"
end
end
end
2 changes: 1 addition & 1 deletion app/views/ad_templates/default/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<span>
<span class="cf-wrapper">
<a data-href="campaign_url" class="cf-img-wrapper" target="_blank" rel="noopener">
<%= image_tag url_for(@campaign.creative.large_image), border: 0, height: 100, width: 130, class: "cf-img" %>
<%= image_tag @campaign.creative.large_image.cloudfront_url, border: 0, height: 100, width: 130, class: "cf-img" %>
</a>
<a data-href="campaign_url" class="cf-text" target="_blank" rel="noopener">
<strong><%= @campaign.creative.headline %></strong>
Expand Down
2 changes: 1 addition & 1 deletion app/views/ad_templates/image-centered/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div id="cf">
<span class="cf-wrapper">
<a data-href="campaign_url" class="cf-img-wrapper" target="_blank" rel="noopener">
<%= image_tag url_for(@campaign.creative.large_image), border: 0, height: 100, width: 130, class: "cf-img" %>
<%= image_tag @campaign.creative.large_image.cloudfront_url, border: 0, height: 100, width: 130, class: "cf-img" %>
</a>
<a data-href="campaign_url" class="cf-text" target="_blank" rel="noopener">
<strong><%= @campaign.creative.headline %></strong>
Expand Down
2 changes: 1 addition & 1 deletion app/views/ad_templates/image-only/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<span class="cf-wrapper">
<div class="cf-header">supported by</div>
<a data-href="campaign_url" class="cf-img-wrapper" target="_blank" rel="noopener">
<%= image_tag url_for(@campaign.creative.small_image), class: "cf-img" %>
<%= image_tag @campaign.creative.small_image.cloudfront_url, class: "cf-img" %>
</a>
<a href="https://codefund.io" class="cf-powered-by" target="_blank" rel="noopener">
<em>ethical</em> ad by CodeFund
Expand Down
2 changes: 1 addition & 1 deletion app/views/ad_templates/square/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div id="cf">
<span class="cf-wrapper">
<a data-href="campaign_url" class="cf-img-wrapper" target="_blank" rel="noopener">
<%= image_tag url_for(@campaign.creative.large_image), class: "cf-img" %>
<%= image_tag @campaign.creative.large_image.cloudfront_url, class: "cf-img" %>
</a>
<a data-href="campaign_url" class="cf-text" target="_blank" rel="noopener">
<strong><%= @campaign.creative.headline %></strong>
Expand Down
2 changes: 1 addition & 1 deletion app/views/ad_templates/vertical/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div id="cf">
<span class="cf-wrapper">
<a data-href="campaign_url" class="cf-img-wrapper" target="_blank" rel="noopener">
<%= image_tag url_for(@campaign.creative.small_image), border: 0, height: 100, width: 130, class: "cf-img" %>
<%= image_tag @campaign.creative.small_image.cloudfront_url, border: 0, height: 100, width: 130, class: "cf-img" %>
</a>
<a data-href="campaign_url" class="cf-text" target="_blank" rel="noopener">
<strong><%= @campaign.creative.headline %></strong>
Expand Down