class Refile::App
A Rack application which can be mounted or run on its own.
@example mounted in Rails
Rails.application.routes.draw do mount Refile::App.new, at: "attachments", as: :refile_app end
@example as standalone app
require "refile" run Refile::App.new
Private Instance Methods
backend()
click to toggle source
# File lib/refile/app.rb, line 141 def backend Refile.backends.fetch(params[:backend]) do |name| log_error("Could not find backend: #{name}") halt 404 end end
download_allowed?()
click to toggle source
# File lib/refile/app.rb, line 114 def download_allowed? Refile.allow_downloads_from == :all or Refile.allow_downloads_from.include?(params[:backend]) end
file()
click to toggle source
# File lib/refile/app.rb, line 148 def file file = backend.get(params[:id]) unless file.exists? log_error("Could not find attachment by id: #{params[:id]}") halt 404 end file.download end
log_error(message)
click to toggle source
# File lib/refile/app.rb, line 164 def log_error(message) logger.error "#{self.class.name}: #{message}" end
logger()
click to toggle source
# File lib/refile/app.rb, line 122 def logger Refile.logger end
processor()
click to toggle source
# File lib/refile/app.rb, line 157 def processor Refile.processors.fetch(params[:processor]) do |name| log_error("Could not find processor: #{name}") halt 404 end end
stream_file(file)
click to toggle source
# File lib/refile/app.rb, line 126 def stream_file(file) expires Refile.content_max_age, :public if file.respond_to?(:path) path = file.path else path = Dir::Tmpname.create(params[:id]) {} IO.copy_stream file, path end filename = request.path.split("/").last send_file path, filename: filename, disposition: "inline", type: ::File.extname(request.path) end
upload_allowed?()
click to toggle source
# File lib/refile/app.rb, line 118 def upload_allowed? Refile.allow_uploads_to == :all or Refile.allow_uploads_to.include?(params[:backend]) end
verified?()
click to toggle source
# File lib/refile/app.rb, line 168 def verified? base_path = request.path.gsub(::File.join(request.script_name, params[:token]), "") Refile.valid_token?(base_path, params[:token]) end