tus-server 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ac1db8e0078cd0824caf54dc3c1993957ca90902
4
- data.tar.gz: 032f12c4aaa676e7f55388f8af96d7a46cad42a7
3
+ metadata.gz: c1e0b6de3b8d7235547c83c2cbbb68070db193ba
4
+ data.tar.gz: b66d6f3fa1a83fe8edf090b110ba96dd1f73f679
5
5
  SHA512:
6
- metadata.gz: 45aa99b75d86eb9197fa3edcb8fd4a140004e9e48bb955327e5e77dd7ac3fa3b407a5782f4bcf12fb2a7277704f4ea4cfd6a2972a35d3d69b5e3c778708dcb0f
7
- data.tar.gz: b27487dc797127e1c51010e65e1ad44e22206bfcc8ff5dbecc4136eedf4c2197c6ae13b1d32bada612d614844f61e9780349748050559bb47c2ea386306bf31d
6
+ metadata.gz: 2b91c48408c262844816d2f0a4747c80da01a6cc69743b1a18c5a2c2026cd9ce05ffe9caafda4d8e4d344768e866d741f344a96bf971be958de215416ac5ec05
7
+ data.tar.gz: 87467de1991030125c12b3b8747b6436d09472c6ab26f540b16feffd4a593d4d94e1fa6b5aeb3cdb2ec1045b261508a8a6815cba236862acb4014d5d8826da80
data/README.md CHANGED
@@ -37,7 +37,7 @@ endpoint:
37
37
  // using tus-js-client
38
38
  new tus.Upload(file, {
39
39
  endpoint: "http://localhost:9292/files",
40
- chunkSize: 15*1024*1024, # 15 MB
40
+ chunkSize: 15*1024*1024, // 15 MB
41
41
  // ...
42
42
  })
43
43
  ```
@@ -50,7 +50,7 @@ see [shrine-tus-demo] on how you can integrate the two.
50
50
 
51
51
  As per tus protocol, you can assign custom metadata when creating a file using
52
52
  the `Upload-Metadata` header. When retrieving the file via a GET request,
53
- tus-server will use
53
+ tus-ruby-server will use
54
54
 
55
55
  * `content_type` -- for setting the `Content-Type` header
56
56
  * `filename` -- for setting the `Content-Disposition` header
@@ -72,8 +72,9 @@ The downside of storing files on the filesystem is that it isn't distributed,
72
72
  so for resumable uploads to work you have to host the tus application on a
73
73
  single server.
74
74
 
75
- However, tus-server also ships with MongoDB [GridFS] storage, which among other
76
- things is convenient for a multi-server setup. It requires the [Mongo] gem:
75
+ However, tus-ruby-server also ships with MongoDB [GridFS] storage, which among
76
+ other things is convenient for a multi-server setup. It requires the [Mongo]
77
+ gem:
77
78
 
78
79
  ```rb
79
80
  gem "mongo"
@@ -129,8 +130,8 @@ The following checksum algorithms are supported for the `checksum` extension:
129
130
 
130
131
  ## Limitations
131
132
 
132
- Since tus-server is built using a Rack-based web framework (Roda), if a PATCH
133
- request gets interrupted, none of the received data will be stored. It's
133
+ Since tus-ruby-server is built using a Rack-based web framework (Roda), if a
134
+ PATCH request gets interrupted, none of the received data will be stored. It's
134
135
  recommended to configure your client tus library not to use a single PATCH
135
136
  request for large files, but rather to split it into multiple chunks. You can
136
137
  do that for [tus-js-client] by specifying a maximum chunk size:
@@ -138,7 +139,7 @@ do that for [tus-js-client] by specifying a maximum chunk size:
138
139
  ```js
139
140
  new tus.Upload(file, {
140
141
  endpoint: "http://localhost:9292/files",
141
- chunkSize: 15*1024*1024, # 15 MB
142
+ chunkSize: 15*1024*1024, // 15 MB
142
143
  // ...
143
144
  })
144
145
  ```
@@ -147,6 +148,10 @@ Tus-server also currently doesn't support the `checksum-trailer` extension,
147
148
  which would allow sending the checksum header *after* the data has been sent,
148
149
  using [trailing headers].
149
150
 
151
+ ## Inspiration
152
+
153
+ The tus-ruby-server was inspired by [rubytus].
154
+
150
155
  ## License
151
156
 
152
157
  [MIT](/LICENSE.txt)
@@ -158,7 +163,9 @@ using [trailing headers].
158
163
  [checksum]: http://tus.io/protocols/resumable-upload.html#checksum
159
164
  [expiration]: http://tus.io/protocols/resumable-upload.html#expiration
160
165
  [termination]: http://tus.io/protocols/resumable-upload.html#termination
161
- [GridFS]: https://docs.mongodb.org/v3.0/core/gridfs/
166
+ [GridFS]: https://docs.mongodb.org/v3.0/core/gridfs/
167
+ [Mongo]: https://github.com/mongodb/mongo-ruby-driver
162
168
  [shrine-tus-demo]: https://github.com/janko-m/shrine-tus-demo
163
169
  [Shrine]: https://github.com/janko-m/shrine
164
170
  [trailing headers]: https://tools.ietf.org/html/rfc7230#section-4.1.2
171
+ [rubytus]: https://github.com/picocandy/rubytus
data/lib/tus/server.rb CHANGED
@@ -27,7 +27,6 @@ module Tus
27
27
  plugin :all_verbs
28
28
  plugin :delete_empty_headers
29
29
  plugin :request_headers
30
- plugin :default_headers, "Content-Type" => ""
31
30
  plugin :not_allowed
32
31
 
33
32
  route do |r|
@@ -95,8 +94,6 @@ module Tus
95
94
  end
96
95
 
97
96
  r.is ":uid" do |uid|
98
- not_found! unless storage.file_exists?(uid)
99
-
100
97
  r.options do
101
98
  response.headers.update(
102
99
  "Tus-Version" => SUPPORTED_VERSIONS.join(","),
@@ -108,13 +105,27 @@ module Tus
108
105
  no_content!
109
106
  end
110
107
 
108
+ r.delete do
109
+ storage.delete_file(uid)
110
+
111
+ no_content!
112
+ end
113
+
114
+ not_found! unless storage.file_exists?(uid)
115
+
111
116
  r.get do
112
117
  path = storage.download_file(uid)
113
118
  info = Info.new(storage.read_info(uid))
114
119
 
115
- file = Rack::File.new(File.dirname(path))
120
+ server = Rack::File.new(File.dirname(path))
116
121
 
117
- result = file.serving(request, path)
122
+ result = if ::Rack.release > "2"
123
+ server.serving(request, path)
124
+ else
125
+ server = server.dup
126
+ server.path = path
127
+ server.serving(env)
128
+ end
118
129
 
119
130
  response.status = result[0]
120
131
  response.headers.update(result[1])
@@ -160,12 +171,6 @@ module Tus
160
171
 
161
172
  no_content!
162
173
  end
163
-
164
- r.delete do
165
- storage.delete_file(uid)
166
-
167
- no_content!
168
- end
169
174
  end
170
175
  end
171
176
 
@@ -273,12 +278,13 @@ module Tus
273
278
 
274
279
  def no_content!
275
280
  response.status = 204
276
- response.headers["Content-Length"] = ""
281
+ request.halt
277
282
  end
278
283
 
279
284
  def created!(location)
280
285
  response.status = 201
281
286
  response.headers["Location"] = location
287
+ request.halt
282
288
  end
283
289
 
284
290
  def not_found!(message = "Upload not found")
@@ -34,8 +34,10 @@ module Tus
34
34
  end
35
35
 
36
36
  def delete_file(uid)
37
- file_path(uid).delete
38
- info_path(uid).delete
37
+ if file_exists?(uid)
38
+ file_path(uid).delete
39
+ info_path(uid).delete
40
+ end
39
41
  end
40
42
 
41
43
  def read_info(uid)
@@ -46,7 +46,7 @@ module Tus
46
46
 
47
47
  def delete_file(uid)
48
48
  file_info = bucket.files_collection.find(filename: uid).first
49
- bucket.delete(file_info.fetch("_id"))
49
+ bucket.delete(file_info.fetch("_id")) if file_info
50
50
  end
51
51
 
52
52
  def read_info(uid)
data/tus-server.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "tus-server"
3
- gem.version = "0.1.0"
3
+ gem.version = "0.1.1"
4
4
 
5
5
  gem.required_ruby_version = ">= 2.1"
6
6
 
@@ -14,8 +14,7 @@ Gem::Specification.new do |gem|
14
14
  gem.files = Dir["README.md", "LICENSE.txt", "lib/**/*.rb", "*.gemspec"]
15
15
  gem.require_path = "lib"
16
16
 
17
- gem.add_dependency "roda", "~> 2.17"
18
- gem.add_dependency "rack", "~> 2.0"
17
+ gem.add_dependency "roda", "~> 2.19"
19
18
 
20
19
  gem.add_development_dependency "rake", "~> 11.1"
21
20
  gem.add_development_dependency "minitest", "~> 5.8"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tus-server
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
  - Janko Marohnić
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-22 00:00:00.000000000 Z
11
+ date: 2016-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: roda
@@ -16,28 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.17'
19
+ version: '2.19'
20
20
  type: :runtime
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: '2.17'
27
- - !ruby/object:Gem::Dependency
28
- name: rack
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '2.0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '2.0'
26
+ version: '2.19'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rake
43
29
  requirement: !ruby/object:Gem::Requirement