active-storage-ftp 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 39c28e1d6c737b6a82bada6c98144ce559eaf384f88b41a1a8e48fce12d831dd
4
- data.tar.gz: 3d375e09b426060428eddb07968b00d8503774dbfaf3fb083e1ba9aa36b9c673
3
+ metadata.gz: 17d6911595715168ddebd3539f62b8e201d09d9acf98d9d6d30c19aff431149d
4
+ data.tar.gz: 4415e8df88899c04e4a78c45cb1117c7a6577c089c9cf4c81ed7731e70eadef1
5
5
  SHA512:
6
- metadata.gz: eaecbd2f4c21dbdecfa2bfc22e0cab18e6da65bad1150f00f6df090bb01a3ea3036b02e823ff64f3b02b13fa4b310494fe7ceb21fb50c504a0d8684f3eac704f
7
- data.tar.gz: ece1cd11ba4746a15cfc98ddc9f7b10f6cbb71728a1357badc05e9b77437dd56b1fcfc307b86a26ecbcfbf60749403c23f2beb3973f1d154a9392d2cb4d645a2
6
+ metadata.gz: e4ad459cc21fb0fa91a7a65142754565559d876e481fe65572f3e9893db659425a91256093fe18739d9332d8d552143483a699c53cda2c3cc6bfc7098bc543fa
7
+ data.tar.gz: a69367e3bada7f7c61eab4a9e3b018793b50aac3dde0477b8cf675346fb50adbbc82a5109e87aaa25440775c3ce6908d051314313512e02ca4cebf86e6c69f1d
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.3.5
7
+ before_install: gem install bundler -v 2.0.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in activestorage-ftp.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ active-storage-ftp (0.1.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ rake (10.5.0)
11
+ rspec (3.8.0)
12
+ rspec-core (~> 3.8.0)
13
+ rspec-expectations (~> 3.8.0)
14
+ rspec-mocks (~> 3.8.0)
15
+ rspec-core (3.8.0)
16
+ rspec-support (~> 3.8.0)
17
+ rspec-expectations (3.8.3)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.8.0)
20
+ rspec-mocks (3.8.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.8.0)
23
+ rspec-support (3.8.0)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ active-storage-ftp!
30
+ bundler (~> 2.0)
31
+ rake (~> 10.0)
32
+ rspec (~> 3.0)
33
+
34
+ BUNDLED WITH
35
+ 2.0.1
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # Activestorage::Ftp
2
+
3
+ Active Storage FTP Service, This project only support FTP service not SSH
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'actives-storage-ftp'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install active-storage-ftp
20
+
21
+ ## Usage
22
+
23
+ ```yml
24
+ production:
25
+ service: FTP
26
+ host: <%= ENV["FTP_HOST"] %>
27
+ port: <%= ENV["FTP_PORT"] %>
28
+ username: <%= ENV["FTP_USERNAME"] %>
29
+ password: <%= ENV["FTP_PASSWORD"] %>
30
+ folder: <%= ENV["FTP_FOLDER"] %>
31
+ url: <%= ENV["FTP_URL"] %>
32
+ # optional
33
+ passive: true
34
+ ssl: false
35
+ debug_mode: false
36
+ ```
37
+
38
+ ## Development
39
+
40
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
41
+
42
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/iscreen/actives-torage-ftp.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,39 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'active_storage_ftp/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'active-storage-ftp'
8
+ spec.version = ActiveStorageFtp::VERSION
9
+ spec.authors = ["Dean Lin"]
10
+ spec.email = ["iscreen@gmail.com"]
11
+
12
+ spec.summary = %q{Active Storage FTP Service.}
13
+ spec.description = %q{Active Storage FTP Service.}
14
+ spec.homepage = 'https://api.genbagames.com/doc/'
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host"'] = 'https://rubygems.org'
20
+
21
+ spec.metadata['homepage_uri'] = spec.homepage
22
+ else
23
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
24
+ 'public gem pushes.'
25
+ end
26
+
27
+ # Specify which files should be added to the gem when it is released.
28
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
29
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
30
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
31
+ end
32
+ spec.bindir = 'exe'
33
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
+ spec.require_paths = ['lib']
35
+
36
+ spec.add_development_dependency 'bundler', '~> 2.0'
37
+ spec.add_development_dependency 'rake', '~> 10.0'
38
+ spec.add_development_dependency 'rspec', '~> 3.0'
39
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "activestorage/ftp"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,2 @@
1
+ # More logical way to require 'rest-client'
2
+ require File.dirname(__FILE__) + '/active_storage_ftp'
@@ -0,0 +1,183 @@
1
+ require 'net/ftp'
2
+
3
+ module ActiveStorage
4
+ class Service::FTPService < Service
5
+ def initialize(**config)
6
+ @config = config
7
+ end
8
+
9
+ def upload(key, io, checksum: nil, content_type: nil, disposition: nil, filename: nil)
10
+ instrument :upload, key: key, checksum: checksum do
11
+ connection do |ftp|
12
+ ftp.put(io, key)
13
+ end
14
+ end
15
+ end
16
+
17
+ def download(key, &block)
18
+ if block_given?
19
+ instrument :streaming_download, key: key do
20
+ stream(key, &block)
21
+ end
22
+ else
23
+ instrument :download, key: key do
24
+ stream(data) do |data|
25
+ result += data
26
+ end
27
+ result
28
+ rescue StandardError => _
29
+ raise ActiveStorage::FileNotFoundError
30
+ end
31
+ end
32
+ end
33
+
34
+ def update_metadata(key, content_type:, disposition: nil, filename: nil)
35
+ instrument :update_metadata, key: key, content_type: content_type, disposition: disposition do
36
+ # Nothing need to do
37
+ end
38
+ end
39
+
40
+ def download_chunk(key, range)
41
+ instrument :download_chunk, key: key, range: range do
42
+ connection do |ftp|
43
+ offset = range.begin
44
+ ftp.retrbinary("RETR #{key}", range.begin) do |data|
45
+ yield data
46
+ offset += data
47
+ end
48
+ end
49
+ rescue StandardError => _
50
+ raise ActiveStorage::FileNotFoundError
51
+ end
52
+ end
53
+
54
+ def delete(key)
55
+ instrument :delete, key: key do
56
+ connection do |ftp|
57
+ ftp.delete(key)
58
+ end
59
+ end
60
+ end
61
+
62
+ def delete_prefixed(prefix)
63
+ instrument :delete_prefixed, prefix: prefix do
64
+ connection do |ftp|
65
+ files = ftp.list("#{prefix}*")
66
+ files.each { |f| f.delete(f) }
67
+ end
68
+ end
69
+ end
70
+
71
+ def exist?(key)
72
+ instrument :exist, key: key do |payload|
73
+ connection do |ftp|
74
+ data = ftp.retrbinary("RETR #{key}")
75
+ answer = !data.nil?
76
+ payload[:exist] = answer
77
+ answer
78
+ end
79
+ end
80
+ end
81
+
82
+ def url(key, expires_in:, filename:, content_type:, disposition:)
83
+ instrument :url, key: key do |payload|
84
+ generated_url = url_for(key)
85
+ payload[:url]
86
+ generated_url
87
+ end
88
+ end
89
+
90
+ def url_for_direct_upload(key, expires_in:, checksum:, **)
91
+ instrument :url, key: key do |payload|
92
+ raise 'not support direct upload'
93
+ # generated_url = bucket.signed_url key, method: "PUT", expires: expires_in, content_md5: checksum
94
+
95
+ # payload[:url] = generated_url
96
+
97
+ # generated_url
98
+ end
99
+ end
100
+
101
+ def headers_for_direct_upload(key, checksum:, **)
102
+ { 'Content-MD5' => checksum }
103
+ end
104
+
105
+ private
106
+
107
+ attr_reader :config
108
+
109
+ def connection
110
+ EnhanceFtp.open(
111
+ ftp_host,
112
+ username: ftp_username,
113
+ password: ftp_password,
114
+ port: ftp_port,
115
+ passive: ftp_passive,
116
+ ssl: ftp_ssl,
117
+ debug_mode: ftp_debug_mode
118
+ ) do |ftp|
119
+ begin
120
+ ftp.chdir(ftp_folder)
121
+ rescue StandardError => _
122
+ ftp.mkdir_p(ftp_folder)
123
+ ftp.chdir(ftp_folder)
124
+ end
125
+ yield ftp
126
+ end
127
+ end
128
+
129
+ def path_for(key) #:nodoc:
130
+ File.join(ftp_folder, key)
131
+ end
132
+
133
+ def url_for(key)
134
+ file_url = [ftp_url, ftp_folder, key].join('/')
135
+ file_url
136
+ end
137
+
138
+ # Reads the file for the given key in chunks, yielding each to the block.
139
+ def stream(key)
140
+ connection do |ftp|
141
+ ftp.retrbinary("RETR #{key}", 5.megabytes) do |data|
142
+ yield data
143
+ end
144
+ end
145
+ end
146
+
147
+ def ftp_host
148
+ config.fetch(:host)
149
+ end
150
+
151
+ def ftp_username
152
+ config.fetch(:username)
153
+ end
154
+
155
+ def ftp_password
156
+ config.fetch(:password)
157
+ end
158
+
159
+ def ftp_port
160
+ config.fetch(:port)
161
+ end
162
+
163
+ def ftp_folder
164
+ config.fetch(:folder)
165
+ end
166
+
167
+ def ftp_ssl
168
+ config.fetch(:ssl, false)
169
+ end
170
+
171
+ def ftp_passive
172
+ config.fetch(:passive, true)
173
+ end
174
+
175
+ def ftp_url
176
+ config.fetch(:url)
177
+ end
178
+
179
+ def ftp_debug_mode
180
+ config.fetch(:debug_mode, false)
181
+ end
182
+ end
183
+ end
@@ -0,0 +1,12 @@
1
+ module ActiveStorageFtp
2
+ class EnhanceFtp < Net::Ftp
3
+ def mkdir_p(remove_path)
4
+ paths = remove_path.split('/')
5
+ full_path = paths.first == '~' ? '' : '/'
6
+ paths.each do |path|
7
+ full_path = File.join(full_path, path)
8
+ mkdir(full_path)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module ActiveStorageFtp
2
+ VERSION = '0.1.1'
3
+ end
@@ -0,0 +1,6 @@
1
+ require 'net/ftp'
2
+ require 'active_storage/service/ftp_service'
3
+ require 'active-storage-ftp/enhance_ftp'
4
+
5
+ module ActiveStorageFtp
6
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active-storage-ftp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dean Lin
@@ -58,7 +58,22 @@ email:
58
58
  executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
- files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - Gemfile.lock
67
+ - README.md
68
+ - Rakefile
69
+ - active_storage_ftp.gemspec
70
+ - bin/console
71
+ - bin/setup
72
+ - lib/active-storage-ftp.rb
73
+ - lib/active_storage/service/ftp_service.rb
74
+ - lib/active_storage_ftp.rb
75
+ - lib/active_storage_ftp/enhance_ftp.rb
76
+ - lib/active_storage_ftp/version.rb
62
77
  homepage: https://api.genbagames.com/doc/
63
78
  licenses: []
64
79
  metadata: