mountable_file_server 0.1.0 → 2.0.0
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/CHANGELOG.md +4 -0
- data/README.md +15 -10
- data/lib/mountable_file_server/server.rb +7 -19
- data/lib/mountable_file_server/unique_identifier.rb +3 -0
- data/lib/mountable_file_server/version.rb +1 -1
- data/mountable_file_server.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06ba105404c99a412b676531f8e1cf413dcef90e
|
4
|
+
data.tar.gz: 4b2a1588e17a8dc4ce720b9b88267e8a93f4fced
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f8109f98d14e82c53933a7e01a7fe7ef96ac4c321d03d57f075de188afef8432d9964126c1a838f4f6916a73de84446365d4a278c4fd7f97572bd4eaf68adb2
|
7
|
+
data.tar.gz: 759a235787657eeeecfdca45a6637b66686b3ca41bc8eac2c3e1018537c1fc7b5e99f117cca7c700bf648ef4ece6b55be0f51dced14e70f074384b3903456fa1
|
data/CHANGELOG.md
CHANGED
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
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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?
|
@@ -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
|
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.
|
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:
|
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
|
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
|
152
|
+
version: 2.0.0
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: dry-configurable
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|