add fetch controller
This commit is contained in:
parent
7e2815fabc
commit
bfcfb6b95a
3 changed files with 42 additions and 2 deletions
36
app/controllers/diaspora_federation/fetch_controller.rb
Normal file
36
app/controllers/diaspora_federation/fetch_controller.rb
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
require_dependency "diaspora_federation/application_controller"
|
||||
|
||||
module DiasporaFederation
|
||||
# this controller processes fetch requests
|
||||
class FetchController < ApplicationController
|
||||
# returns the fetched entity or a redirect
|
||||
#
|
||||
# GET /fetch/:type/:guid
|
||||
def fetch
|
||||
entity = fetch_public_entity
|
||||
if entity
|
||||
magic_env = create_magic_envelope(entity)
|
||||
if magic_env
|
||||
render xml: magic_env, content_type: "application/magic-envelope+xml"
|
||||
else
|
||||
redirect_to DiasporaFederation.callbacks.trigger(:fetch_person_url_to,
|
||||
entity.author, "/fetch/#{params[:type]}/#{params[:guid]}")
|
||||
end
|
||||
else
|
||||
render nothing: true, status: 404
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def fetch_public_entity
|
||||
type = DiasporaFederation::Entity.entity_class(params[:type]).to_s.rpartition("::").last
|
||||
DiasporaFederation.callbacks.trigger(:fetch_public_entity, type, params[:guid])
|
||||
end
|
||||
|
||||
def create_magic_envelope(entity)
|
||||
privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key_by_diaspora_id, entity.author)
|
||||
Salmon::MagicEnvelope.new(entity).envelop(privkey, entity.author) if privkey
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -13,7 +13,7 @@ module DiasporaFederation
|
|||
#
|
||||
# GET /.well-known/host-meta
|
||||
def host_meta
|
||||
render body: WebfingerController.host_meta_xml, content_type: "application/xrd+xml"
|
||||
render xml: WebfingerController.host_meta_xml, content_type: "application/xrd+xml"
|
||||
end
|
||||
|
||||
# @deprecated this is the pre RFC 7033 webfinger
|
||||
|
|
@ -41,7 +41,7 @@ module DiasporaFederation
|
|||
render nothing: true, status: 404
|
||||
else
|
||||
logger.info "webfinger profile request for: #{person_wf.acct_uri}"
|
||||
render body: person_wf.to_xml, content_type: "application/xrd+xml"
|
||||
render xml: person_wf.to_xml, content_type: "application/xrd+xml"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,10 @@ DiasporaFederation::Engine.routes.draw do
|
|||
post "receive/users/:guid" => :private, :as => "receive_private"
|
||||
end
|
||||
|
||||
controller :fetch do
|
||||
get "fetch/:type/:guid" => :fetch, :as => "fetch"
|
||||
end
|
||||
|
||||
controller :webfinger do
|
||||
get ".well-known/host-meta" => :host_meta, :as => "host_meta"
|
||||
get "webfinger" => :legacy_webfinger, :as => "legacy_webfinger"
|
||||
|
|
|
|||
Loading…
Reference in a new issue