Class: PdfController

Inherits:
ApplicationController show all
Defined in:
public/app/controllers/pdf_controller.rb

Constant Summary collapse

PDF_MUTEX =
java.util.concurrent.Semaphore.new(AppConfig[:pui_max_concurrent_pdfs])

Constants included from Searchable

Searchable::ABSTRACT

Instance Method Summary collapse

Methods inherited from ApplicationController

#archivesspace, can_access?, permission_mappings, set_access_control

Methods included from JsonHelper

#merge_notes, #process_json_notes

Methods included from Searchable

#default_search_opts, #get_filter_years, #handle_results, #html_notes, #process_results, #process_search_results, #repo_context, #search_terms, #set_up_advanced_search, #set_up_and_run_search, #set_up_search, #strip_facet_fields

Methods included from HandleFaceting

#fetch_only_facets, #get_pretty_facet_value, #strip_facets

Methods included from ManipulateNode

#inheritance, #process_mixed_content, #strip_mixed_content

Instance Method Details

#resourceObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'public/app/controllers/pdf_controller.rb', line 7

def resource
  PDF_MUTEX.acquire
  begin
    repo_id = params.fetch(:rid, nil)
    resource_id = params.fetch(:id, nil)
    token = params.fetch(:token, nil)

    pdf = FindingAidPDF.new(repo_id, resource_id, archivesspace, "#{request.protocol}#{request.host_with_port}")
    pdf_file = pdf.generate

    if token
      token.gsub!(/[^a-f0-9]/, '')
    end

    respond_to do |format|
      filename = pdf.suggested_filename

      format.all do
        fh = File.open(pdf_file.path, "r")
        self.headers["Content-type"] = "application/pdf"
        self.headers["Content-disposition"] = "attachment; filename=\"#{filename}\""
        self.response_body = Enumerator.new do |y|
          begin
            while chunk = fh.read(4096)
              y << chunk
            end
          ensure
            fh.close
            pdf_file.unlink
          end
        end
      end
    end
  ensure
    PDF_MUTEX.release
  end
end