jieshun-parking 0.6.0 → 0.6.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7affdd12e82772721285b712751dba4b980cb3a81d5cecce5cabdefdae90f173
4
- data.tar.gz: b165205b7afd678bb3bc322dfc66c41ce3e8ef2d33235fffc9a9ad63039b7698
3
+ metadata.gz: ae1b05c5df13925f6987df22d4586859d7887d8cf9dbc4ce17c6c2c008994d14
4
+ data.tar.gz: 21074f7efc9c3e4c0addd8715df66757ed1772cd551726553ef5cbb2f65c2084
5
5
  SHA512:
6
- metadata.gz: 7413aa9df7e55f9e5f7960c11941be91caafc49240bcd9f80bcfd011e7e69580f53e037f7c500c5eccfd4127c4823cb74d28c75bfdbe8d2ac826f82236201d7e
7
- data.tar.gz: c400cea30d101b5ec74a99066827e119fa445155d1a5222ce6752451d59c925e82c7af3157114d741780c9a0145c189a04316424eb4e5ae553a44aa2d9b9a2e7
6
+ metadata.gz: c36c19dc3179417597d1c7386d45e92e9423e42fcfa1f5d6a9972cdb50c1ea6197f05b49f12bbe90a9bdeabdaa44c4ba8110393fe2dae4e0fd2b81b5c8bc83bb
7
+ data.tar.gz: 486cafe53c34bd9003c4cbadb32057060cca63a64ee37f3e0aec8491e298c1314b086d39bfdaf869b4199dfcddff06ee78e3b8f712708b9e119aef136dde19f3
@@ -34,10 +34,25 @@ module Jieshun
34
34
  data_items = []
35
35
  data_items << { filePath: file_path }
36
36
  unify_call("/api/pic/picSearch", data_items.to_json) do |result|
37
- yield(result)
37
+ image = result.body['dataItems'].first['image']
38
+ mime_type = detect_mime_type(image)
39
+ yield( { mime_type_prefix: "data:#{mime_type};base64,", content: image } )
38
40
  end
39
41
  end
40
42
 
43
+ def detect_mime_type(base64_content)
44
+ return "application/pdf" if content_matches?(base64_content, ['JVBERi0'])
45
+ return "image/gif" if content_matches?(base64_content, ['R0lGODdh', 'R0lGODlh'])
46
+ return "image/png" if content_matches?(base64_content, ['iVBORw0KGgo'])
47
+ return "image/jpg" if content_matches?(base64_content, ['/9j/'])
48
+ return "image/bmp" if content_matches?(base64_content, ['Qk'])
49
+ "application/octet-stream"
50
+ end
51
+
52
+ def content_matches?(base64_content, prefixes)
53
+ prefixes.any? { |prefix| base64_content.start_with?(prefix) }
54
+ end
55
+
41
56
  def unify_call(api_path, data_items)
42
57
  login_if_required do |auth_token|
43
58
  ts = Time.now.strftime("%Y%m%d%H%M%S%L")
@@ -51,7 +51,7 @@ module Jieshun
51
51
  unless result_code.zero?
52
52
  message = "Got invalid result code jieshun resultCode: #{result_code}, message: #{json['message']}"
53
53
  Jieshun::Parking.logger.error(message)
54
- raise RuntimeError.new(message)
54
+ raise RuntimeError.new(json['message'])
55
55
  end
56
56
 
57
57
  result = Jieshun::Parking::Result.new(successful, json.to_hash)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jieshun
4
4
  module Parking
5
- VERSION = "0.6.0"
5
+ VERSION = "0.6.2"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jieshun-parking
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - LCola
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-19 00:00:00.000000000 Z
11
+ date: 2023-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport