dato 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/dato.gemspec +0 -1
- data/lib/dato/upload/file.rb +28 -14
- data/lib/dato/version.rb +1 -1
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22be7e5b5bd13a7df1d3ebf63c52ce769b0333d0c8a90e0d8f5d3da7dda8712a
|
4
|
+
data.tar.gz: 4fda2a299ace4004514ed7727d789271a5a4d23361c02eaad3f59d7b9132e7c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f6b5c6e85c74e541ea03b77da23c0284e6447386af8adc4e0918b699028666b0888c1df2f27d701013efec3c75ea8fbec9e8d7b97e0ab54b87945373086ce45
|
7
|
+
data.tar.gz: 285b84bdbcd3e1932fbf65ab72cb9a5519a59eaacde9b7b7150572849efb68dec1f7f0e1fd64ca7f09010e238deefe8d3073e23e3177293d5da980994791442b
|
data/dato.gemspec
CHANGED
@@ -36,7 +36,6 @@ Gem::Specification.new do |spec|
|
|
36
36
|
spec.add_runtime_dependency 'faraday_middleware', ['>= 0.9.0']
|
37
37
|
spec.add_runtime_dependency 'activesupport', ['>= 4.2.7']
|
38
38
|
spec.add_runtime_dependency 'fastimage'
|
39
|
-
spec.add_runtime_dependency 'downloadr'
|
40
39
|
spec.add_runtime_dependency 'addressable'
|
41
40
|
spec.add_runtime_dependency 'thor'
|
42
41
|
spec.add_runtime_dependency 'imgix', ['>= 0.3.1']
|
data/lib/dato/upload/file.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'fastimage'
|
4
4
|
require 'tempfile'
|
5
5
|
require 'addressable'
|
6
6
|
require 'net/http'
|
7
|
-
require 'fastimage'
|
8
7
|
|
9
8
|
module Dato
|
10
9
|
module Upload
|
@@ -21,10 +20,12 @@ module Dato
|
|
21
20
|
def file
|
22
21
|
@file ||= if http_source?
|
23
22
|
uri = Addressable::URI.parse(source)
|
24
|
-
ext = ::File.extname(uri.path)
|
25
|
-
Tempfile.new(['file', ext])
|
26
|
-
|
27
|
-
|
23
|
+
ext = ::File.extname(uri.path).downcase
|
24
|
+
tempfile = Tempfile.new(['file', ext])
|
25
|
+
tempfile.binmode
|
26
|
+
tempfile.write(download_file(source))
|
27
|
+
tempfile.rewind
|
28
|
+
tempfile
|
28
29
|
else
|
29
30
|
::File.new(::File.expand_path(source))
|
30
31
|
end
|
@@ -67,26 +68,39 @@ module Dato
|
|
67
68
|
uploads['id']
|
68
69
|
end
|
69
70
|
|
71
|
+
def download_file(url)
|
72
|
+
connection = Faraday.new do |c|
|
73
|
+
c.response :raise_error
|
74
|
+
c.use FaradayMiddleware::FollowRedirects
|
75
|
+
c.adapter :net_http
|
76
|
+
end
|
77
|
+
connection.get(url).body
|
78
|
+
rescue Faraday::Error => e
|
79
|
+
puts "Error during uploading #{url}"
|
80
|
+
raise e
|
81
|
+
end
|
82
|
+
|
70
83
|
def format_resource(upload_request)
|
71
|
-
extension =
|
84
|
+
extension = FastImage.type(file.path).to_s
|
85
|
+
if extension.empty?
|
86
|
+
extension = ::File.extname(::File.basename(file.path)).delete('.').downcase
|
87
|
+
end
|
88
|
+
|
89
|
+
raise FastImage::UnknownImageType if extension.empty?
|
72
90
|
|
73
91
|
base_format = {
|
74
92
|
path: upload_request[:id],
|
75
93
|
size: ::File.size(file.path),
|
76
94
|
format: extension
|
77
95
|
}
|
78
|
-
|
79
96
|
if IMAGE_FORMATS.include?(extension)
|
80
97
|
width, height = FastImage.size(file.path)
|
81
|
-
|
82
|
-
base_format.merge(
|
98
|
+
base_format = base_format.merge(
|
83
99
|
width: width,
|
84
|
-
height: height
|
85
|
-
format: FastImage.type(file.path).to_s
|
100
|
+
height: height
|
86
101
|
)
|
87
|
-
else
|
88
|
-
base_format
|
89
102
|
end
|
103
|
+
base_format
|
90
104
|
end
|
91
105
|
end
|
92
106
|
end
|
data/lib/dato/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dato
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefano Verna
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -220,20 +220,6 @@ dependencies:
|
|
220
220
|
- - ">="
|
221
221
|
- !ruby/object:Gem::Version
|
222
222
|
version: '0'
|
223
|
-
- !ruby/object:Gem::Dependency
|
224
|
-
name: downloadr
|
225
|
-
requirement: !ruby/object:Gem::Requirement
|
226
|
-
requirements:
|
227
|
-
- - ">="
|
228
|
-
- !ruby/object:Gem::Version
|
229
|
-
version: '0'
|
230
|
-
type: :runtime
|
231
|
-
prerelease: false
|
232
|
-
version_requirements: !ruby/object:Gem::Requirement
|
233
|
-
requirements:
|
234
|
-
- - ">="
|
235
|
-
- !ruby/object:Gem::Version
|
236
|
-
version: '0'
|
237
223
|
- !ruby/object:Gem::Dependency
|
238
224
|
name: addressable
|
239
225
|
requirement: !ruby/object:Gem::Requirement
|