Skip to content
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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

smudge
Copy link
Member

@smudge smudge commented Nov 13, 2024

Summary

This adds a new unauthenticated endpoint for accessing variant screenshots:

/admin/splits/{split_uuid}/screenshots/{variant}.{extension}

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:

Screenshot 2024-11-13 at 12 34 59 PM

Other Information

A made a few other changes to improve the local dev experience, which I'll comment on below.

@smudge smudge requested review from jonmauney and a team November 13, 2024 17:38
@@ -25,6 +25,7 @@
/.powenv
/.env.local
/db/seed_apps.yml
/db/seeds/*.yml
Copy link
Member Author

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"
Copy link
Member Author

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.)

Comment on lines +27 to +30
Admin.find_or_create_by!(email: '[email protected]') do |user|
user.password = 'password'
user.password_confirmation = 'password'
end
Copy link
Member Author

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
Copy link
Member Author

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.

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?

Comment on lines +12 to +16
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)
Copy link
Member Author

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)

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"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔨

Copy link

@jonmauney jonmauney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants