Skip to content

Commit 3ccbe11

Browse files
committed
fix: align defaults and utility links
1 parent 381c44c commit 3ccbe11

9 files changed

Lines changed: 60 additions & 10 deletions

File tree

app/web/config/local_config.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class NotFound < RuntimeError; end
2222
# raised when the local config shape is invalid
2323
class InvalidConfig < RuntimeError; end
2424
FEED_EXTENSION_PATTERN = /\.(json|rss|xml)\z/
25+
EMBEDDED_FEED_NAME_PATTERN = %r{\A[^/]+/.+\z}
2526

2627
# Path to local feed configuration file.
2728
CONFIG_FILE = 'config/feeds.yml'
@@ -92,15 +93,11 @@ def local_feed_config(normalized_name)
9293
# @return [Hash{Symbol=>Object}, nil]
9394
def embedded_feed_config(normalized_name)
9495
return nil unless defined?(Html2rss::Configs)
95-
return nil unless normalized_name.include?('/')
96+
return nil unless normalized_name.match?(EMBEDDED_FEED_NAME_PATTERN)
9697

9798
deep_dup(Html2rss::Configs.find_by_name(normalized_name))
9899
rescue Html2rss::Configs::ConfigNotFound
99100
nil
100-
rescue RuntimeError => error
101-
return nil if error.message == 'name must be in folder/file format'
102-
103-
raise
104101
end
105102

106103
# Applies global defaults only when feed-level keys are absent.

app/web/domain/auto_source.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def enabled?
2121
# @param token_data [Hash{Symbol=>Object}] authenticated account data.
2222
# @param strategy [String]
2323
# @return [Html2rss::Web::Api::V1::FeedMetadata::Metadata, nil]
24-
def create_stable_feed(name, url, token_data, strategy = 'faraday')
24+
def create_stable_feed(name, url, token_data, strategy = Html2rss::RequestService.default_strategy_name.to_s)
2525
return nil unless token_data && FeedAccess.url_allowed_for_username?(token_data[:username], url)
2626

2727
feed_token = Auth.generate_feed_token(token_data[:username], url, strategy: strategy)

app/web/feeds/source_resolver.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def static_cache_identity(feed_name, params)
7171
def static_generator_input(config, params)
7272
generator_input = config.dup
7373
generator_input[:params] = merged_static_params(config, params)
74-
generator_input[:strategy] ||= :faraday
74+
generator_input[:strategy] ||= Html2rss::RequestService.default_strategy_name.to_sym
7575
generator_input
7676
end
7777

frontend/src/__tests__/App.test.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,4 +368,19 @@ describe('App', () => {
368368
expect(bookmarklet.getAttribute('href')).toContain('/?url=');
369369
expect(bookmarklet.getAttribute('href')).not.toContain('%27+encodeURIComponent');
370370
});
371+
372+
it('shows the OpenAPI spec and included-config links in the more menu', () => {
373+
render(<App />);
374+
375+
fireEvent.click(screen.getByRole('button', { name: 'More' }));
376+
377+
expect(screen.getByRole('link', { name: 'OpenAPI spec' })).toHaveAttribute(
378+
'href',
379+
'http://example.test/openapi.yaml'
380+
);
381+
expect(screen.getByRole('link', { name: 'Included configs' })).toHaveAttribute(
382+
'href',
383+
'https://html2rss.github.io/web-application/how-to/use-included-configs/'
384+
);
385+
});
371386
});

frontend/src/components/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ export function App() {
259259
<UtilityStrip
260260
hidden={showTokenPrompt}
261261
hasAccessToken={hasToken}
262+
openapiUrl={metadata?.api.openapi_url ?? null}
262263
onClearToken={() => {
263264
clearToken();
264265
setShowTokenPrompt(false);

frontend/src/components/AppPanels.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,16 @@ export function CreateFeedPanel({
244244
interface UtilityStripProps {
245245
hidden?: boolean;
246246
hasAccessToken: boolean;
247+
openapiUrl: string | null;
247248
onClearToken: () => void;
248249
}
249250

250-
export function UtilityStrip({ hidden = false, hasAccessToken, onClearToken }: UtilityStripProps) {
251+
export function UtilityStrip({
252+
hidden = false,
253+
hasAccessToken,
254+
openapiUrl,
255+
onClearToken,
256+
}: UtilityStripProps) {
251257
const [isOpen, setIsOpen] = useState(false);
252258

253259
if (hidden) return null;
@@ -265,6 +271,19 @@ export function UtilityStrip({ hidden = false, hasAccessToken, onClearToken }: U
265271
{isOpen && (
266272
<div class="utility-strip__items">
267273
<Bookmarklet />
274+
{openapiUrl && (
275+
<a href={openapiUrl} target="_blank" rel="noopener noreferrer" class="utility-link">
276+
OpenAPI spec
277+
</a>
278+
)}
279+
<a
280+
href="https://html2rss.github.io/web-application/how-to/use-included-configs/"
281+
target="_blank"
282+
rel="noopener noreferrer"
283+
class="utility-link"
284+
>
285+
Included configs
286+
</a>
268287
<a
269288
href="https://github.com/html2rss/html2rss-web"
270289
target="_blank"

spec/html2rss/web/boot/setup_spec.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
require 'spec_helper'
44

5-
require_relative '../../../../app'
5+
require_relative '../../../../app/web/boot'
6+
7+
Html2rss::Web::Boot.setup!
8+
require_relative '../../../../app/web/boot/setup'
69

710
RSpec.describe Html2rss::Web::Boot::Setup do
811
describe '.call!' do

spec/html2rss/web/feeds/source_resolver_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def resolved_tuple(resolved)
2929

3030
before do
3131
allow(Html2rss::Web::LocalConfig).to receive(:find).with('legacy').and_return(config)
32+
allow(Html2rss::RequestService).to receive(:default_strategy_name).and_return(:browserless)
3233
end
3334

3435
it 'normalizes the static source into shared generator input', :aggregate_failures do
@@ -39,7 +40,7 @@ def resolved_tuple(resolved)
3940
:static,
4041
start_with('static:legacy:'),
4142
900,
42-
include(params: { 'existing' => '1', 'page' => '3' }, strategy: :faraday)
43+
include(params: { 'existing' => '1', 'page' => '3' }, strategy: :browserless)
4344
]
4445
)
4546
end

spec/html2rss/web/local_config_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ def self.find_by_name(_name); end
3838

3939
expect(config).to include(channel: { title: 'Apple security releases' })
4040
end
41+
42+
it 'returns not found for malformed embedded config paths instead of depending on gem error messages' do
43+
stub_const('Html2rss::Configs', Module.new do
44+
def self.find_by_name(_name); end
45+
end)
46+
stub_const('Html2rss::Configs::ConfigNotFound', Class.new(StandardError))
47+
allow(Html2rss::Configs).to receive(:find_by_name)
48+
allow(described_class).to receive(:snapshot)
49+
.and_return(Html2rss::Web::ConfigSnapshot::Snapshot.new(global: {}, feeds: {}, accounts: []))
50+
51+
expect { described_class.find('/broken-name.rss') }
52+
.to raise_error(described_class::NotFound, "Did not find local feed config at 'broken-name'")
53+
expect(Html2rss::Configs).not_to have_received(:find_by_name)
54+
end
4155
end
4256

4357
describe '.snapshot' do

0 commit comments

Comments
 (0)