Skip to content

Commit 5885d1d

Browse files
authored
feat(deps): use html2rss in latest development status (#728)
* feat(deps): use html2rss in latest development status Signed-off-by: Gil Desmarais <[email protected]> * refactor: remove facade Refactored RSS feed handling in app.rb to eliminate the Html2rssFacade. Merged configuration directly into request handlers, simplifying the feed generation process. This change enhances performance by reducing method calls and improves readability by consolidating logic. Removed unused helper files related to the facade, cleaning up the codebase. Signed-off-by: Gil Desmarais <[email protected]> * test(auto_source): update cache-control header expectation in response test Adjusted the expected value of the cache-control header in the response test to include 'no-cache' and 'no-store'. This change ensures that the test accurately reflects the intended caching behavior for responses, improving reliability and correctness. * chore(request_path): remove unused RequestPath class and related specs This commit deletes the RequestPath class and its corresponding tests, as they are no longer needed in the application. This helps reduce code complexity and maintenance overhead. * 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]> * feat(docker): add directories for rack-cache body and meta Created /app/tmp/rack-cache-body and /app/tmp/rack-cache-meta directories in the Dockerfile to support caching functionality. * fix: references removed error class --------- Signed-off-by: Gil Desmarais <[email protected]>
1 parent c1b1d03 commit 5885d1d

16 files changed

+195
-330
lines changed

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ RUN apk add --no-cache \
5757
--no-create-home \
5858
--uid "$UID" "$USER" \
5959
&& mkdir -p /app \
60+
&& mkdir -p /app/tmp/rack-cache-body \
61+
&& mkdir -p /app/tmp/rack-cache-meta \
6062
&& chown "$USER":"$USER" -R /app
6163

6264
WORKDIR /app

Gemfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ source 'https://rubygems.org'
44

55
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
66

7-
gem 'html2rss', '~> 0.14'
7+
# gem 'html2rss', '~> 0.14'
8+
gem 'html2rss', github: 'html2rss/html2rss'
9+
810
gem 'html2rss-configs', github: 'html2rss/html2rss-configs'
911

1012
# Use these instead of the two above (uncomment them) when developing locally:

Gemfile.lock

Lines changed: 143 additions & 86 deletions
Large diffs are not rendered by default.

app.rb

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,38 @@ def self.development? = ENV['RACK_ENV'] == 'development'
8484
end
8585

8686
r.on String, String do |folder_name, config_name_with_ext|
87-
handle_html2rss_configs(request, folder_name, config_name_with_ext)
87+
response['Content-Type'] = CONTENT_TYPE_RSS
88+
89+
name = "#{folder_name}/#{File.basename(config_name_with_ext, '.*')}"
90+
config = Html2rss::Configs.find_by_name(name)
91+
92+
if (params = request.params).any?
93+
config[:params] ||= {}
94+
config[:params].merge!(params)
95+
end
96+
97+
feed = Html2rss.feed(config)
98+
99+
HttpCache.expires(response, feed.channel.ttl.to_i * 60, cache_control: 'public')
100+
101+
feed.to_s
88102
end
89103

90104
r.on String do |config_name_with_ext|
91-
handle_local_config_feeds(request, config_name_with_ext)
105+
response['Content-Type'] = CONTENT_TYPE_RSS
106+
107+
config = LocalConfig.find(File.basename(config_name_with_ext, '.*'))
108+
109+
if (params = request.params).any?
110+
config[:params] ||= {}
111+
config[:params].merge!(params)
112+
end
113+
114+
feed = Html2rss.feed(config)
115+
116+
HttpCache.expires(response, feed.channel.ttl.to_i * 60, cache_control: 'public')
117+
118+
feed.to_s
92119
end
93120
end
94121

app/html2rss_facade.rb

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

app/http_cache.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ module HttpCache
1515
# @param seconds [Integer]
1616
# @param cache_control [String, nil]
1717
def expires(response, seconds, cache_control: nil)
18+
expires_now(response) and return if seconds <= 0
19+
1820
response['Expires'] = (Time.now + seconds).httpdate
1921

2022
cache_value = "max-age=#{seconds}"

app/request_path.rb

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

app/ssrf_filter_strategy.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def execute
1616
response = SsrfFilter.get(ctx.url, headers:)
1717

1818
Html2rss::RequestService::Response.new(body: response.body,
19+
url: ctx.url,
1920
headers: response.to_hash.transform_values(&:first))
2021
end
2122
end

config/feeds.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ feeds:
1616
selector: "li > div"
1717
title:
1818
selector: "h4"
19-
link:
19+
url:
2020
selector: "a"
2121
extractor: "href"

helpers/handle_error.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@ module Web
88
class App
99
def handle_error(error) # rubocop:disable Metrics/MethodLength
1010
case error
11-
when Html2rss::Config::ParamsMissing,
11+
when Html2rss::Config::DynamicParams::ParamsMissing,
1212
Roda::RodaPlugins::TypecastParams::Error
1313
set_error_response('Parameters missing or invalid', 422)
14-
when Html2rss::AttributePostProcessors::UnknownPostProcessorName,
15-
Html2rss::ItemExtractors::UnknownExtractorName,
16-
Html2rss::Config::ChannelMissing
14+
when Html2rss::Selectors::PostProcessors::UnknownPostProcessorName
1715
set_error_response('Invalid feed config', 422)
1816
when LocalConfig::NotFound,
1917
Html2rss::Configs::ConfigNotFound

0 commit comments

Comments
 (0)