From 632660ff2593e91db5e5cbbc19fcc3c4c32b9dd4 Mon Sep 17 00:00:00 2001 From: Kuba Suder Date: Sat, 26 Aug 2023 00:49:30 +0200 Subject: [PATCH] fixed image CIDs saved into json as CBOR tags --- lib/skyfall/car_archive.rb | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/skyfall/car_archive.rb b/lib/skyfall/car_archive.rb index e440113..d86867c 100644 --- a/lib/skyfall/car_archive.rb +++ b/lib/skyfall/car_archive.rb @@ -32,11 +32,38 @@ module Skyfall end def section_with_cid(cid) - @sections.detect { |s| s.cid == cid }&.body + section = @sections.detect { |s| s.cid == cid } + + if section + convert_cids(section.body) + section.body + end end private + def convert_cids(object) + if object.is_a?(Hash) + object.each do |k, v| + if v.is_a?(Hash) || v.is_a?(Array) + convert_cids(v) + elsif v.is_a?(CBOR::Tagged) + object[k] = CID.from_cbor_tag(v) + end + end + elsif object.is_a?(Array) + object.each_with_index do |v, i| + if v.is_a?(Hash) || v.is_a?(Array) + convert_cids(v) + elsif v.is_a?(CBOR::Tagged) + object[i] = CID.from_cbor_tag(v) + end + end + else + raise DecodeError, "Unexpected value type in record: #{object}" + end + end + def read_header(buffer) len = buffer.read_varint -- 2.51.2