wolf_core 1.0.52 → 1.0.53

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7c1e7e387b6115905bde116bf41eacd035566117c54984cc75107d54a5546524
4
- data.tar.gz: e35f0fa19d1085304258c79eb4d2df57fcbdcfc84b37f525dbf4c2eeb4df30f4
3
+ metadata.gz: c18b0fcfb7ec3e6a05a8bdb147c43414754460c7e2c0d8f4023c2bb915847275
4
+ data.tar.gz: af53acdd4f7fbe265515c04398d95ff88c807f99586e6578724cdd121a32dddf
5
5
  SHA512:
6
- metadata.gz: 1ff850507b14dbae591f32321e88ccea87fbd59cc541ba5a38139eae99719daebdce8f8f9f3f3f929297abb2df3a1d8f8567af5db3930ea1b6bade4dad8b314d
7
- data.tar.gz: c6721e184873ad8c2eb15bcd8279b8e564eddf317b9b73402dd25361b3334361274f35318cc3b00a9ce9c2c842a98e95a1e0e78c8a32a58ed06a9c4d80aabb32
6
+ metadata.gz: 4c87bca3e3d0ad50d5abc09bf8a368b63469bc6d37632c2bcff5d98de43c6089919db1886aa72c8c2d73796dab0d235f549ffa6e194af007369c0ce0321c14ed
7
+ data.tar.gz: b2aca4b3223a0b596d02ac3b33461cc3cc68a6ac5af86501c6e29a7a76689d022c2296fe34b940b1c99bba61d6845f2363497e7e880c54c9ad9e552433d391f4
@@ -1,8 +1,10 @@
1
- require_relative "logging_utils" # rubocop:disable Style/FrozenStringLiteralComment
1
+ require_relative "logging_utils"
2
+ require_relative "string_utils"
2
3
 
3
4
  module WolfCore
4
- module FileUtils # rubocop:disable Style/Documentation
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.read
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.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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WolfCore
4
- VERSION = "1.0.52"
4
+ VERSION = "1.0.53"
5
5
  end
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.52
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-24 00:00:00.000000000 Z
11
+ date: 2024-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty