Remove rabl dependency (#5894)
* Remove rabl dependency * Replicate old Oj configuration
This commit is contained in:
committed by
Yamagishi Kazutoshi
parent
0393a64a90
commit
42bcbd36b7
@ -6,12 +6,10 @@ module WellKnown
|
||||
|
||||
def show
|
||||
@account = Account.find_local!(username_from_resource)
|
||||
@canonical_account_uri = @account.to_webfinger_s
|
||||
@magic_key = pem_to_magic_key(@account.keypair.public_key)
|
||||
|
||||
respond_to do |format|
|
||||
format.any(:json, :html) do
|
||||
render formats: :json, content_type: 'application/jrd+json'
|
||||
render json: @account, serializer: WebfingerSerializer, content_type: 'application/jrd+json'
|
||||
end
|
||||
|
||||
format.xml do
|
||||
@ -35,21 +33,6 @@ module WellKnown
|
||||
WebfingerResource.new(resource_user).username
|
||||
end
|
||||
|
||||
def pem_to_magic_key(public_key)
|
||||
modulus, exponent = [public_key.n, public_key.e].map do |component|
|
||||
result = []
|
||||
|
||||
until component.zero?
|
||||
result << [component % 256].pack('C')
|
||||
component >>= 8
|
||||
end
|
||||
|
||||
result.reverse.join
|
||||
end
|
||||
|
||||
(['RSA'] + [modulus, exponent].map { |n| Base64.urlsafe_encode64(n) }).join('.')
|
||||
end
|
||||
|
||||
def resource_param
|
||||
params.require(:resource)
|
||||
end
|
||||
|
@ -184,6 +184,21 @@ class Account < ApplicationRecord
|
||||
@keypair ||= OpenSSL::PKey::RSA.new(private_key || public_key)
|
||||
end
|
||||
|
||||
def magic_key
|
||||
modulus, exponent = [keypair.public_key.n, keypair.public_key.e].map do |component|
|
||||
result = []
|
||||
|
||||
until component.zero?
|
||||
result << [component % 256].pack('C')
|
||||
component >>= 8
|
||||
end
|
||||
|
||||
result.reverse.join
|
||||
end
|
||||
|
||||
(['RSA'] + [modulus, exponent].map { |n| Base64.urlsafe_encode64(n) }).join('.')
|
||||
end
|
||||
|
||||
def subscription(webhook_url)
|
||||
@subscription ||= OStatus2::Subscription.new(remote_url, secret: secret, webhook: webhook_url, hub: hub_url)
|
||||
end
|
||||
|
26
app/serializers/webfinger_serializer.rb
Normal file
26
app/serializers/webfinger_serializer.rb
Normal file
@ -0,0 +1,26 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class WebfingerSerializer < ActiveModel::Serializer
|
||||
include RoutingHelper
|
||||
|
||||
attributes :subject, :aliases, :links
|
||||
|
||||
def subject
|
||||
object.to_webfinger_s
|
||||
end
|
||||
|
||||
def aliases
|
||||
[short_account_url(object), account_url(object)]
|
||||
end
|
||||
|
||||
def links
|
||||
[
|
||||
{ rel: 'http://webfinger.net/rel/profile-page', type: 'text/html', href: short_account_url(object) },
|
||||
{ rel: 'http://schemas.google.com/g/2010#updates-from', type: 'application/atom+xml', href: account_url(object, format: 'atom') },
|
||||
{ rel: 'self', type: 'application/activity+json', href: account_url(object) },
|
||||
{ rel: 'salmon', href: api_salmon_url(object.id) },
|
||||
{ rel: 'magic-public-key', href: "data:application/magic-public-key,#{object.magic_key}" },
|
||||
{ rel: 'http://ostatus.org/schema/1.0/subscribe', template: "#{authorize_follow_url}?acct={uri}" },
|
||||
]
|
||||
end
|
||||
end
|
@ -1,18 +0,0 @@
|
||||
object @account
|
||||
|
||||
node(:subject) { @canonical_account_uri }
|
||||
|
||||
node(:aliases) do
|
||||
[short_account_url(@account), account_url(@account)]
|
||||
end
|
||||
|
||||
node(:links) do
|
||||
[
|
||||
{ rel: 'http://webfinger.net/rel/profile-page', type: 'text/html', href: short_account_url(@account) },
|
||||
{ rel: 'http://schemas.google.com/g/2010#updates-from', type: 'application/atom+xml', href: account_url(@account, format: 'atom') },
|
||||
{ rel: 'self', type: 'application/activity+json', href: account_url(@account) },
|
||||
{ rel: 'salmon', href: api_salmon_url(@account.id) },
|
||||
{ rel: 'magic-public-key', href: "data:application/magic-public-key,#{@magic_key}" },
|
||||
{ rel: 'http://ostatus.org/schema/1.0/subscribe', template: "#{authorize_follow_url}?acct={uri}" },
|
||||
]
|
||||
end
|
@ -1,13 +1,13 @@
|
||||
Nokogiri::XML::Builder.new do |xml|
|
||||
xml.XRD(xmlns: 'http://docs.oasis-open.org/ns/xri/xrd-1.0') do
|
||||
xml.Subject @canonical_account_uri
|
||||
xml.Subject @account.to_webfinger_s
|
||||
xml.Alias short_account_url(@account)
|
||||
xml.Alias account_url(@account)
|
||||
xml.Link(rel: 'http://webfinger.net/rel/profile-page', type: 'text/html', href: short_account_url(@account))
|
||||
xml.Link(rel: 'http://schemas.google.com/g/2010#updates-from', type: 'application/atom+xml', href: account_url(@account, format: 'atom'))
|
||||
xml.Link(rel: 'self', type: 'application/activity+json', href: account_url(@account))
|
||||
xml.Link(rel: 'salmon', href: api_salmon_url(@account.id))
|
||||
xml.Link(rel: 'magic-public-key', href: "data:application/magic-public-key,#{@magic_key}")
|
||||
xml.Link(rel: 'magic-public-key', href: "data:application/magic-public-key,#{@account.magic_key}")
|
||||
xml.Link(rel: 'http://ostatus.org/schema/1.0/subscribe', template: "#{authorize_follow_url}?acct={uri}")
|
||||
end
|
||||
end.to_xml
|
||||
|
Reference in New Issue
Block a user