Class: ElVfsClient::ElFinderController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/el_vfs_client/el_finder_controller.rb

Instance Method Summary collapse

Instance Method Details

#runObject



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
44
45
46
# File 'app/controllers/el_vfs_client/el_finder_controller.rb', line 13

def run
  params = permitted_params if Rails.version.to_f >= 5.1

  params.delete(:format)
  params.delete(:controller)
  params.delete(:action)

  c = Curl::Easy.new(url) do |curl|
    curl.headers['User-Agent'] = request.user_agent
    curl.headers['Accept'] = 'application/json'
    curl.headers['CLIENT_IP'] = request.env['HTTP_CLIENT_IP']
    curl.headers['X_FORWARDED_FOR'] = request.env['HTTP_X_FORWARDED_FOR']
    curl.headers['REMOTE_ADDR'] = request.env['REMOTE_ADDR']
    curl.multipart_form_post = true
  end

  if params['cmd'] == 'upload'
    upload = params.delete(:upload)
    parameters = params.map{ |key, value| Curl::PostField.content(key, value)}
    files = upload.map{ |file| Curl::PostField.file('upload[]', file.path, file.original_filename) }
    c.http_post(*parameters, *files)
  elsif params['cmd'] == 'put'
    parameters = params.map{ |key, value| Curl::PostField.content(key, value)}
    c.http_post(*parameters)
  else
    c.url << "?#{params.to_query}"
    c.http_get
  end

  respond_to do |format|
    format.html { render :json => c.body_str }
    format.json { render :json => c.body_str }
  end
end

#showObject



8
9
10
11
# File 'app/controllers/el_vfs_client/el_finder_controller.rb', line 8

def show
  @root_path = root_path
  render :file => 'el_finder/layout', :layout => false
end