Skip to content

Commit

Permalink
TEMP: Serve assets from S3 if they exist
Browse files Browse the repository at this point in the history
This is a temporary change that will allow us to test redirecting to and
serving assets from S3 on integration.

This commit causes some tests to fail but we're not worrying about that
as we're not expecting this commit to end up in master.

We've tested the change locally and are happy that it results in a
redirect to assets uploaded to S3. Assets not on S3 continue to be
served directly from the filesystem.
  • Loading branch information
chrisroos committed Aug 9, 2017
1 parent fa1cbba commit d1b95c5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/media_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def download
protected

def redirect_to_s3?
AssetManager.redirect_all_asset_requests_to_s3 || params[:redirect_to_s3].present?
asset.uploaded_to_s3?
end

def stream_from_s3?
Expand Down
3 changes: 3 additions & 0 deletions app/models/asset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class Asset
field :access_limited, type: Boolean, default: false
field :organisation_slug, type: String

field :uploaded_to_s3, type: Boolean, default: false

validates :file, presence: true
validates :organisation_slug, presence: true, if: :access_limited?

Expand Down Expand Up @@ -72,6 +74,7 @@ def accessible_by?(user)

def save_to_cloud_storage
Services.cloud_storage.save(self, cloud_storage_options)
update_attribute(:uploaded_to_s3, true)
rescue => e
Airbrake.notify_or_ignore(e, params: { id: self.id, filename: self.filename })
raise
Expand Down

0 comments on commit d1b95c5

Please sign in to comment.