activestorage-sftp 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +2 -0
- data/lib/active_storage/service/sftp_service.rb +10 -12
- data/lib/active_storage/sftp.rb +2 -1
- data/lib/active_storage/sftp/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53fb9c020a024d48787fccfbdd311b88f1eef5b6
|
4
|
+
data.tar.gz: 396a0b2ffc2cde6bb0f88bf169cdbf2932110855
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 930f62d8856cfda94bfa90285ab6c59fc5d3d4ccdd14ce851a2dece838e5f78114438c87195d2c467738aa01031be7eea591e1f7244f40222507aaa52f30ffbe
|
7
|
+
data.tar.gz: 5a7f980c04c712750beec2f4a328bc676d0be570cc9c52854c46c2e053d0f99fe69f6a47b955fb3157eb554d5efff98579d9bf0b1cb14099ce8718d2b57689b1
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -9,13 +9,14 @@ module ActiveStorage
|
|
9
9
|
|
10
10
|
MAX_CHUNK_SIZE = 64.kilobytes.freeze
|
11
11
|
|
12
|
-
attr_reader :host, :user, :root, :public_host
|
12
|
+
attr_reader :host, :user, :root, :public_host, :public_root
|
13
13
|
|
14
|
-
def initialize(host:, user:, public_host: nil, root: './')
|
14
|
+
def initialize(host:, user:, public_host: nil, root: './', public_root: nil)
|
15
15
|
@host = host
|
16
16
|
@user = user
|
17
17
|
@root = root
|
18
18
|
@public_host = public_host
|
19
|
+
@public_root = public_root
|
19
20
|
end
|
20
21
|
|
21
22
|
def upload(key, io, checksum: nil, **)
|
@@ -30,8 +31,7 @@ module ActiveStorage
|
|
30
31
|
|
31
32
|
def download(key, chunk_size: MAX_CHUNK_SIZE, &block)
|
32
33
|
if chunk_size > MAX_CHUNK_SIZE
|
33
|
-
|
34
|
-
raise "Maximum chunk size: #{MAX_CHUNK_SIZE}"
|
34
|
+
raise ChunkSizeError, "Maximum chunk size: #{MAX_CHUNK_SIZE}"
|
35
35
|
end
|
36
36
|
if block_given?
|
37
37
|
instrument :streaming_download, key: key do
|
@@ -45,8 +45,7 @@ module ActiveStorage
|
|
45
45
|
if response.eof?
|
46
46
|
eof = true
|
47
47
|
elsif !response.ok?
|
48
|
-
|
49
|
-
raise "SFTP Response Error"
|
48
|
+
raise SFTPResponseError, response.code
|
50
49
|
else
|
51
50
|
chunk = response[:data]
|
52
51
|
block.call(chunk)
|
@@ -76,8 +75,7 @@ module ActiveStorage
|
|
76
75
|
def download_chunk(key, range)
|
77
76
|
instrument :download_chunk, key: key, range: range do
|
78
77
|
if range.size > MAX_CHUNK_SIZE
|
79
|
-
|
80
|
-
raise "Maximun chunk size: #{MAX_CHUNK_SIZE}"
|
78
|
+
raise ChunkSizeError, "Maximum chunk size: #{MAX_CHUNK_SIZE}"
|
81
79
|
end
|
82
80
|
chunk = StringIo.new
|
83
81
|
through_sftp do |sftp|
|
@@ -179,6 +177,10 @@ module ActiveStorage
|
|
179
177
|
{ "Content-Type" => content_type }
|
180
178
|
end
|
181
179
|
|
180
|
+
def path_for(key)
|
181
|
+
File.join folder_for(key), key
|
182
|
+
end
|
183
|
+
|
182
184
|
protected
|
183
185
|
def through_sftp(&block)
|
184
186
|
Net::SFTP.start(@host, @user) do |sftp|
|
@@ -186,10 +188,6 @@ module ActiveStorage
|
|
186
188
|
end
|
187
189
|
end
|
188
190
|
|
189
|
-
def path_for(key)
|
190
|
-
File.join folder_for(key), key
|
191
|
-
end
|
192
|
-
|
193
191
|
def folder_for(key)
|
194
192
|
File.join root, relative_folder_for(key)
|
195
193
|
end
|
data/lib/active_storage/sftp.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activestorage-sftp
|
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
|
- treenewbee
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-08-
|
11
|
+
date: 2019-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|