wolf_core 1.0.52 → 1.0.54
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/wolf_core/utils/file_utils.rb +27 -4
- data/lib/wolf_core/utils/string_utils.rb +7 -0
- data/lib/wolf_core/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7e968199325f980d925149e08bb057acc99a855de91e17c51a4031175edf6e2
|
4
|
+
data.tar.gz: b1bdd3fdbf8894e768af16bc4613ca90637fe86c224d638be1b8e316bde5b1c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e9950b19bc35e73f4ed7809a5651b2fe5a70feb5779b7df0b5ca84fd1a766df030b0907c55c0886c73a90c0458bd57b163d89c7945db5d45e2c2b1f65792720
|
7
|
+
data.tar.gz: d23660112f62469745a533b70a885730079c243a7f5e81c5dfecacb72f54a5a549294c6e2c9a50abf67f3170ed74be4a657a180133d4c80c77c2b03b46a3d85b
|
@@ -1,8 +1,10 @@
|
|
1
|
-
require_relative "logging_utils"
|
1
|
+
require_relative "logging_utils"
|
2
|
+
require_relative "string_utils"
|
2
3
|
|
3
4
|
module WolfCore
|
4
|
-
module FileUtils
|
5
|
+
module FileUtils
|
5
6
|
extend WolfCore::LoggingUtils
|
7
|
+
extend WolfCore::StringUtils
|
6
8
|
|
7
9
|
module_function
|
8
10
|
|
@@ -88,7 +90,7 @@ module WolfCore
|
|
88
90
|
url = URI.parse("https://www.filestackapi.com/api/store/S3?key=#{api_key}")
|
89
91
|
request = Net::HTTP::Post.new(url)
|
90
92
|
request["Content-Type"] = "application/octet-stream"
|
91
|
-
request.body = file
|
93
|
+
request.body = bytes_from_file(file)
|
92
94
|
|
93
95
|
response = Net::HTTP.start(url.hostname, url.port, use_ssl: true) do |http|
|
94
96
|
http.request(request)
|
@@ -111,12 +113,33 @@ module WolfCore
|
|
111
113
|
message: "Failed to generate url from file",
|
112
114
|
url: url,
|
113
115
|
file: file,
|
114
|
-
form_data: form_data,
|
115
116
|
request: request,
|
116
117
|
response: response,
|
117
118
|
response_body: response.body,
|
118
119
|
parse_json_error: parse_json_error,
|
119
120
|
})
|
120
121
|
end
|
122
|
+
|
123
|
+
def bytes_from_file(file)
|
124
|
+
if file.is_a?(ActionDispatch::Http::UploadedFile)
|
125
|
+
file.read
|
126
|
+
elsif base64_encoded?(file)
|
127
|
+
base64_string_to_bytes(file)
|
128
|
+
else
|
129
|
+
raise_service_error({
|
130
|
+
message: "Can not generate bytes from this file",
|
131
|
+
file: file,
|
132
|
+
})
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def base64_string_to_bytes(base64_string)
|
137
|
+
begin
|
138
|
+
bytes = Base64.strict_decode64(base64_string)
|
139
|
+
bytes
|
140
|
+
rescue ArgumentError
|
141
|
+
raise_service_error({ message: 'Failed to decode base64 string', base64_string: base64_string })
|
142
|
+
end
|
143
|
+
end
|
121
144
|
end
|
122
145
|
end
|
@@ -39,5 +39,12 @@ module WolfCore
|
|
39
39
|
rescue URI::InvalidURIError
|
40
40
|
false
|
41
41
|
end
|
42
|
+
|
43
|
+
def base64_encoded?(str)
|
44
|
+
return false unless str.is_a?(String) && str.length % 4 == 0
|
45
|
+
|
46
|
+
base64_regex = /^[A-Za-z0-9+\/]+={0,2}$/
|
47
|
+
str.match?(base64_regex)
|
48
|
+
end
|
42
49
|
end
|
43
50
|
end
|
data/lib/wolf_core/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wolf_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.54
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Javier Roncallo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-12-
|
11
|
+
date: 2024-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|