Sha256: 3484e58d90934d674ef1e0f72d69674ec8682e8b3b28b65b1e65c9c65fb0431f

Contents?: true

Size: 1.79 KB

Versions: 2

Compression:

Stored size: 1.79 KB

Contents

require 'curb'
require 'configliere'
require 'uuid'

module ElVfsClient
  class ElFinderController < ApplicationController
    respond_to :json, :html

    def show
      session[:root_path] = session[:root_path]  || (params[:root_path] ? params[:root_path] : generate_folder_uuid)

      render :file => 'el_finder/layout', :layout => false
    end

    def run
      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)
      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

    private
      def url
        url = "#{Settings[:el_vfs][:protocol]}://#{Settings[:el_vfs][:host]}:#{Settings[:el_vfs][:port]}/api/el_finder/v2"
        url << "/#{Settings[:el_vfs][:root_path]}/#{session[:root_path]}" if session[:root_path]
      end

      def generate_folder_uuid
        "#{Time.now.year}_#{Time.now.month}_#{Time.now.day}_#{Time.now.hour}_#{Time.now.min}_#{UUID.generate.split('-').first}"
      end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
el_vfs_client-0.0.5.1 app/controllers/el_vfs_client/el_finder_controller.rb
el_vfs_client-0.0.5 app/controllers/el_vfs_client/el_finder_controller.rb