wolf_core 1.0.51 → 1.0.53
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 +44 -11
- 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: c18b0fcfb7ec3e6a05a8bdb147c43414754460c7e2c0d8f4023c2bb915847275
|
4
|
+
data.tar.gz: af53acdd4f7fbe265515c04398d95ff88c807f99586e6578724cdd121a32dddf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c87bca3e3d0ad50d5abc09bf8a368b63469bc6d37632c2bcff5d98de43c6089919db1886aa72c8c2d73796dab0d235f549ffa6e194af007369c0ce0321c14ed
|
7
|
+
data.tar.gz: b2aca4b3223a0b596d02ac3b33461cc3cc68a6ac5af86501c6e29a7a76689d022c2296fe34b940b1c99bba61d6845f2363497e7e880c54c9ad9e552433d391f4
|
@@ -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
|
|
@@ -85,28 +87,59 @@ module WolfCore
|
|
85
87
|
end
|
86
88
|
|
87
89
|
def generate_url_from_file(file:, api_key:)
|
88
|
-
url = URI.parse("https://
|
89
|
-
form_data = [
|
90
|
-
['file', file.tempfile, file.original_filename]
|
91
|
-
]
|
92
|
-
|
90
|
+
url = URI.parse("https://www.filestackapi.com/api/store/S3?key=#{api_key}")
|
93
91
|
request = Net::HTTP::Post.new(url)
|
94
|
-
request
|
92
|
+
request["Content-Type"] = "application/octet-stream"
|
93
|
+
request.body = bytes_from_file(file)
|
95
94
|
|
96
95
|
response = Net::HTTP.start(url.hostname, url.port, use_ssl: true) do |http|
|
97
96
|
http.request(request)
|
98
97
|
end
|
99
98
|
|
100
|
-
|
99
|
+
parse_json_error = nil
|
100
|
+
if response.is_a?(Net::HTTPSuccess)
|
101
|
+
begin
|
102
|
+
response_body = JSON.parse(response.body)
|
103
|
+
rescue => e
|
104
|
+
parse_json_error = {
|
105
|
+
message: e.message,
|
106
|
+
backtrace: e.backtrace,
|
107
|
+
}
|
108
|
+
end
|
109
|
+
return response_body['url'] if response_body['url'].present?
|
110
|
+
end
|
101
111
|
|
102
112
|
raise_service_error({
|
103
113
|
message: "Failed to generate url from file",
|
104
114
|
url: url,
|
105
115
|
file: file,
|
106
|
-
form_data: form_data,
|
107
116
|
request: request,
|
108
|
-
response: response
|
117
|
+
response: response,
|
118
|
+
response_body: response.body,
|
119
|
+
parse_json_error: parse_json_error,
|
109
120
|
})
|
110
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.bytes
|
140
|
+
rescue ArgumentError
|
141
|
+
raise_service_error({ message: 'Failed to decode base64 string', base64_string: base64_string })
|
142
|
+
end
|
143
|
+
end
|
111
144
|
end
|
112
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.53
|
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
|