diff options
author | Roger Braun <roger@rogerbraun.net> | 2017-03-30 14:32:36 +0200 |
---|---|---|
committer | Roger Braun <roger@rogerbraun.net> | 2017-03-30 14:32:36 +0200 |
commit | d18473f0c3ba151d9640a08192370fee2e9af105 (patch) | |
tree | bf7a17ede06242a7acb64b0acb78ba722d2d35f2 /lib | |
parent | e7dc39e40cde5599f2e1e0dd1715670fd1e76720 (diff) | |
download | pleroma-d18473f0c3ba151d9640a08192370fee2e9af105.tar.gz |
Add port if specified.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/upload.ex | 9 | ||||
-rw-r--r-- | lib/pleroma/web/activity_pub/activity_pub.ex | 8 | ||||
-rw-r--r-- | lib/pleroma/web/web.ex | 19 |
3 files changed, 21 insertions, 15 deletions
diff --git a/lib/pleroma/upload.ex b/lib/pleroma/upload.ex index fdda2634e..158656e92 100644 --- a/lib/pleroma/upload.ex +++ b/lib/pleroma/upload.ex @@ -20,13 +20,6 @@ defmodule Pleroma.Upload do end defp url_for(file) do - host = - Application.get_env(:pleroma, Pleroma.Web.Endpoint) - |> Keyword.fetch!(:url) - |> Keyword.fetch!(:host) - - protocol = Application.get_env(:pleroma, Pleroma.Web.Endpoint) |> Keyword.fetch!(:protocol) - - "#{protocol}://#{host}/media/#{file}" + "#{Pleroma.Web.base_url()}/media/#{file}" end end diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index f7ba1bb37..6c8250de8 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -29,13 +29,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do end def generate_id(type) do - host = - Application.get_env(:pleroma, Pleroma.Web.Endpoint) - |> Keyword.fetch!(:url) - |> Keyword.fetch!(:host) - - protocol = Application.get_env(:pleroma, Pleroma.Web.Endpoint) |> Keyword.fetch!(:protocol) - "#{protocol}://#{host}/#{type}/#{Ecto.UUID.generate}" + "#{Pleroma.Web.base_url()}/#{type}/#{Ecto.UUID.generate}" end def fetch_public_activities(opts \\ %{}) do diff --git a/lib/pleroma/web/web.ex b/lib/pleroma/web/web.ex index f392af2ca..d03db2231 100644 --- a/lib/pleroma/web/web.ex +++ b/lib/pleroma/web/web.ex @@ -60,4 +60,23 @@ defmodule Pleroma.Web do defmacro __using__(which) when is_atom(which) do apply(__MODULE__, which, []) end + + def base_url do + settings = Application.get_env(:pleroma, Pleroma.Web.Endpoint) + host = + settings + |> Keyword.fetch!(:url) + |> Keyword.fetch!(:host) + + protocol = settings |> Keyword.fetch!(:protocol) + + port_fragment = with {:ok, protocol_info} <- settings |> Keyword.fetch(String.to_atom(protocol)), + {:ok, port} <- protocol_info |> Keyword.fetch(:port) + do + ":#{port}" + else _e -> + "" + end + "#{protocol}://#{host}#{port_fragment}" + end end |