Skip to content

Commit de0e657

Browse files
committed
refactor: group web code by concern
1 parent 6c4ca54 commit de0e657

47 files changed

Lines changed: 225 additions & 196 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/web/api/v1/feed_metadata.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,49 @@ def site_title_for(url)
1717
rescue StandardError
1818
nil
1919
end
20+
21+
# @param attributes [Hash{Symbol=>Object}]
22+
# @return [Html2rss::Web::Api::V1::FeedMetadata::Metadata]
23+
def build(attributes)
24+
Metadata.new(**metadata_attributes(attributes))
25+
end
26+
27+
private
28+
29+
# @param attributes [Hash{Symbol=>Object}]
30+
# @return [Hash{Symbol=>Object}]
31+
def metadata_attributes(attributes)
32+
{
33+
id: stable_id(attributes[:username], attributes[:url], attributes[:identity_token]),
34+
name: attributes[:name],
35+
url: attributes[:url],
36+
username: attributes[:username],
37+
strategy: attributes[:strategy],
38+
feed_token: attributes[:feed_token],
39+
public_url: public_url(attributes[:feed_token]),
40+
json_public_url: json_public_url(attributes[:feed_token])
41+
}
42+
end
43+
44+
# @param username [String]
45+
# @param url [String]
46+
# @param token [String]
47+
# @return [String]
48+
def stable_id(username, url, token)
49+
Digest::SHA256.hexdigest("#{username}:#{url}:#{token}")[0..15]
50+
end
51+
52+
# @param feed_token [String]
53+
# @return [String]
54+
def public_url(feed_token)
55+
"/api/v1/feeds/#{feed_token}"
56+
end
57+
58+
# @param feed_token [String]
59+
# @return [String]
60+
def json_public_url(feed_token)
61+
"#{public_url(feed_token)}.json"
62+
end
2063
end
2164

2265
##

app/web/boot.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,17 @@ def build_loader
5555
# @return [void]
5656
def configure_loader(new_loader)
5757
new_loader.push_dir(app_root, namespace: Html2rss)
58+
collapsed_web_dirs.each { |path| new_loader.collapse(path) }
5859
new_loader.inflector.inflect('api_v1' => 'ApiV1')
5960
end
6061

62+
# @return [Array<String>]
63+
def collapsed_web_dirs
64+
%w[config domain errors http rendering request security telemetry].map do |dir|
65+
File.join(app_root, 'web', dir)
66+
end
67+
end
68+
6169
##
6270
# Returns the application directory that maps to the Html2rss root
6371
# namespace.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def create_stable_feed(name, url, token_data, strategy = 'ssrf_filter')
2727
feed_token = Auth.generate_feed_token(token_data[:username], url, strategy: strategy)
2828
return nil unless feed_token
2929

30-
FeedIdentity.metadata(metadata_attributes(name, url, token_data, strategy, feed_token))
30+
Api::V1::FeedMetadata.build(metadata_attributes(name, url, token_data, strategy, feed_token))
3131
end
3232

3333
private

0 commit comments

Comments
 (0)