Class: PdfjsViewer::AssetsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/pdfjs_viewer/assets_controller.rb

Overview

PdfjsViewer Assets Controller

Instance Method Summary collapse

Instance Method Details

#content_type(file_path) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'app/controllers/pdfjs_viewer/assets_controller.rb', line 18

def content_type(file_path)
  case File.extname(file_path)
  when '.js', '.mjs' then 'application/javascript'
  when '.css' then 'text/css'
  when '.wasm' then 'application/wasm'
  when '.map' then 'application/json'
  else 'application/octet-stream'
  end
end

#show ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'app/controllers/pdfjs_viewer/assets_controller.rb', line 7

def show
  file_path = params[:path]
  full_path = File.join(PdfjsViewer::Engine.root, 'public', file_path)

  if File.exist?(full_path)
    send_file full_path, type: content_type(file_path), disposition: 'inline'
  else
    head :not_found
  end
end