Skip to content

Commit 3922db3

Browse files
committed
Simplify
1 parent 19f33c6 commit 3922db3

File tree

5 files changed

+25
-98
lines changed

5 files changed

+25
-98
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ gem "memoist", "~> 0.16.2"
6565

6666
gem "awesome_print", "~> 1.9"
6767

68+
gem 'facet_rails_common', git: 'https://github.com/0xfacet/facet_rails_common.git'
6869

6970
gem "redis", "~> 5.0"
7071

Gemfile.lock

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ GIT
1414
rbsecp256k1 (~> 6.0)
1515
scrypt (~> 3.0)
1616

17+
GIT
18+
remote: https://github.com/0xfacet/facet_rails_common.git
19+
revision: 2d5cf107df9ea12bb7ab59a8b1ce4d38b4de483b
20+
specs:
21+
facet_rails_common (0.1.0)
22+
order_query (~> 0.5.3)
23+
1724
GEM
1825
remote: https://rubygems.org/
1926
specs:
@@ -216,6 +223,9 @@ GEM
216223
bigdecimal (>= 3.0)
217224
ostruct (>= 0.2)
218225
openssl (3.3.0)
226+
order_query (0.5.5)
227+
activerecord (>= 5.0, < 8.1)
228+
activesupport (>= 5.0, < 8.1)
219229
ostruct (0.6.3)
220230
parallel (1.27.0)
221231
parser (3.2.2.4)
@@ -406,6 +416,7 @@ DEPENDENCIES
406416
debug
407417
dotenv-rails (~> 2.8)
408418
eth!
419+
facet_rails_common!
409420
fastlz (~> 0.1.0)
410421
httparty (~> 0.22.0)
411422
jwt (~> 2.8)

app/models/collections_params_extractor.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,12 @@ def extract(content_uri)
101101
begin
102102
# Parse JSON (preserves key order)
103103
# Use DataUri to correctly handle optional parameters like ESIP6
104-
json_str = DataUri.new(content_uri).decoded_data
104+
json_str = if content_uri.start_with?("data:,{")
105+
content_uri.sub(/\Adata:,/, '')
106+
else
107+
DataUri.new(content_uri).decoded_data
108+
end
109+
105110
# TODO: make sure this is safe
106111
data = JSON.parse(json_str)
107112

app/models/generic_protocol_extractor.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ def extract(content_uri)
2626
return DEFAULT_PARAMS unless valid_data_uri?(content_uri)
2727
begin
2828
# Extract JSON from data URI using DataUri to support optional params (e.g., ESIP6)
29-
json_str = DataUri.new(content_uri).decoded_data
30-
29+
json_str = if content_uri.start_with?("data:,{")
30+
content_uri.sub(/\Adata:,/, '')
31+
else
32+
DataUri.new(content_uri).decoded_data
33+
end
3134
# Parse with security checks
3235
data = parse_json_safely(json_str)
3336

@@ -57,6 +60,8 @@ def valid_data_uri?(uri)
5760
return false unless uri.is_a?(String)
5861
return false unless DataUri.valid?(uri)
5962

63+
return true if uri.start_with?("data:,{")
64+
6065
# Ensure the payload is JSON (starts with '{')
6166
begin
6267
payload = DataUri.new(uri).decoded_data

lib/data_uri.rb

Lines changed: 0 additions & 95 deletions
This file was deleted.

0 commit comments

Comments
 (0)