Skip to content

Commit

Permalink
Remove Shrine (#411)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcraigk authored Nov 4, 2024
1 parent 8550dba commit d1a67f3
Show file tree
Hide file tree
Showing 51 changed files with 151 additions and 864 deletions.
6 changes: 2 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ RUN yarn install

COPY . .

# Expose Shrine attachments as public cacheable URLs
# TODO: Remove after grace period
# Expose legacy Shrine files
RUN ln -sf /content/tracks/audio_files ./public/audio

# Expose ActiveStorage attachments as public cacheable URLs
RUN ln -sf /content/active_storage ./public/attachments

EXPOSE 3000
CMD bundle exec puma -b tcp://0.0.0.0:3000
4 changes: 0 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby "3.3.3"

gem "actionpack-action_caching"
gem "chunky_png"
gem "chronic"
gem "dalli"
gem "friendly_id"
gem "dry-initializer"
gem "geocoder"
Expand All @@ -18,7 +16,6 @@ gem "grape-swagger-entity"
gem "htmlentities"
gem "image_processing"
gem "jwt"
gem "highline"
gem "nokogiri"
gem "pg"
gem "pg_search"
Expand All @@ -35,7 +32,6 @@ gem "sidekiq"
gem "sidekiq-scheduler"
gem "sitemap_generator"
gem "shakapacker"
gem "shrine"
gem "slim"
gem "sorcery"
gem "typhoeus"
Expand Down
15 changes: 1 addition & 14 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,8 @@ GEM
chunky_png (1.4.0)
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
content_disposition (1.0.0)
crass (1.0.6)
csv (3.3.0)
dalli (3.2.8)
date (3.4.0)
declarative (0.0.20)
diff-lcs (1.5.1)
Expand All @@ -118,8 +116,6 @@ GEM
dotenv-rails (3.1.4)
dotenv (= 3.1.4)
railties (>= 6.1)
down (5.4.2)
addressable (~> 2.8)
drb (2.2.1)
dry-core (1.0.2)
concurrent-ruby (~> 1.0)
Expand Down Expand Up @@ -214,8 +210,6 @@ GEM
grape-entity (~> 1)
grape-swagger (~> 2)
hashie (5.0.0)
highline (3.1.1)
reline
htmlentities (4.3.4)
httpclient (2.8.3)
i18n (1.14.6)
Expand Down Expand Up @@ -389,7 +383,7 @@ GEM
rubocop-ast (>= 1.32.2, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.33.0)
rubocop-ast (1.33.1)
parser (>= 3.3.1.0)
rubocop-capybara (2.21.0)
rubocop (~> 1.41)
Expand Down Expand Up @@ -450,9 +444,6 @@ GEM
semantic_range (>= 2.3.0)
shoulda-matchers (6.4.0)
activesupport (>= 5.2.0)
shrine (3.6.0)
content_disposition (~> 1.0)
down (~> 5.1)
sidekiq (7.3.4)
connection_pool (>= 2.3.0)
logger
Expand Down Expand Up @@ -524,8 +515,6 @@ DEPENDENCIES
capybara-email
capybara-screenshot
chronic
chunky_png
dalli
dotenv-rails
dry-initializer
factory_bot_rails
Expand All @@ -537,7 +526,6 @@ DEPENDENCIES
grape-entity
grape-swagger
grape-swagger-entity
highline
htmlentities
image_processing
jwt
Expand Down Expand Up @@ -565,7 +553,6 @@ DEPENDENCIES
sentry-ruby
shakapacker
shoulda-matchers
shrine
sidekiq
sidekiq-scheduler
simplecov
Expand Down
2 changes: 1 addition & 1 deletion app/api/api_v2/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ApiV2::Search < ApiV2::Base
helpers do
def fetch_results(term, scope)
Rails.cache.fetch("api/v2/search/#{term}/#{scope}") do
SearchService.new(term, scope).call
SearchService.call(term, scope)
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def index
private

def results
@results ||= SearchService.new(params[:term]).call
@results ||= SearchService.call(params[:term])
end

def respond_with_invalid_term
Expand Down
48 changes: 9 additions & 39 deletions app/controllers/downloads_controller.rb
Original file line number Diff line number Diff line change
@@ -1,55 +1,25 @@
class DownloadsController < ApplicationController
def download_track
raise ActiveRecord::RecordNotFound if track.blank?

if track.mp3_audio.attached?
send_active_storage_audio_as_attachment
elsif track.audio_file.exists?
send_shrine_audio_as_attachment
else
head :not_found
end
return head(:not_found) unless track.mp3_audio.attached?
send_file_response(track.mp3_audio, "attachment", "Phish #{track.show.date} #{track.title}.mp3")
end

def download_blob
raise ActiveRecord::RecordNotFound if blob.blank?
send_blob_file_inline
send_file_response(blob, "inline", blob.filename.to_s)
end

private

def send_active_storage_audio_as_attachment
add_cache_header
send_file \
ActiveStorage::Blob.service.send(:path_for, track.mp3_audio.blob.key),
type: "audio/mpeg",
disposition: "attachment",
filename: "Phish #{track.show.date} #{track.title}.mp3",
length: track.mp3_audio.blob.byte_size
rescue ActionController::MissingFile
head :not_found
end

def send_shrine_audio_as_attachment
add_cache_header
send_file \
track.audio_file.to_io.path,
type: "audio/mpeg",
disposition: "attachment",
filename: "Phish #{track.show.date} #{track.title}.mp3",
length: track.audio_file.size
rescue ActionController::MissingFile
head :not_found
end

def send_blob_file_inline
def send_file_response(file, disposition, filename)
add_cache_header
send_file \
ActiveStorage::Blob.service.send(:path_for, blob.key),
type: blob.content_type || "application/octet-stream",
disposition: "inline",
filename: blob.filename.to_s,
length: blob.byte_size
ActiveStorage::Blob.service.send(:path_for, file.key),
type: file.content_type || "application/octet-stream",
disposition:,
filename:,
length: file.byte_size
rescue ActionController::MissingFile
head :not_found
end
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/jamcharts_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class JamchartsJob
include Sidekiq::Job

def perform
JamchartsImporter.new(api_key).call
JamchartsImporter.call(api_key)
end

private
Expand Down
35 changes: 14 additions & 21 deletions app/models/track.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ class Track < ApplicationRecord
has_one_attached :mp3_audio
has_one_attached :png_waveform

# Deprecated Shrine attachments
include AudioFileUploader::Attachment(:audio_file)
# validates :audio_file, presence: true
include WaveformPngUploader::Attachment(:waveform_png)

include PgSearch::Model
pg_search_scope(
:kinda_matching,
Expand All @@ -29,7 +24,6 @@ class Track < ApplicationRecord
validates :songs, length: { minimum: 1 }

before_save :generate_slug
after_update :process_audio_file, if: :saved_change_to_audio_file_data

scope :chronological, -> { joins(:show).order("shows.date") }
scope :tagged_with, ->(tag_slug) { joins(:tags).where(tags: { slug: tag_slug }) }
Expand All @@ -48,22 +42,20 @@ def set_name
end

def apply_id3_tags
Id3TagService.new(self).call
Id3TagService.call(self)
end

def generate_slug(force: false)
return if !force && slug.present?
self.slug = TrackSlugGenerator.new(self).call
self.slug = TrackSlugGenerator.call(self)
end

def mp3_url
blob_url(mp3_audio) ||
audio_file.url(host: App.content_base_url).gsub("tracks/audio_files", "audio")
blob_url(mp3_audio)
end

def waveform_image_url
blob_url(png_waveform) ||
waveform_png&.url(host: App.content_base_url).gsub("tracks/audio_files", "audio")
blob_url(png_waveform)
end

def urls
Expand All @@ -74,21 +66,22 @@ def urls
}
end

def save_duration
mp3_audio.analyze unless mp3_audio.analyzed?
duration_ms = (mp3_audio.blob.metadata[:duration] * 1000).round
update_column(:duration, duration_ms)
end

def generate_waveform_image(purge_cache: false)
WaveformImageService.new(self).call
WaveformImageService.call(self)
end

def process_audio_file
return if Rails.env.test?
def process_mp3_audio
save_duration
show.save_duration
apply_id3_tags
generate_waveform_image
end

private

def save_duration
mp3_audio.analyze unless mp3_audio.analyzed?
duration_ms = (mp3_audio.blob.metadata[:duration] * 1000).round
update_column(:duration, duration_ms)
end
end
2 changes: 1 addition & 1 deletion app/services/album_cover_service.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "mini_magick"

class AlbumCoverService < BaseService
class AlbumCoverService < ApplicationService
param :show

def call
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class BaseService
class ApplicationService
extend Dry::Initializer

def self.call(...)
Expand Down
2 changes: 1 addition & 1 deletion app/services/bustout_tag_service.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class BustoutTagService < BaseService
class BustoutTagService < ApplicationService
MIN_GAP = 100

param :show
Expand Down
37 changes: 0 additions & 37 deletions app/services/cover_art_generator.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/services/cover_art_image_service.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CoverArtImageService < BaseService
class CoverArtImageService < ApplicationService
param :show
option :dry_run, default: -> { false }

Expand Down
2 changes: 1 addition & 1 deletion app/services/cover_art_prompt_service.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CoverArtPromptService < BaseService
class CoverArtPromptService < ApplicationService
param :show

HUES = %w[
Expand Down
2 changes: 1 addition & 1 deletion app/services/debut_tag_service.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class DebutTagService < BaseService
class DebutTagService < ApplicationService
param :show

def call
Expand Down
2 changes: 1 addition & 1 deletion app/services/gap_service.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class GapService < BaseService
class GapService < ApplicationService
param :show

def call
Expand Down
14 changes: 8 additions & 6 deletions app/services/google_spreadsheet_fetcher.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
class GoogleSpreadsheetFetcher
class GoogleSpreadsheetFetcher < ApplicationService
attr_reader :spreadsheet_id, :range, :has_headers

OOB_URI = "urn:ietf:wg:oauth:2.0:oob".freeze
TOKEN_PATH = Rails.root.join("config/google_api.yml")

def initialize(spreadsheet_id, range, opts = {})
@spreadsheet_id = spreadsheet_id
@range = range
@has_headers = opts[:headers].nil? ? true : opts[:headers]
end
param :spreadsheet_id
param :range
option :opts, optional: true, default: -> { {} }

def call
service.authorization = authorize
Expand Down Expand Up @@ -75,4 +73,8 @@ def authorize
base_url: OOB_URI
)
end

def has_headers
@has_headers = opts[:headers].nil? ? true : opts[:headers]
end
end
Loading

0 comments on commit d1a67f3

Please sign in to comment.