diff --git a/app/controllers/active_storage/blobs_controller.rb b/app/controllers/active_storage/blobs_controller.rb index a8077b0bb..f91541300 100644 --- a/app/controllers/active_storage/blobs_controller.rb +++ b/app/controllers/active_storage/blobs_controller.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module ActiveStorage - class BlobsController < BaseController + class BlobsController < CustomBaseController include ActiveStorage::SetBlob include ActiveStorage::CheckBlobPermissions diff --git a/app/controllers/active_storage/base_controller.rb b/app/controllers/active_storage/custom_base_controller.rb similarity index 81% rename from app/controllers/active_storage/base_controller.rb rename to app/controllers/active_storage/custom_base_controller.rb index b9a3163ac..d5d8ce46f 100644 --- a/app/controllers/active_storage/base_controller.rb +++ b/app/controllers/active_storage/custom_base_controller.rb @@ -2,7 +2,7 @@ # The base controller for all ActiveStorage controllers. module ActiveStorage - class BaseController < ApplicationController + class CustomBaseController < ApplicationController include ActiveStorage::SetCurrent before_action do diff --git a/app/controllers/active_storage/representations_controller.rb b/app/controllers/active_storage/representations_controller.rb index 1f652ce82..e1a1a4fa8 100644 --- a/app/controllers/active_storage/representations_controller.rb +++ b/app/controllers/active_storage/representations_controller.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module ActiveStorage - class RepresentationsController < BaseController + class RepresentationsController < CustomBaseController include ActiveStorage::SetBlob include ActiveStorage::CheckBlobPermissions diff --git a/app/services/reports/docx/private_methods.rb b/app/services/reports/docx/private_methods.rb index 375fc1652..292c6f00f 100644 --- a/app/services/reports/docx/private_methods.rb +++ b/app/services/reports/docx/private_methods.rb @@ -98,7 +98,7 @@ module Reports::Docx::PrivateMethods image = TinyMceAsset.find_by(id: Base62.decode(elem.attributes['data-mce-token'].value)) next unless image - image_path = image_path(image) + image_path = image_path(image.image) dimension = FastImage.size(image_path) style = image_styling(elem, dimension) @@ -204,7 +204,7 @@ module Reports::Docx::PrivateMethods def asset_image_preparing(asset) return unless asset - image_path = image_path(asset) + image_path = image_path(asset.file) dimension = FastImage.size(image_path) x = dimension[0] @@ -292,13 +292,8 @@ module Reports::Docx::PrivateMethods } end - def image_path(asset) - image = if asset.class == Asset - asset.file - else - asset.image - end - image.service_url + def image_path(attachment) + attachment.service_url end def calculate_color_hsp(color) diff --git a/config/storage.yml b/config/storage.yml index fa3150876..964c17ebe 100644 --- a/config/storage.yml +++ b/config/storage.yml @@ -1,9 +1,9 @@ test: - service: Disk + service: CustomDisk root: <%= Rails.root.join("tmp/storage") %> local: - service: Disk + service: CustomDisk root: <%= Rails.root.join("storage") %> amazon: diff --git a/lib/active_storage/service/custom_disk_service.rb b/lib/active_storage/service/custom_disk_service.rb new file mode 100644 index 000000000..02119e0b2 --- /dev/null +++ b/lib/active_storage/service/custom_disk_service.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +require 'active_storage/service/disk_service' + +module ActiveStorage + class Service::CustomDiskService < Service::DiskService + def current_host + host = ActiveStorage::Current.host + host ||= Rails.application.secrets.mail_server_url + host = "http://#{host}" unless host.match?(/^http/) + host + end + end +end