Skip to content

Add endpoint for accessing variant screenshots#233

Open
smudge wants to merge 10 commits intoBetterment:mainfrom
smudge:split-report-config
Open

Add endpoint for accessing variant screenshots#233
smudge wants to merge 10 commits intoBetterment:mainfrom
smudge:split-report-config

Conversation

@smudge
Copy link
Copy Markdown
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 a team and jonmauney November 13, 2024 17:38
Comment thread .gitignore
/.powenv
/.env.local
/db/seed_apps.yml
/db/seeds/*.yml
Copy link
Copy Markdown
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.

Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.

config.hosts << "testtrack.test"
Copy link
Copy Markdown
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 thread db/seeds.rb
Comment on lines +27 to +30
Admin.find_or_create_by!(email: 'admin@example.org') do |user|
user.password = 'password'
user.password_confirmation = 'password'
end
Copy link
Copy Markdown
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.


def max_size
ENV['ATTACHMENT_MAX_SIZE'] || 512.kilobytes
ENV['ATTACHMENT_MAX_SIZE']&.to_i || 1.megabyte
Copy link
Copy Markdown
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.

Copy link
Copy Markdown

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 thread db/seeds.rb
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
Copy Markdown
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)
Copy link
Copy Markdown

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"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔨

Copy link
Copy Markdown

@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