mountable_file_server 0.1.0 → 2.0.0

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
  SHA1:
3
- metadata.gz: 9eca97072a7e354d3523e099982afc7cf4234516
4
- data.tar.gz: 938444d589b364fb81bb16ab26244425601ba4eb
3
+ metadata.gz: 06ba105404c99a412b676531f8e1cf413dcef90e
4
+ data.tar.gz: 4b2a1588e17a8dc4ce720b9b88267e8a93f4fced
5
5
  SHA512:
6
- metadata.gz: 09226be2ad7e5f2ccfac19be367b42f44d94e9570a91a2046f541468a1aaca317eae56baf4829455e450814c831e30f3147897ee344f842f245ca846a812d45b
7
- data.tar.gz: 9f5d940813c63c26497be28472b5e12175ca4be1bec7903f8f5f21fe6412f89cdddaf26e75be3e2e3b4de40a628f898030e33b8f2b509c312625781edcd8067c
6
+ metadata.gz: 0f8109f98d14e82c53933a7e01a7fe7ef96ac4c321d03d57f075de188afef8432d9964126c1a838f4f6916a73de84446365d4a278c4fd7f97572bd4eaf68adb2
7
+ data.tar.gz: 759a235787657eeeecfdca45a6637b66686b3ca41bc8eac2c3e1018537c1fc7b5e99f117cca7c700bf648ef4ece6b55be0f51dced14e70f074384b3903456fa1
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 2.0.0
2
+ * Remove HTTP endpoints for moving and deleting uploads due to security concerns.
3
+ * Return 404 for unknown or malformed FIDs.
4
+
1
5
  # 0.0.2 - 24.08.2015
2
6
  * Internal refactorings.
3
7
  * Introduce `Adapter` class to have one point of contact.
data/README.md CHANGED
@@ -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.
@@ -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 = "2.0.0"
3
3
  end
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency "rack-test", "~> 0.6.3"
29
29
  spec.add_development_dependency "webmock", "~> 2.1.0"
30
30
 
31
- spec.add_runtime_dependency "sinatra", "~> 2.0.0.rc1"
31
+ spec.add_runtime_dependency "sinatra", "~> 2.0.0"
32
32
  spec.add_runtime_dependency "dry-configurable", "~> 0.1.6"
33
33
  spec.add_runtime_dependency "dimensions", "~> 1.3.0"
34
34
  end
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: 2.0.0
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: 2018-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -142,14 +142,14 @@ dependencies:
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: 2.0.0.rc1
145
+ version: 2.0.0
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: 2.0.0
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: dry-configurable
155
155
  requirement: !ruby/object:Gem::Requirement