-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add endpoint for accessing variant screenshots #233
base: main
Are you sure you want to change the base?
Conversation
@@ -25,6 +25,7 @@ | |||
/.powenv | |||
/.env.local | |||
/db/seed_apps.yml | |||
/db/seeds/*.yml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a step to seeds.rb
that will conditionally read from any Rails fixture files placed in this folder.
@@ -1,6 +1,8 @@ | |||
Rails.application.configure do | |||
# Settings specified here will take precedence over those in config/application.rb. | |||
|
|||
config.hosts << "testtrack.test" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A conventional hostname for local dev. (I used puma-dev
to link the DNS to the running server.)
Admin.find_or_create_by!(email: '[email protected]') do |user| | ||
user.password = 'password' | ||
user.password_confirmation = 'password' | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seed the development DB with an admin user.
@@ -19,7 +19,7 @@ def storage_settings | |||
end | |||
|
|||
def max_size | |||
ENV['ATTACHMENT_MAX_SIZE'] || 512.kilobytes | |||
ENV['ATTACHMENT_MAX_SIZE']&.to_i || 1.megabyte |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Increasing the default to 1 megabyte (screen resolutions have gotten a bit bigger since 2017!)
Also casting the max size value to an int, since it would otherwise come in as a string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is 1mb a reasonable size for gifs? any cost to making this higher?
require 'active_record/fixtures' | ||
fixtures_dir = File.join(Rails.root, 'db/seeds') | ||
fixture_files = Dir.glob('db/seeds/*.yml').map { |f| File.basename(f, '.yml') } | ||
|
||
ActiveRecord::FixtureSet.create_fixtures(fixtures_dir, fixture_files) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See here
variant_detail = split.variant_details.find_by!(variant: variant) | ||
raise ActiveRecord::RecordNotFound unless variant_detail.screenshot_file_name? | ||
|
||
redirect_to variant_detail.screenshot.expiring_url(300) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
|
||
describe 'GET /variant.ext' do | ||
it 'returns a 404' do | ||
get "/admin/splits/#{split.id}/screenshots/hammer_time.jpg" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔨
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
Summary
This adds a new unauthenticated endpoint for accessing variant screenshots:
A split's UUID must be known in order to construct this path, and when requested it will 302 redirect to a signed, expiring S3 URL (via paperclip's
expiring_url
method).This this also adds a column to the splits show page that links out to the screenshot:
Other Information
A made a few other changes to improve the local dev experience, which I'll comment on below.