mountable_file_server 0.1.0 → 3.0.2

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
- SHA1:
3
- metadata.gz: 9eca97072a7e354d3523e099982afc7cf4234516
4
- data.tar.gz: 938444d589b364fb81bb16ab26244425601ba4eb
2
+ SHA256:
3
+ metadata.gz: '086ef547685f9b8f4ca5d2dc5ef78d599006fb16da4b26c9037123ce63d2d260'
4
+ data.tar.gz: c7ddc3f6ab666fe4a24d45acc4d83ae9bf5e8f66d1a7382913f1387bde8522e5
5
5
  SHA512:
6
- metadata.gz: 09226be2ad7e5f2ccfac19be367b42f44d94e9570a91a2046f541468a1aaca317eae56baf4829455e450814c831e30f3147897ee344f842f245ca846a812d45b
7
- data.tar.gz: 9f5d940813c63c26497be28472b5e12175ca4be1bec7903f8f5f21fe6412f89cdddaf26e75be3e2e3b4de40a628f898030e33b8f2b509c312625781edcd8067c
6
+ metadata.gz: 50e035cca646a00c33bdefed071fce9a0177e6f36f5595c10e9e34d20a349a9fb26905ea727c2adb7f0c20bde582a5b2245eb83a507bb5b1aa959ae003a7fcbd
7
+ data.tar.gz: 31a502e8602d71c906e208a0b75749d0467fa522938868c2848ece0c9b725ae742b168f8b6d9f58ec82881a4253f2fb3ecf104a541743e39ea0ff136877ace08
data/.gitignore CHANGED
@@ -16,4 +16,4 @@ mkmf.log
16
16
  *.sqlite3
17
17
  test/rails-dummy/tmp/
18
18
  test/rails-dummy/uploads/
19
- .ruby-version
19
+ /.local-data/
@@ -0,0 +1 @@
1
+ 2.5.8
@@ -1,3 +1,20 @@
1
+ # 3.0.2
2
+ * Fix deprecation warning when calling metadata class initializer with keyword arguments.
3
+ * Don't break when uploading a private file.
4
+
5
+ # 3.0.1
6
+ * Repair broken `FileAccessor` class.
7
+
8
+ # 3.0.0
9
+ * **Breaking Change**: Remove `MountableFileServer::Client`. Use `MountableFileServer::Adapter` instead.
10
+
11
+ # 2.1.0
12
+ * Relax Sinatra dependency so Ruby on Rails 4 can use Rack 1.X
13
+
14
+ # 2.0.0
15
+ * Remove HTTP endpoints for moving and deleting uploads due to security concerns.
16
+ * Return 404 for unknown or malformed FIDs.
17
+
1
18
  # 0.0.2 - 24.08.2015
2
19
  * Internal refactorings.
3
20
  * Introduce `Adapter` class to have one point of contact.
data/README.md CHANGED
@@ -4,7 +4,7 @@ Mountable File Server can be used with any Ruby (on Rails) application and it re
4
4
  app only stores reference to uploaded file
5
5
 
6
6
  ## MountableFileServer::Server
7
- The core of Mountable File Server (MFS) is a small HTTP API that accepts file uploads and offers endpoints to interact with uploaded files. While the frontend deals directly with the HTTP API, your Ruby application will want to use the Ruby Client `MountableFileServer::Client`.
7
+ The core of Mountable File Server (MFS) is a small HTTP API that accepts file uploads and offers endpoints to interact with uploaded files. While the frontend deals directly with the HTTP API, your Ruby application will want to use the Ruby adapter `MountableFileServer::Adapter`.
8
8
 
9
9
 
10
10
 
@@ -53,7 +53,7 @@ end
53
53
  ~~~
54
54
 
55
55
  ## Configuration
56
- As seen in the previous section there is a global configuration at `MountableFileServer.configuration` available.
56
+ As seen in the previous section there is a global configuration at `MountableFileServer.configuration` available.
57
57
  This is an instance of the `MountableFileServer::Configration` class. The global configuration is a default argument for all classes that require access to the configuration. In situations where you have multiple endpoints with different settings you can pass in you own configuration objects instead.
58
58
 
59
59
  The global configuration can be configured through a block.
@@ -81,36 +81,41 @@ The `files` argument is an array of `File` objects or an `FileList` object. Thes
81
81
 
82
82
  Following events will be dispatched on the element that was passed to `uploadFiles`. When you are listening to one of these events you can access the described attributes on the `event.detail` object.
83
83
 
84
- `upload:start` is dispatched when the upload starts.
84
+ `upload:start` is dispatched when the upload starts.
85
85
  It has the attributes `uploadId` and `file`. The `uploadId` is local and can be used to identify events in a scenario where multiple files are uploaded. The `file` attribute is the original `File` object and useful for showing a preview or other information about the file.
86
86
 
87
- `upload:progress` is continuously dispatched while the upload is happening.
87
+ `upload:progress` is continuously dispatched while the upload is happening.
88
88
  It has the attributes `uploadId` and `progress`. The `progress` attribute is the original [ProgressEvent](https://developer.mozilla.org/en-US/docs/Web/API/ProgressEvent) object of the AJAX request.
89
89
 
90
- `upload:success` is dispatched when the upload succeeded.
90
+ `upload:success` is dispatched when the upload succeeded.
91
91
  It has the attributes `uploadId`, `uid` and `wasLastUpload`. The `uid` attribute is the unique identifier generated by the MountableFileServer. You will want to add it to your form and store it along your other data. The `wasLastUpload` attribute indicates if this was the last upload in progress.
92
92
 
93
93
  ## Ruby API
94
94
  The `MountableFileServer::Adapter` class allows you to interact with uploaded files. It takes a `MountableFileServer::Configuration` instance as argument and uses `MountableFileServer.configuration` by default.
95
95
 
96
- `MountableFileServer::Adapter#store_temporary(input, type, extension)`
96
+ `MountableFileServer::Adapter#store_temporary(input, type, extension)`
97
97
  Stores the input as file in the temporary storage and returns the `uid` of the file. `input` can be a path to a file or an [IO](http://ruby-doc.org/core-2.2.2/IO.html) object. `type` can be `public` or `private` and the `extension` argument specifies the extension the file should have.
98
98
 
99
- `MountableFileServer::Adapter#store_permanent(input, type, extension)`
99
+ `MountableFileServer::Adapter#store_permanent(input, type, extension)`
100
100
  Stores the input as file in the permanent storage and returns the `uid` of the file. `input` can be a path to a file or an [IO](http://ruby-doc.org/core-2.2.2/IO.html) object. `type` can be `public` or `private` and the `extension` argument specifies the extension the file should have.
101
101
 
102
- `MountableFileServer::Adapter#move_to_permanent_storage(uid)`
102
+ `MountableFileServer::Adapter#move_to_permanent_storage(uid)`
103
103
  Moves a file from the temporary storage to the permanent one. This is mostly used in a scenario where users upload files. A file uploaded through the endpoint is initially only stored in the temporary storage. The application has to move it explicitly to the permanent storage. For example after all validations passed.
104
104
 
105
- `MountableFileServer::Adapter#remove_from_permanent_storage(uid)`
105
+ `MountableFileServer::Adapter#remove_from_permanent_storage(uid)`
106
106
  Removes the file from the permanent storage.
107
107
 
108
- `MountableFileServer::Adapter#url_for(uid)`
108
+ `MountableFileServer::Adapter#url_for(uid)`
109
109
  Returns the URL for an uploaded file. Only works for public files, if you pass the `uid` of a private file an error will be raised.
110
110
 
111
- `MountableFileServer::Adapter#pathname_for(id)`
111
+ `MountableFileServer::Adapter#pathname_for(id)`
112
112
  Returns a [Pathname](http://ruby-doc.org/stdlib-2.2.2/libdoc/pathname/rdoc/Pathname.html) object for the uploaded file. The pathname will always point to the file on disk independent from the files type or current storage location.
113
113
 
114
+ # Development
115
+ Run the migrations of the Ruby on Rails dummy application to make sure you can run the tests: `cd test/rails-dummy && RAILS_ENV=test bundle exec rake db:migrate`.
116
+
117
+ Run tests with `bundle exec rake test`.
118
+
114
119
  # Publish on RubyGems.org
115
120
 
116
121
  1. Increment `lib/mountable_image_server/version.rb` to your liking.
@@ -33,9 +33,8 @@ module MountableFileServer
33
33
  end
34
34
 
35
35
  def url_for(uid)
36
- # uid = UniqueIdentifier.new uid
37
- # FileAccessor.new(uid, configuration).url
38
- configuration.base_url + uid
36
+ uid = UniqueIdentifier.new uid
37
+ FileAccessor.new(uid, configuration).url
39
38
  end
40
39
 
41
40
  def pathname_for(uid)
@@ -1,3 +1,4 @@
1
+ require 'mountable_file_server/uri'
1
2
  require 'pathname'
2
3
 
3
4
  module MountableFileServer
@@ -39,7 +39,7 @@ module MountableFileServer
39
39
  parameters[:height] = dimensions[1]
40
40
  end
41
41
 
42
- new(parameters)
42
+ new(**parameters)
43
43
  end
44
44
  end
45
45
  end
@@ -1,6 +1,5 @@
1
1
  require 'mountable_file_server'
2
2
  require 'mountable_file_server/server'
3
- require 'mountable_file_server/client'
4
3
 
5
4
  module MountableFileServer
6
5
  class Engine < Rails::Engine
@@ -11,7 +11,7 @@ module MountableFileServer
11
11
  pathname = Pathname(params[:file][:tempfile].path)
12
12
  type = params[:type]
13
13
  fid = adapter.store_temporary(pathname, type, pathname.extname)
14
- url = adapter.url_for(fid)
14
+ url = adapter.url_for(fid) if fid.public?
15
15
  metadata = Metadata.for_path(pathname)
16
16
 
17
17
  content_type :json
@@ -25,25 +25,13 @@ module MountableFileServer
25
25
  end
26
26
 
27
27
  get '/:fid' do |fid|
28
- adapter = Adapter.new
29
- pathname = adapter.pathname_for(fid)
30
- send_file pathname
31
- end
32
-
33
- post '/:fid/store-permanent' do |fid|
34
- adapter = Adapter.new
35
- adapter.move_to_permanent_storage(fid)
36
-
37
- content_type :json
38
- status 200
39
- end
40
-
41
- delete '/:fid' do |fid|
42
- adapter = Adapter.new
43
- adapter.remove_from_storage(fid)
44
-
45
- content_type :json
46
- status 200
28
+ begin
29
+ adapter = Adapter.new
30
+ pathname = adapter.pathname_for(fid)
31
+ send_file pathname
32
+ rescue MissingFile, MalformedIdentifier
33
+ status 404
34
+ end
47
35
  end
48
36
  end
49
37
  end
@@ -2,11 +2,14 @@ require 'securerandom'
2
2
 
3
3
  module MountableFileServer
4
4
  UnknownType = Class.new(ArgumentError)
5
+ MalformedIdentifier = Class.new(ArgumentError)
5
6
 
6
7
  class UniqueIdentifier < String
7
8
  attr_reader :type, :filename
8
9
 
9
10
  def initialize(string)
11
+ raise MalformedIdentifier.new unless /(\w+)-(.+)$/.match(string)
12
+
10
13
  @type, @filename = /(\w+)-(.+)$/.match(string).captures
11
14
 
12
15
  raise UnknownType.new(type) unless known_type?
@@ -1,3 +1,3 @@
1
1
  module MountableFileServer
2
- VERSION = "0.1.0"
2
+ VERSION = "3.0.2"
3
3
  end
@@ -18,17 +18,17 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.7"
22
- spec.add_development_dependency "rake", "~> 10.0"
21
+ spec.add_development_dependency "bundler", "~> 2.1"
22
+ spec.add_development_dependency "rake", ">= 12.3.3"
23
23
  spec.add_development_dependency "minitest", "~> 5.8.0"
24
- spec.add_development_dependency "rails", "~> 5.0.2"
25
- spec.add_development_dependency "capybara", "~> 2.4.4"
24
+ spec.add_development_dependency "rails", "~> 5.0.7.2"
25
+ spec.add_development_dependency "capybara", "2.18.0"
26
26
  spec.add_development_dependency "sqlite3", "~> 1.3.10"
27
- spec.add_development_dependency "poltergeist", "~> 1.6.0"
27
+ spec.add_development_dependency "poltergeist", "1.18.1"
28
28
  spec.add_development_dependency "rack-test", "~> 0.6.3"
29
- spec.add_development_dependency "webmock", "~> 2.1.0"
29
+ spec.add_development_dependency "mocha", "1.11.2"
30
30
 
31
- spec.add_runtime_dependency "sinatra", "~> 2.0.0.rc1"
31
+ spec.add_runtime_dependency "sinatra", ">= 1.4.8"
32
32
  spec.add_runtime_dependency "dry-configurable", "~> 0.1.6"
33
33
  spec.add_runtime_dependency "dimensions", "~> 1.3.0"
34
34
  end
@@ -0,0 +1,26 @@
1
+ {
2
+ pkgs ? import (fetchGit {
3
+ url = https://github.com/NixOS/nixpkgs-channels;
4
+ ref = "nixos-20.03";
5
+ }) {},
6
+ ruby ? pkgs.ruby_2_5,
7
+ bundler ? pkgs.bundler.override { inherit ruby; }
8
+ }:
9
+
10
+ pkgs.mkShell {
11
+ buildInputs = with pkgs; [
12
+ ruby
13
+ bundler
14
+ git
15
+ sqlite
16
+ zlib
17
+ phantomjs
18
+ rubyPackages_2_5.nokogiri
19
+ ];
20
+
21
+ shellHook = ''
22
+ mkdir -p .local-data/gems
23
+ export GEM_HOME=$PWD/.local-data/gems
24
+ export GEM_PATH=$GEM_HOME
25
+ '';
26
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mountable_file_server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Strauß
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-10 00:00:00.000000000 Z
11
+ date: 1970-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.7'
19
+ version: '2.1'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.7'
26
+ version: '2.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: 12.3.3
34
34
  type: :development
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: '10.0'
40
+ version: 12.3.3
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -58,28 +58,28 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 5.0.2
61
+ version: 5.0.7.2
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 5.0.2
68
+ version: 5.0.7.2
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: capybara
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - '='
74
74
  - !ruby/object:Gem::Version
75
- version: 2.4.4
75
+ version: 2.18.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - '='
81
81
  - !ruby/object:Gem::Version
82
- version: 2.4.4
82
+ version: 2.18.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: sqlite3
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -98,16 +98,16 @@ dependencies:
98
98
  name: poltergeist
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - '='
102
102
  - !ruby/object:Gem::Version
103
- version: 1.6.0
103
+ version: 1.18.1
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - "~>"
108
+ - - '='
109
109
  - !ruby/object:Gem::Version
110
- version: 1.6.0
110
+ version: 1.18.1
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rack-test
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -123,33 +123,33 @@ dependencies:
123
123
  - !ruby/object:Gem::Version
124
124
  version: 0.6.3
125
125
  - !ruby/object:Gem::Dependency
126
- name: webmock
126
+ name: mocha
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - "~>"
129
+ - - '='
130
130
  - !ruby/object:Gem::Version
131
- version: 2.1.0
131
+ version: 1.11.2
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - "~>"
136
+ - - '='
137
137
  - !ruby/object:Gem::Version
138
- version: 2.1.0
138
+ version: 1.11.2
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: sinatra
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - "~>"
143
+ - - ">="
144
144
  - !ruby/object:Gem::Version
145
- version: 2.0.0.rc1
145
+ version: 1.4.8
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - "~>"
150
+ - - ">="
151
151
  - !ruby/object:Gem::Version
152
- version: 2.0.0.rc1
152
+ version: 1.4.8
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: dry-configurable
155
155
  requirement: !ruby/object:Gem::Requirement
@@ -186,6 +186,7 @@ extensions: []
186
186
  extra_rdoc_files: []
187
187
  files:
188
188
  - ".gitignore"
189
+ - ".ruby-version"
189
190
  - ".travis.yml"
190
191
  - CHANGELOG.md
191
192
  - Gemfile
@@ -194,7 +195,6 @@ files:
194
195
  - Rakefile
195
196
  - lib/mountable_file_server.rb
196
197
  - lib/mountable_file_server/adapter.rb
197
- - lib/mountable_file_server/client.rb
198
198
  - lib/mountable_file_server/file_accessor.rb
199
199
  - lib/mountable_file_server/metadata.rb
200
200
  - lib/mountable_file_server/rails.rb
@@ -204,6 +204,7 @@ files:
204
204
  - lib/mountable_file_server/uri.rb
205
205
  - lib/mountable_file_server/version.rb
206
206
  - mountable_file_server.gemspec
207
+ - shell.nix
207
208
  - vendor/assets/javascripts/mountable_file_server.js
208
209
  homepage: https://github.com/stravid/mountable_file_server
209
210
  licenses:
@@ -224,8 +225,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
224
225
  - !ruby/object:Gem::Version
225
226
  version: '0'
226
227
  requirements: []
227
- rubyforge_project:
228
- rubygems_version: 2.5.1
228
+ rubygems_version: 3.1.2
229
229
  signing_key:
230
230
  specification_version: 4
231
231
  summary: Simple mountable server that handles file uploads
@@ -1,44 +0,0 @@
1
- require 'net/http'
2
- require 'uri'
3
- require 'stringio'
4
-
5
- module MountableFileServer
6
- class Client
7
- def move_to_permanent_storage(fid)
8
- if MountableFileServer.config.base_url.start_with?('http')
9
- uri = ::URI.parse(MountableFileServer.config.base_url)
10
- http = Net::HTTP.new(uri.host, uri.port)
11
- http.set_debug_output($stdout)
12
- request = Net::HTTP::Post.new(uri.request_uri + fid + '/store-permanent')
13
-
14
- http.request(request)
15
- else
16
- MountableFileServer::Server.new.call({
17
- "rack.input" => StringIO.new(""),
18
- "REQUEST_METHOD"=> "POST",
19
- "PATH_INFO"=> "/#{fid}/store-permanent",
20
- })
21
- end
22
- end
23
-
24
- def remove_from_storage(fid)
25
- if MountableFileServer.config.base_url.start_with?('http')
26
- uri = ::URI.parse(MountableFileServer.config.base_url)
27
- http = Net::HTTP.new(uri.host, uri.port)
28
- request = Net::HTTP::Delete.new(uri.request_uri + fid)
29
-
30
- http.request(request)
31
- else
32
- MountableFileServer::Server.new.call({
33
- "rack.input" => StringIO.new(""),
34
- "REQUEST_METHOD"=> "DELETE",
35
- "PATH_INFO"=> "/#{fid}",
36
- })
37
- end
38
- end
39
-
40
- def url_for(fid)
41
- MountableFileServer.config.base_url + fid
42
- end
43
- end
44
- end