Skip to content

Commit c126faf

Browse files
committed
feat(auto_source): replace stylesheet workaround
Replaced the previous RSS construction with a new feed builder to simplify code and improve maintainability. Updated caching logic to align with the new structure, enhancing response handling for auto-source features. Signed-off-by: Gil Desmarais <[email protected]>
1 parent fb5f461 commit c126faf

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

routes/auto_source.rb

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,19 @@ class App
2121

2222
r.on String, method: :get do |encoded_url|
2323
strategy = (request.params['strategy'] || :ssrf_filter).to_sym
24-
unless Html2rss::RequestService.strategy_registered?(strategy)
25-
raise Html2rss::RequestService::UnknownStrategy
26-
end
2724

28-
response['Content-Type'] = CONTENT_TYPE_RSS
29-
30-
url = Addressable::URI.parse(Base64.urlsafe_decode64(encoded_url)).to_s
31-
rss = Html2rss.auto_source(url, strategy:)
25+
url = Addressable::URI.parse(Base64.urlsafe_decode64(encoded_url))
3226

33-
# Unfortunately, Ruby's rss gem does not provide a direct method to
34-
# add an XML stylesheet to the RSS::RSS object itself.
35-
stylesheet = Html2rss::RssBuilder::Stylesheet.new(href: '/rss.xsl', type: 'text/xsl').to_xml
27+
feed = Html2rss.feed(stylesheets: [{ href: '/rss.xsl', type: 'text/xsl' }],
28+
strategy:,
29+
channel: { url: url.to_s },
30+
auto_source: {})
3631

37-
xml_content = rss.to_xml
38-
xml_content.sub!(/^<\?xml version="1.0" encoding="UTF-8"\?>/,
39-
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n#{stylesheet}")
32+
HttpCache.expires(response, AutoSource.ttl_in_seconds(feed), cache_control: 'private, must-revalidate')
4033

41-
HttpCache.expires response,
42-
AutoSource.ttl_in_seconds(rss),
43-
cache_control: 'private, must-revalidate'
44-
45-
xml_content
34+
response['Content-Type'] = CONTENT_TYPE_RSS
35+
response.status = 200
36+
feed.to_xml
4637
end
4738
else
4839
# auto_source feature is disabled

0 commit comments

Comments
 (0)