Remove unnecessary code

This commit is contained in:
Alex Kotov 2024-02-22 06:39:57 +04:00
parent 3755b56cb6
commit 55e362b812
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08

View file

@ -19,8 +19,6 @@ module Diversipub
private
# rubocop:disable Metrics/MethodLength
def builder
@builder ||= Rack::Builder.new.tap do |builder|
builder.use Rack::Head
@ -28,16 +26,11 @@ module Diversipub
builder.use Rack::ShowStatus
builder.use Rack::ContentLength
builder.use Rack::Protection, except: %i[session_hijacking]
builder.map '/.well-known/webfinger' do
run Webfinger.new
end
builder.use Rack::Static, **rack_static_kwargs
builder.run rest
end
end
# rubocop:enable Metrics/MethodLength
def rack_static_kwargs
@rack_static_kwargs ||= {
cascade: true,
@ -50,57 +43,5 @@ module Diversipub
def rest
@rest ||= ->(_) { [200, {}, ['Hello, World!']] }
end
##
# Webfinger endpoint.
#
class Webfinger
JRD_JSON = 'application/jrd+json'
ACCT_RU = 'acct:ru@causa-arcana.com'
ACCT_EN = 'acct:en@causa-arcana.com'
def call(env)
request = Rack::Request.new env
resource = request.params['resource']
data =
case resource
when ACCT_RU then build_data :ru
when ACCT_EN then build_data :en
else
raise 'Unknown resource'
end
[
200,
{
Rack::CONTENT_TYPE => JRD_JSON,
},
[
data.to_json,
],
]
end
def build_data(name)
{
subject: "acct:#{name}@causa-arcana.com",
aliases: [].freeze,
links: [
{
rel: 'http://webfinger.net/rel/profile-page',
type: 'text/html',
href: "https://causa-arcana.com/#{name}/blog/feed.html",
},
{
rel: 'http://webfinger.net/rel/profile-page',
type: 'text/gemini; charset=utf-8',
href: "gemini://causa-arcana.com/#{name}/blog/feed.gmi",
},
].freeze,
}.freeze
end
end
end
end