class FilesController < ApplicationController
  skip_forgery_protection

  def show
    result = FileService.new.show(FileShowInputDto.new(path: params[:path]))
    case result.type
    when :redirect  then redirect_to result.url, status: :moved_permanently
    when :file
      ext = File.extname(result.path.to_s).delete_prefix(".")
      mime = Mime::Type.lookup_by_extension(ext) || "application/octet-stream"
      send_file result.path, disposition: "inline", type: mime
    when :not_found then head :not_found
    end
  end
end
