Sha256: 6c4cc013cb5ecdd9d23b56d2f5717f67306afb6725933c096f86b29de02b3efc
Contents?: true
Size: 1.42 KB
Versions: 5
Compression:
Stored size: 1.42 KB
Contents
class DownloadController < ApplicationController include Blacklight::SolrHelper def show @response, @document = get_solr_response_for_doc_id restricted_should_authenticate response = check_type validate response respond_to do |format| format.json { render json: flash, response: response } format.html { render json: flash, response: response } end end def file # Grab the solr document to check if it should be public or not @response, @document = get_solr_response_for_doc_id(file_name_to_id(params[:id])) restricted_should_authenticate send_file "tmp/cache/downloads/#{params[:id]}.#{params[:format]}", type: 'application/zip', x_sendfile: true end private def check_type case params[:type] when 'shapefile' response = ShapefileDownload.new(@document).get when 'kmz' response = KmzDownload.new(@document).get end response end def validate(response) if response.nil? flash[:danger] = t 'geoblacklight.download.error' else flash[:success] = view_context.link_to(t('geoblacklight.download.success', title: response), download_file_path(response)) end end # Checks whether a document is public, if not require user to authenticate def restricted_should_authenticate unless @document.public? authenticate_user! end end def file_name_to_id(file_name) file_name.split('-')[0..-2].join('-') end end
Version data entries
5 entries across 5 versions & 1 rubygems