el_finder_s3 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/el_finder_s3.gemspec +3 -2
- data/lib/el_finder_s3.rb +2 -0
- data/lib/el_finder_s3/adapter.rb +39 -119
- data/lib/el_finder_s3/cache_connector.rb +26 -14
- data/lib/el_finder_s3/connector.rb +28 -4
- data/lib/el_finder_s3/dummy_cache_client.rb +16 -0
- data/lib/el_finder_s3/image.rb +14 -5
- data/lib/el_finder_s3/operations.rb +18 -0
- data/lib/el_finder_s3/pathname.rb +25 -13
- data/lib/el_finder_s3/s3_connector.rb +32 -11
- data/lib/el_finder_s3/s3_pathname.rb +4 -0
- data/lib/el_finder_s3/version.rb +1 -1
- metadata +35 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95d6d7d38463b1f822c03d848b501737e2bafe27
|
4
|
+
data.tar.gz: 5c51a060e1600965bfca37ab7f2a3a9db657dbc6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a24ad66767cf9a42e59d91c990ec7adce78d4f943844082e5a29c0ff36f7c87d00d86cb1ac28632c272fb24da20625136fe62bedc7e9f3f990d8cfc5fb592445
|
7
|
+
data.tar.gz: 5f74141f55e33675c210d5c6080c4d04bec99f2a347281ac7ce9b02d7fbfef1c4a5bd8edc2630b6c112df4fce6ee4b00e4121a5757941437f3904c3a9225d569
|
data/el_finder_s3.gemspec
CHANGED
@@ -28,8 +28,9 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.require_paths = ['lib']
|
29
29
|
|
30
30
|
spec.add_dependency('aws-sdk', '~> 2')
|
31
|
-
|
32
|
-
spec.add_dependency('
|
31
|
+
spec.add_dependency('mini_magick', '~> 4.2')
|
32
|
+
spec.add_dependency('memcached', '~> 1.8')
|
33
|
+
spec.add_dependency('cache', '~> 0.4')
|
33
34
|
|
34
35
|
spec.add_development_dependency 'bundler', '~> 1.10'
|
35
36
|
spec.add_development_dependency 'rake', '~> 10.0'
|
data/lib/el_finder_s3.rb
CHANGED
data/lib/el_finder_s3/adapter.rb
CHANGED
@@ -1,17 +1,19 @@
|
|
1
1
|
module ElFinderS3
|
2
|
+
require 'memcached'
|
3
|
+
require 'cache'
|
4
|
+
|
2
5
|
class Adapter
|
3
|
-
attr_reader :
|
6
|
+
attr_reader :server, :s3_connector
|
4
7
|
|
5
|
-
def initialize(server)
|
8
|
+
def initialize(server, cache_connector)
|
6
9
|
@server = {
|
7
10
|
response_cache_expiry_seconds: 3000
|
8
11
|
}
|
9
12
|
@cached_responses = {}
|
10
13
|
@s3_connector = ElFinderS3::S3Connector.new server
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
@connection
|
14
|
+
@cache_connector = cache_connector.nil? ? ElFinderS3::CacheConnector.new : @cache_connector = cache_connector
|
15
|
+
# client = Memcached.new('127.0.0.1:11211', :binary_protocol => true)
|
16
|
+
# @cache = Cache.wrap(client)
|
15
17
|
end
|
16
18
|
|
17
19
|
def close
|
@@ -19,64 +21,58 @@ module ElFinderS3
|
|
19
21
|
end
|
20
22
|
|
21
23
|
def children(pathname, with_directory)
|
22
|
-
cached
|
23
|
-
@s3_connector.ls_la(pathname
|
24
|
+
elements = @cache_connector.cached ElFinderS3::Operations::CHILDREN, pathname do
|
25
|
+
@s3_connector.ls_la(pathname)
|
24
26
|
end
|
27
|
+
|
28
|
+
result = []
|
29
|
+
elements[:folders].each { |folder|
|
30
|
+
result.push(pathname.fullpath + ElFinderS3::S3Pathname.new(@s3_connector, folder, {:type => :directory}))
|
31
|
+
}
|
32
|
+
elements[:files].each { |file|
|
33
|
+
if with_directory
|
34
|
+
result.push(pathname.fullpath + ElFinderS3::S3Pathname.new(@s3_connector, file, {:type => :file}))
|
35
|
+
else
|
36
|
+
result.push(ElFinderS3::S3Pathname.new(@s3_connector, file, {:type => :file}))
|
37
|
+
end
|
38
|
+
}
|
39
|
+
result
|
25
40
|
end
|
26
41
|
|
27
42
|
def touch(pathname, options={})
|
28
|
-
@s3_connector.touch(pathname.to_file_prefix_s)
|
43
|
+
if @s3_connector.touch(pathname.to_file_prefix_s)
|
44
|
+
@cache_connector.clear_cache(pathname, false)
|
45
|
+
true
|
46
|
+
end
|
29
47
|
end
|
30
48
|
|
31
49
|
def exist?(pathname)
|
32
|
-
cached
|
50
|
+
@cache_connector.cached ElFinderS3::Operations::EXIST, pathname do
|
33
51
|
@s3_connector.exist? pathname
|
34
52
|
end
|
35
53
|
end
|
36
54
|
|
37
|
-
# @param [ElFinderS3::Pathname] pathname
|
38
55
|
def path_type(pathname)
|
39
|
-
cached
|
56
|
+
@cache_connector.cached ElFinderS3::Operations::PATH_TYPE, pathname do
|
40
57
|
result = :directory
|
41
|
-
|
42
|
-
|
43
|
-
result = :directory
|
44
|
-
end
|
45
|
-
rescue
|
46
|
-
result = pathname[:type]
|
58
|
+
if pathname.to_s == '/'
|
59
|
+
result = :directory
|
47
60
|
end
|
48
|
-
|
61
|
+
result
|
49
62
|
end
|
50
63
|
end
|
51
64
|
|
52
65
|
def size(pathname)
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
# ElFinderS3::Connector.logger.debug " \e[1;32mFTP:\e[0m Getting size of #{pathname}"
|
57
|
-
# begin
|
58
|
-
# size(pathname.to_s)
|
59
|
-
# rescue Net::FTPPermError => e
|
60
|
-
# nil
|
61
|
-
# rescue Net::FTPReplyError => e
|
62
|
-
# nil
|
63
|
-
# end
|
64
|
-
# end
|
65
|
-
# end
|
66
|
+
@cache_connector.cached :size, pathname do
|
67
|
+
@s3_connector.size(pathname)
|
68
|
+
end
|
66
69
|
end
|
67
70
|
|
68
71
|
#FIXME
|
69
72
|
def mtime(pathname)
|
70
|
-
cached
|
71
|
-
#
|
72
|
-
# ElFinderS3::Connector.logger.debug " \e[1;32mFTP:\e[0m Getting modified time of #{pathname}"
|
73
|
-
# begin
|
74
|
-
# mtime(pathname.to_s)
|
75
|
-
# rescue Net::FTPPermError => e
|
76
|
-
# This command doesn't work on directories
|
73
|
+
@cache_connector.cached ElFinderS3::Operations::MTIME, pathname do
|
74
|
+
#mtime(pathname.to_s)
|
77
75
|
0
|
78
|
-
# end
|
79
|
-
# end
|
80
76
|
end
|
81
77
|
end
|
82
78
|
|
@@ -106,9 +102,7 @@ module ElFinderS3
|
|
106
102
|
|
107
103
|
def mkdir(pathname)
|
108
104
|
if @s3_connector.mkdir(pathname.to_prefix_s)
|
109
|
-
|
110
|
-
# clear_cache(pathname)
|
111
|
-
true
|
105
|
+
@cache_connector.clear_cache(pathname)
|
112
106
|
else
|
113
107
|
false
|
114
108
|
end
|
@@ -137,86 +131,12 @@ module ElFinderS3
|
|
137
131
|
end
|
138
132
|
|
139
133
|
def retrieve(pathname)
|
140
|
-
|
141
|
-
# ftp_context do
|
142
|
-
# ElFinderS3::Connector.logger.debug " \e[1;32mFTP:\e[0m Retrieving #{pathname}"
|
143
|
-
# content = StringIO.new()
|
144
|
-
# begin
|
145
|
-
# retrbinary("RETR #{pathname}", 10240) do |block|
|
146
|
-
# content << block
|
147
|
-
# end
|
148
|
-
# content.string
|
149
|
-
# ensure
|
150
|
-
# content.close
|
151
|
-
# end
|
152
|
-
# end
|
134
|
+
@s3_connector.get(pathname.to_file_prefix_s)
|
153
135
|
end
|
154
136
|
|
155
137
|
def store(pathname, content)
|
156
138
|
@s3_connector.store(pathname.to_file_prefix_s, content)
|
157
139
|
#TODO clear_cache(pathname)
|
158
140
|
end
|
159
|
-
|
160
|
-
private
|
161
|
-
|
162
|
-
##
|
163
|
-
# Remove all entries for the given pathname (and its parent folder)
|
164
|
-
# from the FTP cache
|
165
|
-
def clear_cache(pathname)
|
166
|
-
@cached_responses.delete(pathname.to_s)
|
167
|
-
|
168
|
-
if pathname.to_s != '/' && pathname.to_s != '.'
|
169
|
-
# Clear parent of this entry, too
|
170
|
-
@cached_responses.delete(pathname.dirname.to_s)
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
##
|
175
|
-
# Looks in the cache for an entry for the given pathname and operation,
|
176
|
-
# returning the cached result if one is found. If one is not found, the given
|
177
|
-
# block is invoked and its result is stored in the cache and returned
|
178
|
-
#
|
179
|
-
# The FTP cache is used to prevent redundant FTP queries for information such as a
|
180
|
-
# file's size, or a directory's contents, during a *single* FTP session.
|
181
|
-
def cached(operation, pathname)
|
182
|
-
response = cache_get(operation, pathname)
|
183
|
-
unless response.nil?
|
184
|
-
return response
|
185
|
-
end
|
186
|
-
|
187
|
-
response = yield
|
188
|
-
cache_put operation, pathname, response
|
189
|
-
|
190
|
-
response
|
191
|
-
end
|
192
|
-
|
193
|
-
##
|
194
|
-
# Store an FTP response in the cache
|
195
|
-
def cache_put(operation, pathname, response)
|
196
|
-
@cached_responses[pathname.to_s] = {} unless @cached_responses.include?(pathname.to_s)
|
197
|
-
|
198
|
-
@cached_responses[pathname.to_s][operation] = {
|
199
|
-
timestamp: Time.now,
|
200
|
-
response: response
|
201
|
-
}
|
202
|
-
end
|
203
|
-
|
204
|
-
##
|
205
|
-
# Fetch an FTP response from the cache
|
206
|
-
def cache_get(operation, pathname)
|
207
|
-
if @cached_responses.include?(pathname.to_s) && @cached_responses[pathname.to_s].include?(operation)
|
208
|
-
response = @cached_responses[pathname.to_s][operation]
|
209
|
-
|
210
|
-
#FIXME cache timeout
|
211
|
-
# max_staleness = Time.now - @server[:response_cache_expiry_seconds]
|
212
|
-
|
213
|
-
# if response[:timestamp] < max_staleness
|
214
|
-
# @cached_responses[pathname.to_s].delete(operation)
|
215
|
-
# nil
|
216
|
-
# else
|
217
|
-
response[:response]
|
218
|
-
# end
|
219
|
-
end
|
220
|
-
end
|
221
141
|
end
|
222
142
|
end
|
@@ -1,27 +1,39 @@
|
|
1
1
|
module ElFinderS3
|
2
|
+
require 'cache'
|
2
3
|
class CacheConnector
|
3
4
|
|
4
|
-
def
|
5
|
-
|
5
|
+
def initialize(client = nil)
|
6
|
+
@cache = client.nil? ? ElFinderS3::DummyCacheClient.new : Cache.wrap(client)
|
6
7
|
end
|
7
8
|
|
8
|
-
def
|
9
|
-
|
9
|
+
def cache_hash(operation, pathname)
|
10
|
+
Base64.urlsafe_encode64("#{operation}::#{pathname}").chomp.tr("=\n", "")
|
10
11
|
end
|
11
12
|
|
12
|
-
def
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
13
|
+
def cached(operation, pathname)
|
14
|
+
cache_hash_key = cache_hash(operation, pathname)
|
15
|
+
if @cache.exist? cache_hash_key
|
16
|
+
return @cache.get(cache_hash_key)
|
17
|
+
else
|
18
|
+
response = yield
|
19
19
|
|
20
|
+
@cache.set(cache_hash_key, response, 2.years)
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
raise 'This is not implemented!'
|
22
|
+
response
|
23
|
+
end
|
24
24
|
end
|
25
25
|
|
26
|
+
def clear_cache(pathname, recursive = true)
|
27
|
+
ElFinderS3::Operations.each do |operation|
|
28
|
+
@cache.delete cache_hash(operation, pathname)
|
29
|
+
end
|
30
|
+
|
31
|
+
if recursive || pathname.file?
|
32
|
+
pathname_str = pathname.to_s
|
33
|
+
if pathname_str != '/' && pathname_str != '.'
|
34
|
+
clear_cache(pathname.dirname, recursive)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
26
38
|
end
|
27
39
|
end
|
@@ -77,7 +77,7 @@ module ElFinderS3
|
|
77
77
|
# @see VALID_COMMANDS
|
78
78
|
def run(params)
|
79
79
|
|
80
|
-
@adapter = ElFinderS3::Adapter.new(@options[:server])
|
80
|
+
@adapter = ElFinderS3::Adapter.new(@options[:server], @options[:cache_connector])
|
81
81
|
# @adapter = ElFinderS3::FtpAdapter.new(@options[:server])
|
82
82
|
@root = ElFinderS3::Pathname.new(adapter)
|
83
83
|
|
@@ -103,7 +103,9 @@ module ElFinderS3
|
|
103
103
|
|
104
104
|
begin
|
105
105
|
send("_#{@params[:cmd]}")
|
106
|
-
rescue
|
106
|
+
rescue Exception => exception
|
107
|
+
puts exception.message
|
108
|
+
puts exception.backtrace.inspect
|
107
109
|
@response[:error] = 'Access Denied'
|
108
110
|
end
|
109
111
|
else
|
@@ -272,6 +274,7 @@ module ElFinderS3
|
|
272
274
|
end
|
273
275
|
|
274
276
|
file = @target + @params[:name]
|
277
|
+
file.type = :file
|
275
278
|
if !file.exist? && file.touch
|
276
279
|
@response[:select] = [to_hash(file)]
|
277
280
|
_open(@target)
|
@@ -465,7 +468,26 @@ module ElFinderS3
|
|
465
468
|
|
466
469
|
#
|
467
470
|
def _tmb
|
468
|
-
|
471
|
+
if image_handler.nil?
|
472
|
+
command_not_implemented
|
473
|
+
else
|
474
|
+
@response[:current] = to_hash(@current)
|
475
|
+
@response[:images] = {}
|
476
|
+
idx = 0
|
477
|
+
@current.children.select { |e| mime_handler.for(e) =~ /image/ }.each do |img|
|
478
|
+
if (idx >= @options[:thumbs_at_once])
|
479
|
+
@response[:tmb] = true
|
480
|
+
break
|
481
|
+
end
|
482
|
+
thumbnail = thumbnail_for(img)
|
483
|
+
unless thumbnail.exist? && thumbnail.file?
|
484
|
+
imgSourcePath = @options[:url] + '/' + img.path.to_s
|
485
|
+
image_handler.thumbnail(imgSourcePath, thumbnail, :width => @options[:thumbs_size].to_i, :height => @options[:thumbs_size].to_i)
|
486
|
+
@response[:images][to_hash(img)] = @options[:url] + '/' + thumbnail.path.to_s
|
487
|
+
idx += 1
|
488
|
+
end
|
489
|
+
end
|
490
|
+
end
|
469
491
|
end
|
470
492
|
|
471
493
|
# of tmb
|
@@ -500,7 +522,9 @@ module ElFinderS3
|
|
500
522
|
|
501
523
|
#
|
502
524
|
def thumbnail_for(pathname)
|
503
|
-
@thumb_directory + "#{to_hash(pathname)}.png"
|
525
|
+
result = @thumb_directory + "#{to_hash(pathname)}.png"
|
526
|
+
result.type = :file
|
527
|
+
result
|
504
528
|
end
|
505
529
|
|
506
530
|
#
|
data/lib/el_finder_s3/image.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'shellwords'
|
3
3
|
require 'image_size'
|
4
|
+
require 'mini_magick'
|
4
5
|
|
5
6
|
module ElFinderS3
|
6
7
|
|
@@ -17,12 +18,20 @@ module ElFinderS3
|
|
17
18
|
|
18
19
|
def self.resize(pathname, options = {})
|
19
20
|
return nil unless File.exist?(pathname)
|
20
|
-
system(
|
21
|
-
end
|
21
|
+
system(::Shellwords.join(['mogrify', '-resize', "#{options[:width]}x#{options[:height]}!", pathname.to_s]))
|
22
|
+
end
|
23
|
+
|
24
|
+
# of self.resize
|
22
25
|
|
23
|
-
def self.thumbnail(
|
24
|
-
|
25
|
-
|
26
|
+
def self.thumbnail(imgSourcePath, dst, options = {})
|
27
|
+
image = MiniMagick::Image.open(imgSourcePath)
|
28
|
+
image.combine_options do |c|
|
29
|
+
c.thumbnail "#{options[:width]}x#{options[:height]}"
|
30
|
+
c.background 'white'
|
31
|
+
c.gravity 'center'
|
32
|
+
c.extent "#{options[:width]}x#{options[:height]}"
|
33
|
+
end
|
34
|
+
dst.write(image)
|
26
35
|
end # of self.resize
|
27
36
|
|
28
37
|
end # of class Image
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module ElFinderS3
|
2
|
+
class Operations
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
PATH_TYPE = :path_type
|
6
|
+
EXIST = :exist
|
7
|
+
CHILDREN = :children
|
8
|
+
MTIME = :mtime
|
9
|
+
|
10
|
+
def self.each
|
11
|
+
yield PATH_TYPE
|
12
|
+
yield EXIST
|
13
|
+
yield CHILDREN
|
14
|
+
yield MTIME
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -34,8 +34,9 @@ module ElFinderS3
|
|
34
34
|
|
35
35
|
# of initialize
|
36
36
|
|
37
|
-
def type(
|
38
|
-
@type =
|
37
|
+
def type=(value)
|
38
|
+
@type = value
|
39
|
+
fullpath.type = value
|
39
40
|
end
|
40
41
|
|
41
42
|
#
|
@@ -65,6 +66,25 @@ module ElFinderS3
|
|
65
66
|
@path.relative?
|
66
67
|
end
|
67
68
|
|
69
|
+
def exist?
|
70
|
+
realpath.exist?
|
71
|
+
rescue Errno::ENOENT
|
72
|
+
false
|
73
|
+
end
|
74
|
+
|
75
|
+
def directory?
|
76
|
+
realpath.directory?
|
77
|
+
rescue Errno::ENOENT
|
78
|
+
false
|
79
|
+
end
|
80
|
+
|
81
|
+
def file?
|
82
|
+
realpath.file?
|
83
|
+
rescue Errno::ENOENT
|
84
|
+
false
|
85
|
+
end
|
86
|
+
|
87
|
+
|
68
88
|
# of relative?
|
69
89
|
|
70
90
|
#
|
@@ -111,13 +131,6 @@ module ElFinderS3
|
|
111
131
|
|
112
132
|
# of basename
|
113
133
|
|
114
|
-
#
|
115
|
-
def basename(*args)
|
116
|
-
@path.basename(*args)
|
117
|
-
end
|
118
|
-
|
119
|
-
# of basename
|
120
|
-
|
121
134
|
#
|
122
135
|
def dirname
|
123
136
|
self.class.new(@adapter, @path.dirname)
|
@@ -172,7 +185,9 @@ module ElFinderS3
|
|
172
185
|
|
173
186
|
#
|
174
187
|
def touch(options = {})
|
175
|
-
|
188
|
+
file2Touch = cleanpath
|
189
|
+
self.file? ? file2Touch.type = :file : file2Touch.type = :directory
|
190
|
+
adapter.touch(file2Touch, options)
|
176
191
|
end
|
177
192
|
|
178
193
|
#
|
@@ -220,9 +235,6 @@ module ElFinderS3
|
|
220
235
|
# of rename
|
221
236
|
|
222
237
|
{
|
223
|
-
'directory?' => {:path => 'realpath', :rescue => true},
|
224
|
-
'exist?' => {:path => 'realpath', :rescue => true},
|
225
|
-
'file?' => {:path => 'realpath', :rescue => true},
|
226
238
|
'ftype' => {:path => 'realpath', },
|
227
239
|
'mkdir' => {:path => 'fullpath', :args => '(*args)'},
|
228
240
|
'mtime' => {:path => 'realpath', },
|
@@ -16,8 +16,7 @@ module ElFinderS3
|
|
16
16
|
@s3_client = Aws::S3::Client.new
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
|
-
def ls_la(pathname, with_directory)
|
19
|
+
def ls_la(pathname)
|
21
20
|
prefix = pathname.to_prefix_s
|
22
21
|
query = {
|
23
22
|
bucket: @bucket_name,
|
@@ -28,23 +27,23 @@ module ElFinderS3
|
|
28
27
|
}
|
29
28
|
|
30
29
|
response = @s3_client.list_objects(query)
|
31
|
-
result =
|
30
|
+
result = {
|
31
|
+
:folders => [],
|
32
|
+
:files => []
|
33
|
+
}
|
34
|
+
|
32
35
|
#Files
|
33
36
|
response.contents.each { |e|
|
34
37
|
if e.key != prefix
|
35
38
|
e.key = e.key.gsub(prefix, '')
|
36
|
-
|
37
|
-
result.push(pathname.fullpath + ::ElFinderS3::S3Pathname.new(self, e))
|
38
|
-
else
|
39
|
-
result.push(::ElFinderS3::S3Pathname.new(self, e))
|
40
|
-
end
|
39
|
+
result[:files].push(e[:key])
|
41
40
|
end
|
42
41
|
}
|
43
42
|
#Folders
|
44
43
|
response.common_prefixes.each { |f|
|
45
44
|
if f.prefix != '' && f.prefix != prefix && f.prefix != '/'
|
46
45
|
f.prefix = f.prefix.split('/').last
|
47
|
-
result.push(
|
46
|
+
result[:folders].push(f[:prefix])
|
48
47
|
end
|
49
48
|
}
|
50
49
|
return result
|
@@ -54,7 +53,7 @@ module ElFinderS3
|
|
54
53
|
def exist?(pathname)
|
55
54
|
query = {
|
56
55
|
bucket: @bucket_name,
|
57
|
-
key: pathname.to_prefix_s
|
56
|
+
key: pathname.file? ? pathname.to_file_prefix_s : pathname.to_prefix_s
|
58
57
|
}
|
59
58
|
begin
|
60
59
|
@s3_client.head_object(query)
|
@@ -83,7 +82,29 @@ module ElFinderS3
|
|
83
82
|
end
|
84
83
|
|
85
84
|
def store(filename, content)
|
86
|
-
|
85
|
+
if content.is_a?(MiniMagick::Image)
|
86
|
+
@s3_client.put_object(bucket: @bucket_name, key: filename, body: content.to_blob, acl: 'public-read')
|
87
|
+
elsif @s3_client.put_object(bucket: @bucket_name, key: filename, body: content, acl: 'public-read')
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def get(filename)
|
92
|
+
response = @s3_client.get_object(bucket: @bucket_name, key: filename)
|
93
|
+
return nil unless !response.nil?
|
94
|
+
response.body
|
95
|
+
end
|
96
|
+
|
97
|
+
def size(pathname)
|
98
|
+
query = {
|
99
|
+
bucket: @bucket_name,
|
100
|
+
key: pathname.file? ? pathname.to_file_prefix_s : pathname.to_prefix_s
|
101
|
+
}
|
102
|
+
begin
|
103
|
+
head = @s3_client.head_object(query)
|
104
|
+
head[:content_length]
|
105
|
+
rescue Aws::S3::Errors::NotFound
|
106
|
+
0
|
107
|
+
end
|
87
108
|
end
|
88
109
|
end
|
89
110
|
end
|
data/lib/el_finder_s3/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: el_finder_s3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Raúl Anatol
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -25,19 +25,47 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: mini_magick
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '4.2'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '4.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: memcached
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.8'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.8'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: cache
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.4'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.4'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: bundler
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -90,8 +118,10 @@ files:
|
|
90
118
|
- lib/el_finder_s3/base64.rb
|
91
119
|
- lib/el_finder_s3/cache_connector.rb
|
92
120
|
- lib/el_finder_s3/connector.rb
|
121
|
+
- lib/el_finder_s3/dummy_cache_client.rb
|
93
122
|
- lib/el_finder_s3/image.rb
|
94
123
|
- lib/el_finder_s3/mime_type.rb
|
124
|
+
- lib/el_finder_s3/operations.rb
|
95
125
|
- lib/el_finder_s3/pathname.rb
|
96
126
|
- lib/el_finder_s3/railties.rb
|
97
127
|
- lib/el_finder_s3/s3_connector.rb
|