]> git.openstreetmap.org Git - rails.git/blob - config/initializers/active_storage.rb
Run any Active Storage jobs in the storage queue
[rails.git] / config / initializers / active_storage.rb
1 Rails.application.config.active_storage.queue = :storage
2
3 Rails.configuration.after_initialize do
4   require "active_storage/service/s3_service"
5   require_dependency "active_storage/variant"
6
7   module OpenStreetMap
8     module ActiveStorage
9       module Variant
10         private
11
12         def upload(image)
13           File.open(image.path, "r") { |file| service.upload(key, file, :content_type => content_type) }
14         end
15       end
16
17       module S3Service
18         def upload(key, io, content_type:, **options)
19           @upload_options[:content_type] = content_type
20           super(key, io, **options)
21           @upload_options.delete(:content_type)
22         end
23       end
24     end
25   end
26
27   ActiveStorage::Variant.prepend(OpenStreetMap::ActiveStorage::Variant)
28   ActiveStorage::Service::S3Service.prepend(OpenStreetMap::ActiveStorage::S3Service)
29
30   ActiveSupport::Reloader.to_complete do
31     ActiveStorage::Variant.prepend(OpenStreetMap::ActiveStorage::Variant)
32   end
33 end