Allow instance to have non-standard ports
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
19052ba48b
commit
f6ac72f08d
@ -8,7 +8,9 @@ defmodule Mobilizon.Federation.ActivityPub.Publisher do
|
||||
alias Mobilizon.Federation.ActivityPub.{Activity, Federator, Relay, Transmogrifier, Visibility}
|
||||
alias Mobilizon.Federation.HTTPSignatures.Signature
|
||||
require Logger
|
||||
import Mobilizon.Federation.ActivityPub.Utils, only: [remote_actors: 1]
|
||||
|
||||
import Mobilizon.Federation.ActivityPub.Utils,
|
||||
only: [remote_actors: 1, create_full_domain_string: 1]
|
||||
|
||||
@doc """
|
||||
Publish an activity to all appropriated audiences inboxes
|
||||
@ -77,7 +79,7 @@ defmodule Mobilizon.Federation.ActivityPub.Publisher do
|
||||
Tesla.Env.result()
|
||||
def publish_one(%{inbox: inbox, json: json, actor: actor, id: id}) do
|
||||
Logger.info("Federating #{id} to #{inbox}")
|
||||
%URI{host: host, path: path} = URI.parse(inbox)
|
||||
%URI{path: path} = uri = URI.new!(inbox)
|
||||
|
||||
digest = Signature.build_digest(json)
|
||||
date = Signature.generate_date_header()
|
||||
@ -87,7 +89,7 @@ defmodule Mobilizon.Federation.ActivityPub.Publisher do
|
||||
signature =
|
||||
Signature.sign(actor, %{
|
||||
"(request-target)": "post #{path}",
|
||||
host: host,
|
||||
host: create_full_domain_string(uri),
|
||||
"content-length": byte_size(json),
|
||||
digest: digest,
|
||||
date: date
|
||||
|
@ -14,9 +14,9 @@ defmodule Mobilizon.Federation.ActivityPub.Relay do
|
||||
alias Mobilizon.Federation.ActivityPub.{Actions, Activity, Transmogrifier}
|
||||
alias Mobilizon.Federation.ActivityPub.Actor, as: ActivityPubActor
|
||||
alias Mobilizon.Federation.WebFinger
|
||||
alias Mobilizon.Service.Workers.Background
|
||||
|
||||
alias Mobilizon.GraphQL.API.Follows
|
||||
alias Mobilizon.Service.Workers.Background
|
||||
import Mobilizon.Federation.ActivityPub.Utils, only: [create_full_domain_string: 1]
|
||||
|
||||
require Logger
|
||||
|
||||
@ -172,14 +172,14 @@ defmodule Mobilizon.Federation.ActivityPub.Relay do
|
||||
defp fetch_actor("http://" <> address), do: fetch_actor(address)
|
||||
|
||||
defp fetch_actor(address) do
|
||||
%URI{host: host} = URI.parse("http://" <> address)
|
||||
%URI{host: host} = uri = URI.parse("http://" <> address)
|
||||
|
||||
cond do
|
||||
String.contains?(address, "@") ->
|
||||
check_actor(address)
|
||||
|
||||
!is_nil(host) ->
|
||||
check_actor("relay@#{host}")
|
||||
uri |> create_full_domain_string() |> check_actor()
|
||||
|
||||
true ->
|
||||
{:error, :bad_url}
|
||||
|
@ -781,4 +781,16 @@ defmodule Mobilizon.Federation.ActivityPub.Utils do
|
||||
params
|
||||
end
|
||||
end
|
||||
|
||||
@schemes_with_no_port ["http", "https"]
|
||||
|
||||
def create_full_domain_string(%URI{host: host, port: nil}), do: host
|
||||
|
||||
def create_full_domain_string(%URI{host: host, port: port}) do
|
||||
if port in Enum.map(@schemes_with_no_port, &URI.default_port/1) do
|
||||
host
|
||||
else
|
||||
"#{host}:#{port}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -17,6 +17,7 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Actor do
|
||||
alias Mobilizon.Service.RichMedia.Parser
|
||||
alias Mobilizon.Web.Upload
|
||||
import Mobilizon.Federation.ActivityStream.Converter.Utils, only: [get_address: 1]
|
||||
import Mobilizon.Federation.ActivityPub.Utils, only: [create_full_domain_string: 1]
|
||||
|
||||
@behaviour Converter
|
||||
|
||||
@ -54,7 +55,7 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Actor do
|
||||
outbox_url: data["outbox"],
|
||||
following_url: data["following"],
|
||||
followers_url: data["followers"],
|
||||
domain: URI.parse(data["id"]).host,
|
||||
domain: data["id"] |> URI.new!() |> create_full_domain_string(),
|
||||
manually_approves_followers: data["manuallyApprovesFollowers"],
|
||||
type: data["type"],
|
||||
visibility: if(Map.get(data, "discoverable", false) == true, do: :public, else: :unlisted),
|
||||
|
Loading…
Reference in New Issue
Block a user