diff options
author | George Claghorn <george@basecamp.com> | 2018-01-03 22:01:31 -0500 |
---|---|---|
committer | George Claghorn <george@basecamp.com> | 2018-01-03 22:01:31 -0500 |
commit | a72473f0320cc58bea1b47c856c62f015d5da82b (patch) | |
tree | 9c5051a4fbdcac0cd0795022a1769779561c52ae /activestorage/lib | |
parent | bce675eac49a8673d63ea41991f020aa3aa8c506 (diff) | |
download | rails-a72473f0320cc58bea1b47c856c62f015d5da82b.tar.gz rails-a72473f0320cc58bea1b47c856c62f015d5da82b.tar.bz2 rails-a72473f0320cc58bea1b47c856c62f015d5da82b.zip |
Configure previewer/analyzer command paths centrally
Diffstat (limited to 'activestorage/lib')
5 files changed, 15 insertions, 23 deletions
diff --git a/activestorage/lib/active_storage.rb b/activestorage/lib/active_storage.rb index 4e6c02f71b..01fd0f4415 100644 --- a/activestorage/lib/active_storage.rb +++ b/activestorage/lib/active_storage.rb @@ -41,5 +41,6 @@ module ActiveStorage mattr_accessor :queue mattr_accessor :previewers, default: [] mattr_accessor :analyzers, default: [] + mattr_accessor :paths, default: {} mattr_accessor :variable_content_types, default: [] end diff --git a/activestorage/lib/active_storage/analyzer/video_analyzer.rb b/activestorage/lib/active_storage/analyzer/video_analyzer.rb index 1c144baa37..09e8605a59 100644 --- a/activestorage/lib/active_storage/analyzer/video_analyzer.rb +++ b/activestorage/lib/active_storage/analyzer/video_analyzer.rb @@ -19,8 +19,6 @@ module ActiveStorage # This analyzer requires the {ffmpeg}[https://www.ffmpeg.org] system library, which is not provided by Rails. You must # install ffmpeg yourself to use this analyzer. class Analyzer::VideoAnalyzer < Analyzer - class_attribute :ffprobe_path, default: "ffprobe" - def self.accept?(blob) blob.video? end @@ -89,5 +87,9 @@ module ActiveStorage logger.info "Skipping video analysis because ffmpeg isn't installed" {} end + + def ffprobe_path + ActiveStorage.paths[:ffprobe] || "ffprobe" + end end end diff --git a/activestorage/lib/active_storage/engine.rb b/activestorage/lib/active_storage/engine.rb index b41d8bb4d7..d5c71670ff 100644 --- a/activestorage/lib/active_storage/engine.rb +++ b/activestorage/lib/active_storage/engine.rb @@ -16,8 +16,8 @@ module ActiveStorage config.active_storage = ActiveSupport::OrderedOptions.new config.active_storage.previewers = [ ActiveStorage::Previewer::PDFPreviewer, ActiveStorage::Previewer::VideoPreviewer ] config.active_storage.analyzers = [ ActiveStorage::Analyzer::ImageAnalyzer, ActiveStorage::Analyzer::VideoAnalyzer ] - config.active_storage.variable_content_types = [ "image/png", "image/gif", "image/jpg", "image/jpeg", "image/vnd.adobe.photoshop" ] config.active_storage.paths = ActiveSupport::OrderedOptions.new + config.active_storage.variable_content_types = [ "image/png", "image/gif", "image/jpg", "image/jpeg", "image/vnd.adobe.photoshop" ] config.eager_load_namespaces << ActiveStorage @@ -27,6 +27,7 @@ module ActiveStorage ActiveStorage.queue = app.config.active_storage.queue ActiveStorage.previewers = app.config.active_storage.previewers || [] ActiveStorage.analyzers = app.config.active_storage.analyzers || [] + ActiveStorage.paths = app.config.active_storage.paths || {} ActiveStorage.variable_content_types = app.config.active_storage.variable_content_types || [] end end @@ -71,21 +72,5 @@ module ActiveStorage end end end - - initializer "active_storage.paths" do - config.after_initialize do |app| - if ffprobe_path = app.config.active_storage.paths.ffprobe - ActiveStorage::Analyzer::VideoAnalyzer.ffprobe_path = ffprobe_path - end - - if ffmpeg_path = app.config.active_storage.paths.ffmpeg - ActiveStorage::Previewer::VideoPreviewer.ffmpeg_path = ffmpeg_path - end - - if mutool_path = app.config.active_storage.paths.mutool - ActiveStorage::Previewer::PDFPreviewer.mutool_path = mutool_path - end - end - end end end diff --git a/activestorage/lib/active_storage/previewer/pdf_previewer.rb b/activestorage/lib/active_storage/previewer/pdf_previewer.rb index b84aefcc9c..426ff51eb1 100644 --- a/activestorage/lib/active_storage/previewer/pdf_previewer.rb +++ b/activestorage/lib/active_storage/previewer/pdf_previewer.rb @@ -2,8 +2,6 @@ module ActiveStorage class Previewer::PDFPreviewer < Previewer - class_attribute :mutool_path, default: "mutool" - def self.accept?(blob) blob.content_type == "application/pdf" end @@ -20,5 +18,9 @@ module ActiveStorage def draw_first_page_from(file, &block) draw mutool_path, "draw", "-F", "png", "-o", "-", file.path, "1", &block end + + def mutool_path + ActiveStorage.paths[:mutool] || "mutool" + end end end diff --git a/activestorage/lib/active_storage/previewer/video_previewer.rb b/activestorage/lib/active_storage/previewer/video_previewer.rb index 5d06e33f44..2f28a3d341 100644 --- a/activestorage/lib/active_storage/previewer/video_previewer.rb +++ b/activestorage/lib/active_storage/previewer/video_previewer.rb @@ -2,8 +2,6 @@ module ActiveStorage class Previewer::VideoPreviewer < Previewer - class_attribute :ffmpeg_path, default: "ffmpeg" - def self.accept?(blob) blob.video? end @@ -21,5 +19,9 @@ module ActiveStorage draw ffmpeg_path, "-i", file.path, "-y", "-vcodec", "png", "-vf", "thumbnail", "-vframes", "1", "-f", "image2", "-", &block end + + def ffmpeg_path + ActiveStorage.paths[:ffmpeg] || "ffmpeg" + end end end |