File tree Expand file tree Collapse file tree 6 files changed +209
-89
lines changed
Expand file tree Collapse file tree 6 files changed +209
-89
lines changed Original file line number Diff line number Diff line change @@ -68,8 +68,6 @@ gem "awesome_print", "~> 1.9"
6868
6969gem "redis" , "~> 5.0"
7070
71- gem 'facet_rails_common' , git : 'https://github.com/0xfacet/facet_rails_common.git'
72-
7371gem "cbor" , "~> 0.5.9"
7472
7573gem 'rswag-api'
Original file line number Diff line number Diff line change 11GIT
22 remote: https://github.com/0xFacet/eth.rb.git
3- revision: da52c74fe9baecf17177f6b5bfee9f42c1b18970
3+ revision: 089128a7703aa5eeafe41d538f05732b29340188
44 branch: sync/v0.5.16-nohex
55 specs:
66 eth (0.5.16 )
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-
2417GEM
2518 remote: https://rubygems.org/
2619 specs:
10598 awesome_print (1.9.2 )
10699 base64 (0.2.0 )
107100 benchmark (0.4.1 )
108- bigdecimal (3.1.5 )
101+ bigdecimal (3.2.3 )
109102 bls12-381 (0.3.0 )
110103 h2c (~> 0.2.0 )
111104 bootsnap (1.17.0 )
157150 csv
158151 mini_mime (>= 1.0.0 )
159152 multi_xml (>= 0.5.2 )
160- httpx (1.6.0 )
153+ httpx (1.6.2 )
161154 http-2 (>= 1.0.0 )
162155 i18n (1.14.1 )
163156 concurrent-ruby (~> 1.0 )
223216 bigdecimal (>= 3.0 )
224217 ostruct (>= 0.2 )
225218 openssl (3.3.0 )
226- order_query (0.5.5 )
227- activerecord (>= 5.0 , < 8.1 )
228- activesupport (>= 5.0 , < 8.1 )
229219 ostruct (0.6.3 )
230220 parallel (1.27.0 )
231221 parser (3.2.2.4 )
285275 rake (>= 12.2 )
286276 thor (~> 1.0 , >= 1.2.2 )
287277 zeitwerk (~> 2.6 )
288- rake (13.1 .0 )
278+ rake (13.3 .0 )
289279 rbi (0.3.6 )
290280 prism (~> 1.0 )
291281 rbs (>= 3.4.4 )
@@ -416,7 +406,6 @@ DEPENDENCIES
416406 debug
417407 dotenv-rails (~> 2.8 )
418408 eth !
419- facet_rails_common !
420409 fastlz (~> 0.1.0 )
421410 httparty (~> 0.22.0 )
422411 jwt (~> 2.8 )
Original file line number Diff line number Diff line change 11class ApplicationController < ActionController ::API
2- include FacetRailsCommon ::ApplicationControllerMethods
2+ def self . cache_actions_on_block ( ...)
3+ end
34end
Original file line number Diff line number Diff line change @@ -19,20 +19,24 @@ def self.extract(content_uri)
1919
2020 # Try extractors in order of strictness
2121 # 1. Token protocol (most strict - exact character position matters)
22- # 2. Collections protocol (strict - exact key order required)
23- # 3. Generic protocol (flexible - for all other protocols)
22+ # 2. Collections protocol (strict - exact key order required) - gated by ENABLE_COLLECTIONS
23+ # 3. Generic protocol (flexible - for all other protocols) - gated by ENABLE_GENERIC_PROTOCOLS
2424
2525 # Try token extractor first (most strict)
2626 result = try_token_extractor ( content_uri )
2727 return result if result
2828
29- # Try collections extractor next
30- result = try_collections_extractor ( content_uri )
31- return result if result
29+ # Try collections extractor next (if enabled)
30+ if ENV [ 'ENABLE_COLLECTIONS' ] == 'true'
31+ result = try_collections_extractor ( content_uri )
32+ return result if result
33+ end
3234
33- # Try generic extractor last (most flexible)
34- # result = try_generic_extractor(content_uri)
35- # return result if result
35+ # Try generic extractor last (if enabled)
36+ if ENV [ 'ENABLE_GENERIC_PROTOCOLS' ] == 'true'
37+ result = try_generic_extractor ( content_uri )
38+ return result if result
39+ end
3640
3741 # No protocol could be extracted
3842 nil
Original file line number Diff line number Diff line change 1+ class DataUri
2+ REGEXP = %r{
3+ \A data:
4+ (?<mediatype>
5+ (?<mimetype> .+? / .+? )?
6+ (?<parameters> (?: ; .+? = .+? )* )
7+ )?
8+ (?<extension>;base64)?
9+ ,
10+ (?<data>.*)
11+ }x . freeze
12+
13+ attr_reader :uri , :match
14+
15+ def initialize ( uri )
16+ match = REGEXP . match ( uri )
17+ raise ArgumentError , 'invalid data URI' unless match
18+
19+ @uri = uri
20+ @match = match
21+
22+ validate_base64_content
23+ end
24+
25+ def self . valid? ( uri )
26+ begin
27+ DataUri . new ( uri )
28+ true
29+ rescue ArgumentError
30+ false
31+ end
32+ end
33+
34+ def self . esip6? ( uri )
35+ begin
36+ parameters = DataUri . new ( uri ) . parameters
37+
38+ parameters . include? ( "rule=esip6" )
39+ rescue ArgumentError
40+ false
41+ end
42+ end
43+
44+ def validate_base64_content
45+ if base64?
46+ begin
47+ Base64 . strict_decode64 ( data )
48+ rescue ArgumentError
49+ raise ArgumentError , 'malformed base64 content'
50+ end
51+ end
52+ end
53+
54+ def mediatype
55+ "#{ mimetype } #{ parameters } "
56+ end
57+
58+ def decoded_data
59+ return data unless base64?
60+
61+ Base64 . decode64 ( data )
62+ end
63+
64+ def base64?
65+ !String ( extension ) . empty?
66+ end
67+
68+ def mimetype
69+ if String ( match [ :mimetype ] ) . empty? || uri . starts_with? ( "data:," )
70+ return 'text/plain'
71+ end
72+
73+ match [ :mimetype ]
74+ end
75+
76+ def data
77+ # Special case: if it's "data:," with no mediatype, return everything after comma
78+ if uri . start_with? ( "data:," )
79+ return uri [ 6 ..-1 ] # Everything after "data:,"
80+ end
81+ match [ :data ]
82+ end
83+
84+ def parameters
85+ return [ ] if String ( match [ :mimetype ] ) . empty? && String ( match [ :parameters ] ) . empty?
86+
87+ match [ :parameters ] . split ( ";" ) . reject ( &:empty? )
88+ end
89+
90+ def extension
91+ match [ :extension ]
92+ end
93+ end
You can’t perform that action at this time.
0 commit comments