el_finder 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/el_finder/connector.rb +29 -7
- data/lib/el_finder/version.rb +1 -1
- data/test/test_el_finder.rb +13 -0
- data/test/test_el_finder_options.rb +43 -0
- metadata +4 -2
data/lib/el_finder/connector.rb
CHANGED
@@ -18,7 +18,7 @@ module ElFinder
|
|
18
18
|
DEFAULT_OPTIONS = {
|
19
19
|
:mime_handler => ElFinder::MimeType,
|
20
20
|
:image_handler => ElFinder::Image,
|
21
|
-
:original_filename_method => lambda { |file| file.original_filename },
|
21
|
+
:original_filename_method => lambda { |file| file.original_filename.force_encoding('utf-8') },
|
22
22
|
:disabled_commands => [],
|
23
23
|
:allow_dot_files => true,
|
24
24
|
:upload_max_size => '50M',
|
@@ -236,15 +236,19 @@ module ElFinder
|
|
236
236
|
@response[:error] = 'Access Denied'
|
237
237
|
return
|
238
238
|
end
|
239
|
-
|
240
239
|
select = []
|
241
240
|
@params[:upload].to_a.each do |file|
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
241
|
+
if upload_max_size_in_bytes > 0 && file.size > upload_max_size_in_bytes
|
242
|
+
@response[:error] ||= "Some files were not uploaded"
|
243
|
+
@response[:errorData][@options[:original_filename_method].call(file)] = 'File exceeds the maximum allowed filesize'
|
244
|
+
else
|
245
|
+
dst = @current + @options[:original_filename_method].call(file)
|
246
|
+
FileUtils.mv(file.path, dst.fullpath)
|
247
|
+
FileUtils.chmod @options[:upload_file_mode], dst
|
248
|
+
select << to_hash(dst)
|
249
|
+
end
|
246
250
|
end
|
247
|
-
@response[:select] = select
|
251
|
+
@response[:select] = select unless select.empty?
|
248
252
|
_open(@current)
|
249
253
|
end # of upload
|
250
254
|
|
@@ -421,6 +425,24 @@ module ElFinder
|
|
421
425
|
################################################################################
|
422
426
|
private
|
423
427
|
|
428
|
+
#
|
429
|
+
def upload_max_size_in_bytes
|
430
|
+
bytes = @options[:upload_max_size]
|
431
|
+
if bytes.is_a?(String) && bytes.strip =~ /(\d+)([KMG]?)/
|
432
|
+
bytes = $1.to_i
|
433
|
+
unit = $2
|
434
|
+
case unit
|
435
|
+
when 'K'
|
436
|
+
bytes *= 1024
|
437
|
+
when 'M'
|
438
|
+
bytes *= 1024 * 1024
|
439
|
+
when 'G'
|
440
|
+
bytes *= 1024 * 1024 * 1024
|
441
|
+
end
|
442
|
+
end
|
443
|
+
bytes.to_i
|
444
|
+
end
|
445
|
+
|
424
446
|
#
|
425
447
|
def thumbnail_for(pathname)
|
426
448
|
@thumb_directory + "#{to_hash(pathname)}.png"
|
data/lib/el_finder/version.rb
CHANGED
data/test/test_el_finder.rb
CHANGED
@@ -141,6 +141,19 @@ class TestElFinder < Test::Unit::TestCase
|
|
141
141
|
assert_not_nil r[:select]
|
142
142
|
end
|
143
143
|
|
144
|
+
def test_upload_too_big
|
145
|
+
@elfinder.options = {:upload_max_size => 5}
|
146
|
+
h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
|
147
|
+
uploads = []
|
148
|
+
uploads << File.open(File.join(@vroot, 'foo/philip.txt'))
|
149
|
+
uploads << File.open(File.join(@vroot, 'foo/sam.txt'))
|
150
|
+
h, r = @elfinder.run(:cmd => 'upload', :upload => uploads, :current => r[:cwd][:hash])
|
151
|
+
assert !File.exist?(File.join(@vroot, 'philip.txt'))
|
152
|
+
assert File.exist?(File.join(@vroot, 'sam.txt'))
|
153
|
+
assert_not_nil r[:select]
|
154
|
+
assert_match(/some files were not uploaded/i, r[:error])
|
155
|
+
end
|
156
|
+
|
144
157
|
def test_ping
|
145
158
|
h, r = @elfinder.run(:cmd => 'ping')
|
146
159
|
assert r.empty?
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'el_finder_test_case'
|
3
|
+
|
4
|
+
class TestElFinder < Test::Unit::TestCase
|
5
|
+
|
6
|
+
include ElFinderTestCase
|
7
|
+
|
8
|
+
################################################################################
|
9
|
+
|
10
|
+
def test_to_hash_method
|
11
|
+
@elfinder.options = {} # default is '50M'
|
12
|
+
assert_equal (50 * 1024 * 1024), @elfinder.send(:upload_max_size_in_bytes)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_from_hash_method
|
16
|
+
@elfinder.options = {
|
17
|
+
:upload_max_size => 1
|
18
|
+
}
|
19
|
+
assert_equal 1, @elfinder.send(:upload_max_size_in_bytes)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_from_hash_method
|
23
|
+
@elfinder.options = {
|
24
|
+
:upload_max_size => '1'
|
25
|
+
}
|
26
|
+
assert_equal 1, @elfinder.send(:upload_max_size_in_bytes)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_from_hash_method
|
30
|
+
@elfinder.options = {
|
31
|
+
:upload_max_size => '1K'
|
32
|
+
}
|
33
|
+
assert_equal 1024, @elfinder.send(:upload_max_size_in_bytes)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_from_hash_method
|
37
|
+
@elfinder.options = {
|
38
|
+
:upload_max_size => '1G'
|
39
|
+
}
|
40
|
+
assert_equal 1073741824, @elfinder.send(:upload_max_size_in_bytes)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: el_finder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: image_size
|
@@ -100,6 +100,7 @@ files:
|
|
100
100
|
- test/test_el_finder_archivers.rb
|
101
101
|
- test/test_el_finder_extractors.rb
|
102
102
|
- test/test_el_finder_hash.rb
|
103
|
+
- test/test_el_finder_options.rb
|
103
104
|
- test/test_el_finder_permissions.rb
|
104
105
|
- test/test_el_finder_symlink.rb
|
105
106
|
- test/test_el_finder_thumbs.rb
|
@@ -146,6 +147,7 @@ test_files:
|
|
146
147
|
- test/test_el_finder_archivers.rb
|
147
148
|
- test/test_el_finder_extractors.rb
|
148
149
|
- test/test_el_finder_hash.rb
|
150
|
+
- test/test_el_finder_options.rb
|
149
151
|
- test/test_el_finder_permissions.rb
|
150
152
|
- test/test_el_finder_symlink.rb
|
151
153
|
- test/test_el_finder_thumbs.rb
|