skyfall 0.2.1 → 0.2.3

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: 9a508caa504715c30f9d9ff68dbf419c8b88ad00e5fbc6315ae6a3abb624e167
4
- data.tar.gz: 9010ece05b7f1cce0a2573ecfa75965d1dba2b77cd7926eaa8fc510f8e2ae7e2
3
+ metadata.gz: 3917568c1283d599d3103b428599141e04d0df2cce33c4b17291bc935b8add4d
4
+ data.tar.gz: 329dd70a2f17bb689fa0a10c6646c7f522c1ac165b1e0ef49f96cd5b6d746d57
5
5
  SHA512:
6
- metadata.gz: b9fc0370411496e76a4caaa7b2795e999b2fbf3445e21a02e3b9135e4c7fc5e3766d7ea3a94e145becf3ab96fd4d494b0f7d8a04a09eee03698a97125d44238d
7
- data.tar.gz: b302a5f7eefc30509a6b721809105bd9439f6919b31ab73878d132fa8a67062d0d77c17d375d3d433cb77bbba63127a823d1817f5d1a71f16c2b6601dca7d493
6
+ metadata.gz: '09e6812b1234a0f7e4aeab3dee4fe962b47a781d7ddcf1151b1f310558e72837808caee9c1ca0d4e98f7e137e7147b72c8bdcd9ae17501c48f1d1dcc1a32ca35'
7
+ data.tar.gz: 5c558d41a7fc49ecc34273a791dc26a706c00708ca0b00b09a59d5bdc4684ff4f14611c065e35343f65d7989a948e5294b7c9edc55b41426f5b2eae893bea392
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## [0.2.3] - 2023-09-28
2
+
3
+ - fixed encoding of image CIDs again (they should be wrapped in a `$link` object)
4
+ - binary strings are now correctly returned as `$bytes` objects
5
+ - added `list`, `listblock` and `threadgate` to record type symbols and collection constants
6
+
7
+ ## [0.2.2] - 2023-09-06
8
+
9
+ - fixed image CIDs returned in the record JSON as CBOR tag objects (they are now returned decoded to the string form)
10
+
1
11
  ## [0.2.1] - 2023-08-19
2
12
 
3
13
  - optimized `WebsocketMessage` parsing performance - lazy parsing of most properties (message decoding should be over 50% faster on average)
@@ -2,6 +2,7 @@ require_relative 'cid'
2
2
  require_relative 'errors'
3
3
  require_relative 'extensions'
4
4
 
5
+ require 'base64'
5
6
  require 'cbor'
6
7
  require 'stringio'
7
8
 
@@ -32,11 +33,46 @@ module Skyfall
32
33
  end
33
34
 
34
35
  def section_with_cid(cid)
35
- @sections.detect { |s| s.cid == cid }&.body
36
+ section = @sections.detect { |s| s.cid == cid }
37
+ section && section.body
36
38
  end
37
39
 
38
40
  private
39
41
 
42
+ def convert_data(object)
43
+ if object.is_a?(Hash)
44
+ object.each do |k, v|
45
+ if v.is_a?(Hash) || v.is_a?(Array)
46
+ convert_data(v)
47
+ elsif v.is_a?(CBOR::Tagged)
48
+ object[k] = make_cid_link(v)
49
+ elsif v.is_a?(String) && v.encoding == Encoding::ASCII_8BIT
50
+ object[k] = make_bytes(v)
51
+ end
52
+ end
53
+ elsif object.is_a?(Array)
54
+ object.each_with_index do |v, i|
55
+ if v.is_a?(Hash) || v.is_a?(Array)
56
+ convert_data(v)
57
+ elsif v.is_a?(CBOR::Tagged)
58
+ object[i] = make_cid_link(v)
59
+ elsif v.is_a?(String) && v.encoding == Encoding::ASCII_8BIT
60
+ object[i] = make_bytes(v)
61
+ end
62
+ end
63
+ else
64
+ raise DecodeError, "Unexpected value type in record: #{object}"
65
+ end
66
+ end
67
+
68
+ def make_cid_link(cid)
69
+ { '$link' => CID.from_cbor_tag(cid) }
70
+ end
71
+
72
+ def make_bytes(data)
73
+ { '$bytes' => Base64.encode64(data).chomp.gsub(/=+$/, '') }
74
+ end
75
+
40
76
  def read_header(buffer)
41
77
  len = buffer.read_varint
42
78
 
@@ -77,6 +113,7 @@ module Skyfall
77
113
 
78
114
  body_data = sbuffer.read
79
115
  body = CBOR.decode(body_data)
116
+ convert_data(body)
80
117
 
81
118
  @sections << CarSection.new(cid, body)
82
119
  end
@@ -1,12 +1,15 @@
1
1
  module Skyfall
2
2
  module Collection
3
- BSKY_POST = "app.bsky.feed.post"
4
- BSKY_LIKE = "app.bsky.feed.like"
5
- BSKY_FOLLOW = "app.bsky.graph.follow"
6
- BSKY_REPOST = "app.bsky.feed.repost"
7
- BSKY_BLOCK = "app.bsky.graph.block"
8
- BSKY_PROFILE = "app.bsky.actor.profile"
9
- BSKY_LISTITEM = "app.bsky.graph.listitem"
10
- BSKY_FEED = "app.bsky.feed.generator"
3
+ BSKY_PROFILE = "app.bsky.actor.profile"
4
+ BSKY_FEED = "app.bsky.feed.generator"
5
+ BSKY_LIKE = "app.bsky.feed.like"
6
+ BSKY_POST = "app.bsky.feed.post"
7
+ BSKY_REPOST = "app.bsky.feed.repost"
8
+ BSKY_THREADGATE = "app.bsky.feed.threadgate"
9
+ BSKY_BLOCK = "app.bsky.graph.block"
10
+ BSKY_FOLLOW = "app.bsky.graph.follow"
11
+ BSKY_LIST = "app.bsky.graph.list"
12
+ BSKY_LISTBLOCK = "app.bsky.graph.listblock"
13
+ BSKY_LISTITEM = "app.bsky.graph.listitem"
11
14
  end
12
15
  end
@@ -41,14 +41,17 @@ module Skyfall
41
41
 
42
42
  def type
43
43
  case collection
44
- when Collection::BSKY_POST then :bsky_post
45
- when Collection::BSKY_LIKE then :bsky_like
46
- when Collection::BSKY_FOLLOW then :bsky_follow
47
- when Collection::BSKY_REPOST then :bsky_repost
48
- when Collection::BSKY_BLOCK then :bsky_block
49
- when Collection::BSKY_PROFILE then :bsky_profile
50
- when Collection::BSKY_LISTITEM then :bsky_listitem
51
- when Collection::BSKY_FEED then :bsky_feed
44
+ when Collection::BSKY_BLOCK then :bsky_block
45
+ when Collection::BSKY_FEED then :bsky_feed
46
+ when Collection::BSKY_FOLLOW then :bsky_follow
47
+ when Collection::BSKY_LIKE then :bsky_like
48
+ when Collection::BSKY_LIST then :bsky_list
49
+ when Collection::BSKY_LISTBLOCK then :bsky_listblock
50
+ when Collection::BSKY_LISTITEM then :bsky_listitem
51
+ when Collection::BSKY_POST then :bsky_post
52
+ when Collection::BSKY_PROFILE then :bsky_profile
53
+ when Collection::BSKY_REPOST then :bsky_repost
54
+ when Collection::BSKY_THREADGATE then :bsky_threadgate
52
55
  else :unknown
53
56
  end
54
57
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Skyfall
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.3"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skyfall
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kuba Suder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-19 00:00:00.000000000 Z
11
+ date: 2023-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base32