Sha256: 546ce67cff9bbc5882c94ec790375fc8e681f54dd018b3596c3298c93e1c5cda

Contents?: true

Size: 853 Bytes

Versions: 4

Compression:

Stored size: 853 Bytes

Contents

# frozen_string_literal: true

module RailsDevtools
  class HostAppImagesController < BaseController
    def show
      return head :not_found unless image?

      image_path = find_source_image
      return head :not_found unless image_path

      mime_type = Mime::Type.lookup_by_extension(params[:format])

      send_file image_path, type: mime_type, disposition: "inline"
    end

    private

    def image?
      ImageAssets::ImageInfo::IMAGE_EXTENSIONS.include?(".#{params[:format]}")
    end

    def find_source_image
      filename = CGI.unescape(File.basename(params[:path]))
      found = nil

      RailsDevtools.asset_config.paths.each do |base_path|
        paths = Dir.glob("#{base_path}/**/*#{filename}*")
        found = paths.find { |file_path| File.file?(file_path) }
        break if found
      end

      found
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rails_devtools-0.1.3 app/controllers/rails_devtools/host_app_images_controller.rb
rails_devtools-0.1.2 app/controllers/rails_devtools/host_app_images_controller.rb
rails_devtools-0.1.1 app/controllers/rails_devtools/host_app_images_controller.rb
rails_devtools-0.1.0 app/controllers/rails_devtools/host_app_images_controller.rb