shrine-transloadit 0.1.2 → 0.2.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/README.md +4 -19
- data/lib/shrine/plugins/transloadit.rb +36 -4
- data/shrine-transloadit.gemspec +2 -1
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f40ec5ac77cc70adcbccbe3dd19c37fea7eb515
|
4
|
+
data.tar.gz: f2dcde874d01e7edfdeccbafdc1913181b55e319
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4da721d4c333e12d33683349b53d68086b79fd5902addc2ae21d99c85b98549b61094b0ac090f9bffd6f380f56f6726e0669148a6f60f72b55656b1de0bc0fc
|
7
|
+
data.tar.gz: d9b21d982ea502e0e612d808943cac381ad6644d23866f608cefccc5a5bc7a901d86abdeca9e760d145629c83c005f6ffdf70312ac7d3d87841475d4bd5a6e73
|
data/README.md
CHANGED
@@ -218,25 +218,10 @@ only want to do some light processing on direct uploads, and without any
|
|
218
218
|
exporting, so that you have better control over your Transloadit bandwidth.
|
219
219
|
|
220
220
|
When direct upload finishes, Transloadit returns information about the uploaded
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
```js
|
227
|
-
{
|
228
|
-
id: data['url'], // we save the URL
|
229
|
-
storage: 'cache',
|
230
|
-
metadata: {
|
231
|
-
size: data['size'],
|
232
|
-
filename: data['name'],
|
233
|
-
mime_type: data['mime'],
|
234
|
-
width: data['meta'] && data['meta']['width'],
|
235
|
-
height: data['meta'] && data['meta']['height'],
|
236
|
-
transloadit: data['meta'],
|
237
|
-
}
|
238
|
-
}
|
239
|
-
```
|
221
|
+
file(s). You can just convert that data to a JSON string and pass it as attachment
|
222
|
+
value (e.g. by assigning it to the hidden attachment field), and the plugin
|
223
|
+
will automatically recognize it and convert it to Shrine's attachment
|
224
|
+
representation.
|
240
225
|
|
241
226
|
See the **[demo app]** for a complete implementation of direct uploads.
|
242
227
|
|
@@ -1,7 +1,10 @@
|
|
1
1
|
require "transloadit"
|
2
|
+
require "down"
|
3
|
+
|
2
4
|
require "uri"
|
3
5
|
require "json"
|
4
6
|
require "openssl"
|
7
|
+
require "net/http"
|
5
8
|
|
6
9
|
class Shrine
|
7
10
|
module Plugins
|
@@ -58,7 +61,7 @@ class Shrine
|
|
58
61
|
response = assembly.submit!
|
59
62
|
raise Error, "#{response["error"]}: #{response["message"]}" if response["error"]
|
60
63
|
cached_file.metadata["transloadit_response"] = response.body.to_json
|
61
|
-
swap(cached_file)
|
64
|
+
swap(cached_file) or _set(cached_file)
|
62
65
|
end
|
63
66
|
|
64
67
|
def transloadit_save(response, valid: true)
|
@@ -74,11 +77,24 @@ class Shrine
|
|
74
77
|
end
|
75
78
|
|
76
79
|
if valid
|
77
|
-
|
80
|
+
swap(stored_file)
|
78
81
|
else
|
79
82
|
_delete(stored_file, phase: :abort)
|
80
83
|
end
|
81
84
|
end
|
85
|
+
|
86
|
+
def uploaded_file(value)
|
87
|
+
if value.is_a?(String) || value.is_a?(Hash)
|
88
|
+
value = JSON.parse(value) if value.is_a?(String)
|
89
|
+
if value["url"].is_a?(String) # from direct upload
|
90
|
+
cache.transloadit_uploaded_file(value)
|
91
|
+
else
|
92
|
+
super
|
93
|
+
end
|
94
|
+
else
|
95
|
+
super
|
96
|
+
end
|
97
|
+
end
|
82
98
|
end
|
83
99
|
|
84
100
|
module ClassMethods
|
@@ -93,8 +109,9 @@ class Shrine
|
|
93
109
|
module InstanceMethods
|
94
110
|
def transloadit_uploaded_file(result)
|
95
111
|
case url = result.fetch("url")
|
112
|
+
when /tmp\.transloadit\.com/
|
113
|
+
id = url
|
96
114
|
when /amazonaws\.com/
|
97
|
-
raise Error, "Cannot save a processed file which wasn't exported: #{url.inspect}" if url.include?("tmp.transloadit.com")
|
98
115
|
path = URI(url).path
|
99
116
|
id = path.match(/^\/#{storage.prefix}/).post_match
|
100
117
|
else
|
@@ -103,7 +120,7 @@ class Shrine
|
|
103
120
|
|
104
121
|
self.class::UploadedFile.new(
|
105
122
|
"id" => id,
|
106
|
-
"storage" => storage_key,
|
123
|
+
"storage" => storage_key.to_s,
|
107
124
|
"metadata" => {
|
108
125
|
"filename" => result.fetch("name"),
|
109
126
|
"size" => result.fetch("size"),
|
@@ -266,6 +283,21 @@ class Shrine
|
|
266
283
|
end
|
267
284
|
|
268
285
|
class UrlStorage
|
286
|
+
def download(id)
|
287
|
+
Down.download(id)
|
288
|
+
end
|
289
|
+
|
290
|
+
def open(id)
|
291
|
+
Down.open(id)
|
292
|
+
end
|
293
|
+
|
294
|
+
def exists?(id)
|
295
|
+
response = nil
|
296
|
+
uri = URI(id)
|
297
|
+
Net::HTTP.start(uri.host, uri.port) { |http| response = http.head(id) }
|
298
|
+
response.code.to_i == 200
|
299
|
+
end
|
300
|
+
|
269
301
|
def url(id, **options)
|
270
302
|
id
|
271
303
|
end
|
data/shrine-transloadit.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |gem|
|
2
2
|
gem.name = "shrine-transloadit"
|
3
|
-
gem.version = "0.
|
3
|
+
gem.version = "0.2.0"
|
4
4
|
|
5
5
|
gem.required_ruby_version = ">= 2.1"
|
6
6
|
|
@@ -15,6 +15,7 @@ Gem::Specification.new do |gem|
|
|
15
15
|
|
16
16
|
gem.add_dependency "shrine", "~> 2.1"
|
17
17
|
gem.add_dependency "transloadit", "~> 1.2"
|
18
|
+
gem.add_dependency "down", ">= 2.3.3"
|
18
19
|
|
19
20
|
gem.add_development_dependency "rake"
|
20
21
|
gem.add_development_dependency "minitest"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shrine-transloadit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Janko Marohnić
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: down
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.3.3
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.3.3
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rake
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|