Class: Alchemy::Custom::Model::ElFinder::Connector
- Inherits:
-
Object
- Object
- Alchemy::Custom::Model::ElFinder::Connector
- Defined in:
- lib/alchemy/custom/model/el_finder/connector.rb
Constant Summary collapse
- VERSION =
2.1
- VALID_COMMANDS =
Valid commands to run.
%w[open tree file paste upload search rm ls dim resize duplicate]
- DEFAULT_OPTIONS =
Default options for instances.
{ :mime_handler => ::ElFinder::MimeType, # :image_handler => ElFinder::Image, :original_filename_method => lambda {|file| file.original_filename.respond_to?(:force_encoding) ? file.original_filename.force_encoding('utf-8') : file.original_filename}, :disabled_commands => [], :allow_dot_files => true, :upload_max_size => '50M', # :upload_file_mode => 0644, # :archivers => {}, # :extractors => {}, :home => 'Home', :default_perms => {:read => true, :write => true, :rm => true, :hidden => false}, :perms => [], :thumbs => false, :thumbs_directory => '.thumbs', :thumbs_size => 48, :thumbs_at_once => 5, # :tree_sub_folders => true, # list sub/sub folders in the tree }
Instance Attribute Summary collapse
-
#options ⇒ Hash
writeonly
Options setter.
Instance Method Summary collapse
- #from_hash(hash) ⇒ Object
-
#initialize(options) ⇒ Connector
constructor
Initializes new instance.
-
#run(params) ⇒ Object
Runs request-response cycle.
- #to_hash(pathname) ⇒ Object
Constructor Details
#initialize(options) ⇒ Connector
Initializes new instance.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/alchemy/custom/model/el_finder/connector.rb', line 37 def initialize() @options = DEFAULT_OPTIONS.merge() @options[:disabled_commands] += ['mkdir', 'rename'] raise(ArgumentError, "Missing required :volumes option") unless @options.key?(:volumes) # raise(ArgumentError, "Missing required :url option") unless @options.key?(:url) # raise(ArgumentError, "Missing required :root option") unless @options.key?(:root) raise(ArgumentError, "Mime Handler is invalid") unless mime_handler.respond_to?(:for) # raise(ArgumentError, "Image Handler is invalid") unless image_handler.nil? || ([:size, :resize, :thumbnail].all? {|m| image_handler.respond_to?(m)}) @volumes = [:volumes] @root = PathName.new([:root]) @headers = {} @response = {} end |
Instance Attribute Details
#options=(value) ⇒ Hash (writeonly)
Options setter.
132 133 134 135 136 137 |
# File 'lib/alchemy/custom/model/el_finder/connector.rb', line 132 def (value = {}) value.each_pair do |k, v| @options[k.to_sym] = v end @options end |
Instance Method Details
#from_hash(hash) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/alchemy/custom/model/el_finder/connector.rb', line 103 def from_hash(hash) volume = @volumes.find {|v| v.contains?(hash)} if volume [volume, volume.decode(hash)] else @response[:error] = 'errFileNotFound' nil end # restore missing '=' # len = hash.length % 4 # hash += '==' if len == 1 or len == 2 # hash += '=' if len == 3 # decoded_hash = Base64.urlsafe_decode64(hash) # decoded_hash = decoded_hash.respond_to?(:force_encoding) ? decoded_hash.force_encoding('utf-8') : decoded_hash # pathname = @root + decoded_hash # rescue ArgumentError => e # if e.message != 'invalid base64' # raise # end # nil end |
#run(params) ⇒ Object
Runs request-response cycle.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/alchemy/custom/model/el_finder/connector.rb', line 61 def run(params) @params = params.dup @headers = {} @response = {} @response[:errorData] = {} @file = nil if VALID_COMMANDS.include?(@params[:cmd]) if @options[:thumbs] @thumb_directory = @root + @options[:thumbs_directory] @thumb_directory.mkdir unless @thumb_directory.exist? raise(RuntimeError, "Unable to create thumbs directory") unless @thumb_directory.directory? end @current = @params[:current] ? from_hash(@params[:current]) : nil @volume, @target = (@params[:target] and !@params[:target].empty?) ? from_hash(@params[:target]) : [nil, nil] if params[:targets] @targets = @params[:targets].map {|t| from_hash(t)} end send("_#{@params[:cmd]}") else invalid_request end @response.delete(:errorData) if @response[:errorData].empty? return @headers, @response, @file end |
#to_hash(pathname) ⇒ Object
95 96 97 98 |
# File 'lib/alchemy/custom/model/el_finder/connector.rb', line 95 def to_hash(pathname) # note that '=' are removed Base64.urlsafe_encode64(pathname.path.to_s).chomp.tr("=\n", "") end |