Deprecate Pleroma.Web.base_url/0

Use Pleroma.Web.Endpoint.url/0 directly instead. Reduces compiler cycles.
This commit is contained in:
Alex Gleason 2021-05-31 15:09:11 -05:00
parent 2e682788a3
commit 51a9f97e87
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
43 changed files with 93 additions and 96 deletions

View file

@ -299,7 +299,7 @@ defmodule Pleroma.LoadTesting.Activities do
"url" => [ "url" => [
%{ %{
"href" => "href" =>
"#{Pleroma.Web.base_url()}/media/b1b873552422a07bf53af01f3c231c841db4dfc42c35efde681abaf0f2a4eab7.jpg", "#{Pleroma.Web.Endpoint.url()}/media/b1b873552422a07bf53af01f3c231c841db4dfc42c35efde681abaf0f2a4eab7.jpg",
"mediaType" => "image/jpeg", "mediaType" => "image/jpeg",
"type" => "Link" "type" => "Link"
} }

View file

@ -25,7 +25,7 @@ defmodule Pleroma.Application do
if Process.whereis(Pleroma.Web.Endpoint) do if Process.whereis(Pleroma.Web.Endpoint) do
case Config.get([:http, :user_agent], :default) do case Config.get([:http, :user_agent], :default) do
:default -> :default ->
info = "#{Pleroma.Web.base_url()} <#{Config.get([:instance, :email], "")}>" info = "#{Pleroma.Web.Endpoint.url()} <#{Config.get([:instance, :email], "")}>"
named_version() <> "; " <> info named_version() <> "; " <> info
custom -> custom ->

View file

@ -28,5 +28,5 @@ defmodule Pleroma.Constants do
~w(index.html robots.txt static static-fe finmoji emoji packs sounds images instance sw.js sw-pleroma.js favicon.png schemas doc embed.js embed.css) ~w(index.html robots.txt static static-fe finmoji emoji packs sounds images instance sw.js sw-pleroma.js favicon.png schemas doc embed.js embed.css)
) )
def as_local_public, do: Pleroma.Web.base_url() <> "/#Public" def as_local_public, do: Pleroma.Web.Endpoint.url() <> "/#Public"
end end

View file

@ -73,7 +73,7 @@ defmodule Pleroma.Emails.AdminEmail do
#{comment_html} #{comment_html}
#{statuses_html} #{statuses_html}
<p> <p>
<a href="#{Pleroma.Web.base_url()}/pleroma/admin/#/reports/index">View Reports in AdminFE</a> <a href="#{Pleroma.Web.Endpoint.url()}/pleroma/admin/#/reports/index">View Reports in AdminFE</a>
""" """
new() new()
@ -87,7 +87,7 @@ defmodule Pleroma.Emails.AdminEmail do
html_body = """ html_body = """
<p>New account for review: <a href="#{account.ap_id}">@#{account.nickname}</a></p> <p>New account for review: <a href="#{account.ap_id}">@#{account.nickname}</a></p>
<blockquote>#{HTML.strip_tags(account.registration_reason)}</blockquote> <blockquote>#{HTML.strip_tags(account.registration_reason)}</blockquote>
<a href="#{Pleroma.Web.base_url()}/pleroma/admin/#/users/#{account.id}/">Visit AdminFE</a> <a href="#{Pleroma.Web.Endpoint.url()}/pleroma/admin/#/users/#{account.id}/">Visit AdminFE</a>
""" """
new() new()

View file

@ -5,7 +5,7 @@
defmodule Pleroma.Emoji.Formatter do defmodule Pleroma.Emoji.Formatter do
alias Pleroma.Emoji alias Pleroma.Emoji
alias Pleroma.HTML alias Pleroma.HTML
alias Pleroma.Web alias Pleroma.Web.Endpoint
alias Pleroma.Web.MediaProxy alias Pleroma.Web.MediaProxy
def emojify(text) do def emojify(text) do
@ -44,7 +44,7 @@ defmodule Pleroma.Emoji.Formatter do
Emoji.get_all() Emoji.get_all()
|> Enum.filter(fn {emoji, %Emoji{}} -> String.contains?(text, ":#{emoji}:") end) |> Enum.filter(fn {emoji, %Emoji{}} -> String.contains?(text, ":#{emoji}:") end)
|> Enum.reduce(%{}, fn {name, %Emoji{file: file}}, acc -> |> Enum.reduce(%{}, fn {name, %Emoji{file: file}}, acc ->
Map.put(acc, name, to_string(URI.merge(Web.base_url(), file))) Map.put(acc, name, to_string(URI.merge(Endpoint.url(), file)))
end) end)
end end

View file

@ -62,7 +62,7 @@ defmodule Pleroma.Formatter do
def hashtag_handler("#" <> tag = tag_text, _buffer, _opts, acc) do def hashtag_handler("#" <> tag = tag_text, _buffer, _opts, acc) do
tag = String.downcase(tag) tag = String.downcase(tag)
url = "#{Pleroma.Web.base_url()}/tag/#{tag}" url = "#{Pleroma.Web.Endpoint.url()}/tag/#{tag}"
link = link =
Phoenix.HTML.Tag.content_tag(:a, tag_text, Phoenix.HTML.Tag.content_tag(:a, tag_text,

View file

@ -325,7 +325,7 @@ defmodule Pleroma.Object do
end end
def local?(%Object{data: %{"id" => id}}) do def local?(%Object{data: %{"id" => id}}) do
String.starts_with?(id, Pleroma.Web.base_url() <> "/") String.starts_with?(id, Pleroma.Web.Endpoint.url() <> "/")
end end
def replies(object, opts \\ []) do def replies(object, opts \\ []) do

View file

@ -225,7 +225,7 @@ defmodule Pleroma.Upload do
case uploader do case uploader do
Pleroma.Uploaders.Local -> Pleroma.Uploaders.Local ->
upload_base_url || Pleroma.Web.base_url() <> "/media/" upload_base_url || Pleroma.Web.Endpoint.url() <> "/media/"
Pleroma.Uploaders.S3 -> Pleroma.Uploaders.S3 ->
bucket = Config.get([Pleroma.Uploaders.S3, :bucket]) bucket = Config.get([Pleroma.Uploaders.S3, :bucket])
@ -251,7 +251,7 @@ defmodule Pleroma.Upload do
end end
_ -> _ ->
public_endpoint || upload_base_url || Pleroma.Web.base_url() <> "/media/" public_endpoint || upload_base_url || Pleroma.Web.Endpoint.url() <> "/media/"
end end
end end
end end

View file

@ -27,13 +27,13 @@ defmodule Pleroma.User do
alias Pleroma.Repo alias Pleroma.Repo
alias Pleroma.User alias Pleroma.User
alias Pleroma.UserRelationship alias Pleroma.UserRelationship
alias Pleroma.Web
alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Builder alias Pleroma.Web.ActivityPub.Builder
alias Pleroma.Web.ActivityPub.Pipeline alias Pleroma.Web.ActivityPub.Pipeline
alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.CommonAPI alias Pleroma.Web.CommonAPI
alias Pleroma.Web.CommonAPI.Utils, as: CommonUtils alias Pleroma.Web.CommonAPI.Utils, as: CommonUtils
alias Pleroma.Web.Endpoint
alias Pleroma.Web.OAuth alias Pleroma.Web.OAuth
alias Pleroma.Web.RelMe alias Pleroma.Web.RelMe
alias Pleroma.Workers.BackgroundWorker alias Pleroma.Workers.BackgroundWorker
@ -359,7 +359,7 @@ defmodule Pleroma.User do
_ -> _ ->
unless options[:no_default] do unless options[:no_default] do
Config.get([:assets, :default_user_avatar], "#{Web.base_url()}/images/avi.png") Config.get([:assets, :default_user_avatar], "#{Endpoint.url()}/images/avi.png")
end end
end end
end end
@ -367,12 +367,12 @@ defmodule Pleroma.User do
def banner_url(user, options \\ []) do def banner_url(user, options \\ []) do
case user.banner do case user.banner do
%{"url" => [%{"href" => href} | _]} -> href %{"url" => [%{"href" => href} | _]} -> href
_ -> !options[:no_default] && "#{Web.base_url()}/images/banner.png" _ -> !options[:no_default] && "#{Endpoint.url()}/images/banner.png"
end end
end end
# Should probably be renamed or removed # Should probably be renamed or removed
def ap_id(%User{nickname: nickname}), do: "#{Web.base_url()}/users/#{nickname}" def ap_id(%User{nickname: nickname}), do: "#{Endpoint.url()}/users/#{nickname}"
def ap_followers(%User{follower_address: fa}) when is_binary(fa), do: fa def ap_followers(%User{follower_address: fa}) when is_binary(fa), do: fa
def ap_followers(%User{} = user), do: "#{ap_id(user)}/followers" def ap_followers(%User{} = user), do: "#{ap_id(user)}/followers"

View file

@ -231,8 +231,4 @@ defmodule Pleroma.Web do
defmacro __using__(which) when is_atom(which) do defmacro __using__(which) when is_atom(which) do
apply(__MODULE__, which, []) apply(__MODULE__, which, [])
end end
def base_url do
Pleroma.Web.Endpoint.url()
end
end end

View file

@ -6,7 +6,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.NoEmptyPolicy do
@moduledoc "Filter local activities which have no content" @moduledoc "Filter local activities which have no content"
@behaviour Pleroma.Web.ActivityPub.MRF @behaviour Pleroma.Web.ActivityPub.MRF
alias Pleroma.Web alias Pleroma.Web.Endpoint
@impl true @impl true
def filter(%{"actor" => actor} = object) do def filter(%{"actor" => actor} = object) do
@ -24,7 +24,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.NoEmptyPolicy do
def filter(object), do: {:ok, object} def filter(object), do: {:ok, object}
defp is_local?(actor) do defp is_local?(actor) do
if actor |> String.starts_with?("#{Web.base_url()}") do if actor |> String.starts_with?("#{Endpoint.url()}") do
true true
else else
false false

View file

@ -272,7 +272,7 @@ defmodule Pleroma.Web.ActivityPub.Publisher do
}, },
%{ %{
"rel" => "http://ostatus.org/schema/1.0/subscribe", "rel" => "http://ostatus.org/schema/1.0/subscribe",
"template" => "#{Pleroma.Web.base_url()}/ostatus_subscribe?acct={uri}" "template" => "#{Pleroma.Web.Endpoint.url()}/ostatus_subscribe?acct={uri}"
} }
] ]
end end

View file

@ -12,7 +12,6 @@ defmodule Pleroma.Web.ActivityPub.Utils do
alias Pleroma.Object alias Pleroma.Object
alias Pleroma.Repo alias Pleroma.Repo
alias Pleroma.User alias Pleroma.User
alias Pleroma.Web
alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Visibility alias Pleroma.Web.ActivityPub.Visibility
alias Pleroma.Web.AdminAPI.AccountView alias Pleroma.Web.AdminAPI.AccountView
@ -107,7 +106,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
%{ %{
"@context" => [ "@context" => [
"https://www.w3.org/ns/activitystreams", "https://www.w3.org/ns/activitystreams",
"#{Web.base_url()}/schemas/litepub-0.1.jsonld", "#{Endpoint.url()}/schemas/litepub-0.1.jsonld",
%{ %{
"@language" => "und" "@language" => "und"
} }
@ -132,7 +131,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
end end
def generate_id(type) do def generate_id(type) do
"#{Web.base_url()}/#{type}/#{UUID.generate()}" "#{Endpoint.url()}/#{type}/#{UUID.generate()}"
end end
def get_notified_from_object(%{"type" => type} = object) when type in @supported_object_types do def get_notified_from_object(%{"type" => type} = object) when type in @supported_object_types do

View file

@ -51,10 +51,10 @@ defmodule Pleroma.Web.Feed.FeedView do
def feed_logo do def feed_logo do
case Pleroma.Config.get([:feed, :logo]) do case Pleroma.Config.get([:feed, :logo]) do
nil -> nil ->
"#{Pleroma.Web.base_url()}/static/logo.svg" "#{Pleroma.Web.Endpoint.url()}/static/logo.svg"
logo -> logo ->
"#{Pleroma.Web.base_url()}#{logo}" "#{Pleroma.Web.Endpoint.url()}#{logo}"
end end
|> MediaProxy.url() |> MediaProxy.url()
end end

View file

@ -8,8 +8,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchController do
alias Pleroma.Activity alias Pleroma.Activity
alias Pleroma.Repo alias Pleroma.Repo
alias Pleroma.User alias Pleroma.User
alias Pleroma.Web
alias Pleroma.Web.ControllerHelper alias Pleroma.Web.ControllerHelper
alias Pleroma.Web.Endpoint
alias Pleroma.Web.MastodonAPI.AccountView alias Pleroma.Web.MastodonAPI.AccountView
alias Pleroma.Web.MastodonAPI.StatusView alias Pleroma.Web.MastodonAPI.StatusView
alias Pleroma.Web.Plugs.OAuthScopesPlug alias Pleroma.Web.Plugs.OAuthScopesPlug
@ -108,7 +108,7 @@ defmodule Pleroma.Web.MastodonAPI.SearchController do
end end
defp resource_search(:v2, "hashtags", query, options) do defp resource_search(:v2, "hashtags", query, options) do
tags_path = Web.base_url() <> "/tag/" tags_path = Endpoint.url() <> "/tag/"
query query
|> prepare_tags(options) |> prepare_tags(options)

View file

@ -6,14 +6,14 @@ defmodule Pleroma.Web.MastodonAPI.CustomEmojiView do
use Pleroma.Web, :view use Pleroma.Web, :view
alias Pleroma.Emoji alias Pleroma.Emoji
alias Pleroma.Web alias Pleroma.Web.Endpoint
def render("index.json", %{custom_emojis: custom_emojis}) do def render("index.json", %{custom_emojis: custom_emojis}) do
render_many(custom_emojis, __MODULE__, "show.json") render_many(custom_emojis, __MODULE__, "show.json")
end end
def render("show.json", %{custom_emoji: {shortcode, %Emoji{file: relative_url, tags: tags}}}) do def render("show.json", %{custom_emoji: {shortcode, %Emoji{file: relative_url, tags: tags}}}) do
url = Web.base_url() |> URI.merge(relative_url) |> to_string() url = Endpoint.url() |> URI.merge(relative_url) |> to_string()
%{ %{
"shortcode" => shortcode, "shortcode" => shortcode,

View file

@ -14,7 +14,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
instance = Config.get(:instance) instance = Config.get(:instance)
%{ %{
uri: Pleroma.Web.base_url(), uri: Pleroma.Web.Endpoint.url(),
title: Keyword.get(instance, :name), title: Keyword.get(instance, :name),
description: Keyword.get(instance, :description), description: Keyword.get(instance, :description),
version: "#{@mastodon_api_level} (compatible; #{Pleroma.Application.named_version()})", version: "#{@mastodon_api_level} (compatible; #{Pleroma.Application.named_version()})",
@ -23,7 +23,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
streaming_api: Pleroma.Web.Endpoint.websocket_url() streaming_api: Pleroma.Web.Endpoint.websocket_url()
}, },
stats: Pleroma.Stats.get_stats(), stats: Pleroma.Stats.get_stats(),
thumbnail: Pleroma.Web.base_url() <> Keyword.get(instance, :instance_thumbnail), thumbnail: Pleroma.Web.Endpoint.url() <> Keyword.get(instance, :instance_thumbnail),
languages: ["en"], languages: ["en"],
registrations: Keyword.get(instance, :registrations_open), registrations: Keyword.get(instance, :registrations_open),
approval_required: Keyword.get(instance, :account_approval_required), approval_required: Keyword.get(instance, :account_approval_required),
@ -34,7 +34,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
avatar_upload_limit: Keyword.get(instance, :avatar_upload_limit), avatar_upload_limit: Keyword.get(instance, :avatar_upload_limit),
background_upload_limit: Keyword.get(instance, :background_upload_limit), background_upload_limit: Keyword.get(instance, :background_upload_limit),
banner_upload_limit: Keyword.get(instance, :banner_upload_limit), banner_upload_limit: Keyword.get(instance, :banner_upload_limit),
background_image: Pleroma.Web.base_url() <> Keyword.get(instance, :background_image), background_image: Pleroma.Web.Endpoint.url() <> Keyword.get(instance, :background_image),
chat_limit: Keyword.get(instance, :chat_limit), chat_limit: Keyword.get(instance, :chat_limit),
description_limit: Keyword.get(instance, :description_limit), description_limit: Keyword.get(instance, :description_limit),
pleroma: %{ pleroma: %{

View file

@ -485,7 +485,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
def build_tags(object_tags) when is_list(object_tags) do def build_tags(object_tags) when is_list(object_tags) do
object_tags object_tags
|> Enum.filter(&is_binary/1) |> Enum.filter(&is_binary/1)
|> Enum.map(&%{name: &1, url: "#{Pleroma.Web.base_url()}/tag/#{URI.encode(&1)}"}) |> Enum.map(&%{name: &1, url: "#{Pleroma.Web.Endpoint.url()}/tag/#{URI.encode(&1)}"})
end end
def build_tags(_), do: [] def build_tags(_), do: []

View file

@ -6,7 +6,7 @@ defmodule Pleroma.Web.MediaProxy do
alias Pleroma.Config alias Pleroma.Config
alias Pleroma.Helpers.UriHelper alias Pleroma.Helpers.UriHelper
alias Pleroma.Upload alias Pleroma.Upload
alias Pleroma.Web alias Pleroma.Web.Endpoint
alias Pleroma.Web.MediaProxy.Invalidation alias Pleroma.Web.MediaProxy.Invalidation
@base64_opts [padding: false] @base64_opts [padding: false]
@ -69,7 +69,7 @@ defmodule Pleroma.Web.MediaProxy do
# non-local non-whitelisted URLs through it and be sure that body size constraint is preserved. # non-local non-whitelisted URLs through it and be sure that body size constraint is preserved.
def preview_enabled?, do: enabled?() and !!Config.get([:media_preview_proxy, :enabled]) def preview_enabled?, do: enabled?() and !!Config.get([:media_preview_proxy, :enabled])
def local?(url), do: String.starts_with?(url, Web.base_url()) def local?(url), do: String.starts_with?(url, Endpoint.url())
def whitelisted?(url) do def whitelisted?(url) do
%{host: domain} = URI.parse(url) %{host: domain} = URI.parse(url)
@ -122,7 +122,7 @@ defmodule Pleroma.Web.MediaProxy do
end end
defp signed_url(url) do defp signed_url(url) do
:crypto.hmac(:sha, Config.get([Web.Endpoint, :secret_key_base]), url) :crypto.hmac(:sha, Config.get([Endpoint, :secret_key_base]), url)
end end
def filename(url_or_path) do def filename(url_or_path) do
@ -130,7 +130,7 @@ defmodule Pleroma.Web.MediaProxy do
end end
def base_url do def base_url do
Config.get([:media_proxy, :base_url], Web.base_url()) Config.get([:media_proxy, :base_url], Endpoint.url())
end end
defp proxy_url(path, sig_base64, url_base64, filename) do defp proxy_url(path, sig_base64, url_base64, filename) do

View file

@ -5,7 +5,7 @@
defmodule Pleroma.Web.Nodeinfo.NodeinfoController do defmodule Pleroma.Web.Nodeinfo.NodeinfoController do
use Pleroma.Web, :controller use Pleroma.Web, :controller
alias Pleroma.Web alias Pleroma.Web.Endpoint
alias Pleroma.Web.Nodeinfo.Nodeinfo alias Pleroma.Web.Nodeinfo.Nodeinfo
def schemas(conn, _params) do def schemas(conn, _params) do
@ -13,11 +13,11 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do
links: [ links: [
%{ %{
rel: "http://nodeinfo.diaspora.software/ns/schema/2.0", rel: "http://nodeinfo.diaspora.software/ns/schema/2.0",
href: Web.base_url() <> "/nodeinfo/2.0.json" href: Endpoint.url() <> "/nodeinfo/2.0.json"
}, },
%{ %{
rel: "http://nodeinfo.diaspora.software/ns/schema/2.1", rel: "http://nodeinfo.diaspora.software/ns/schema/2.1",
href: Web.base_url() <> "/nodeinfo/2.1.json" href: Endpoint.url() <> "/nodeinfo/2.1.json"
} }
] ]
} }

View file

@ -38,7 +38,7 @@
<%= if id == Pleroma.Constants.as_public() do %> <%= if id == Pleroma.Constants.as_public() do %>
<link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/> <link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/>
<% else %> <% else %>
<%= unless Regex.match?(~r/^#{Pleroma.Web.base_url()}.+followers$/, id) do %> <%= unless Regex.match?(~r/^#{Pleroma.Web.Endpoint.url()}.+followers$/, id) do %>
<link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="<%= id %>"/> <link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="<%= id %>"/>
<% end %> <% end %>
<% end %> <% end %>

View file

@ -38,7 +38,7 @@
<%= if id == Pleroma.Constants.as_public() do %> <%= if id == Pleroma.Constants.as_public() do %>
<link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection">http://activityschema.org/collection/public</link> <link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection">http://activityschema.org/collection/public</link>
<% else %> <% else %>
<%= unless Regex.match?(~r/^#{Pleroma.Web.base_url()}.+followers$/, id) do %> <%= unless Regex.match?(~r/^#{Pleroma.Web.Endpoint.url()}.+followers$/, id) do %>
<link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person"><%= id %></link> <link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person"><%= id %></link>
<% end %> <% end %>
<% end %> <% end %>

View file

@ -33,7 +33,7 @@
ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection"
href="http://activityschema.org/collection/public"/> href="http://activityschema.org/collection/public"/>
<% else %> <% else %>
<%= unless Regex.match?(~r/^#{Pleroma.Web.base_url()}.+followers$/, id) do %> <%= unless Regex.match?(~r/^#{Pleroma.Web.Endpoint.url()}.+followers$/, id) do %>
<link rel="mentioned" <link rel="mentioned"
ostatus:object-type="http://activitystrea.ms/schema/1.0/person" ostatus:object-type="http://activitystrea.ms/schema/1.0/person"
href="<%= id %>" /> href="<%= id %>" />

View file

@ -1,2 +1,2 @@
<h2>Password reset failed</h2> <h2>Password reset failed</h2>
<h3><a href="<%= Pleroma.Web.base_url() %>">Homepage</a></h3> <h3><a href="<%= Pleroma.Web.Endpoint.url() %>">Homepage</a></h3>

View file

@ -1,2 +1,2 @@
<h2>Password changed!</h2> <h2>Password changed!</h2>
<h3><a href="<%= Pleroma.Web.base_url() %>">Homepage</a></h3> <h3><a href="<%= Pleroma.Web.Endpoint.url() %>">Homepage</a></h3>

View file

@ -6,14 +6,14 @@ defmodule Pleroma.Web.TwitterAPI.UtilView do
use Pleroma.Web, :view use Pleroma.Web, :view
import Phoenix.HTML.Form import Phoenix.HTML.Form
alias Pleroma.Config alias Pleroma.Config
alias Pleroma.Web alias Pleroma.Web.Endpoint
def status_net_config(instance) do def status_net_config(instance) do
""" """
<config> <config>
<site> <site>
<name>#{Keyword.get(instance, :name)}</name> <name>#{Keyword.get(instance, :name)}</name>
<site>#{Web.base_url()}</site> <site>#{Endpoint.url()}</site>
<textlimit>#{Keyword.get(instance, :limit)}</textlimit> <textlimit>#{Keyword.get(instance, :limit)}</textlimit>
<closed>#{!Keyword.get(instance, :registrations_open)}</closed> <closed>#{!Keyword.get(instance, :registrations_open)}</closed>
</site> </site>

View file

@ -78,7 +78,7 @@ defmodule Pleroma.Web.MastoFEView do
theme_color: Config.get([:manifest, :theme_color]), theme_color: Config.get([:manifest, :theme_color]),
background_color: Config.get([:manifest, :background_color]), background_color: Config.get([:manifest, :background_color]),
display: "standalone", display: "standalone",
scope: Pleroma.Web.base_url(), scope: Pleroma.Web.Endpoint.url(),
start_url: Routes.masto_fe_path(Pleroma.Web.Endpoint, :index, ["getting-started"]), start_url: Routes.masto_fe_path(Pleroma.Web.Endpoint, :index, ["getting-started"]),
categories: [ categories: [
"social" "social"

View file

@ -5,7 +5,7 @@
defmodule Pleroma.Web.WebFinger do defmodule Pleroma.Web.WebFinger do
alias Pleroma.HTTP alias Pleroma.HTTP
alias Pleroma.User alias Pleroma.User
alias Pleroma.Web alias Pleroma.Web.Endpoint
alias Pleroma.Web.Federator.Publisher alias Pleroma.Web.Federator.Publisher
alias Pleroma.Web.XML alias Pleroma.Web.XML
alias Pleroma.XmlBuilder alias Pleroma.XmlBuilder
@ -13,7 +13,7 @@ defmodule Pleroma.Web.WebFinger do
require Logger require Logger
def host_meta do def host_meta do
base_url = Web.base_url() base_url = Endpoint.url()
{ {
:XRD, :XRD,

View file

@ -151,7 +151,7 @@ defmodule Pleroma.UserTest do
test "ap_id returns the activity pub id for the user" do test "ap_id returns the activity pub id for the user" do
user = UserBuilder.build() user = UserBuilder.build()
expected_ap_id = "#{Pleroma.Web.base_url()}/users/#{user.nickname}" expected_ap_id = "#{Pleroma.Web.Endpoint.url()}/users/#{user.nickname}"
assert expected_ap_id == User.ap_id(user) assert expected_ap_id == User.ap_id(user)
end end

View file

@ -504,7 +504,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
defp build_local_message do defp build_local_message do
%{ %{
"actor" => "#{Pleroma.Web.base_url()}/users/alice", "actor" => "#{Pleroma.Web.Endpoint.url()}/users/alice",
"to" => [], "to" => [],
"cc" => [] "cc" => []
} }

View file

@ -38,7 +38,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
}, },
%{ %{
"rel" => "http://ostatus.org/schema/1.0/subscribe", "rel" => "http://ostatus.org/schema/1.0/subscribe",
"template" => "#{Pleroma.Web.base_url()}/ostatus_subscribe?acct={uri}" "template" => "#{Pleroma.Web.Endpoint.url()}/ostatus_subscribe?acct={uri}"
} }
] ]

View file

@ -8,7 +8,7 @@ defmodule Pleroma.Web.AdminAPI.OAuthAppControllerTest do
import Pleroma.Factory import Pleroma.Factory
alias Pleroma.Web alias Pleroma.Web.Endpoint
setup do setup do
admin = insert(:user, is_admin: true) admin = insert(:user, is_admin: true)
@ -36,7 +36,7 @@ defmodule Pleroma.Web.AdminAPI.OAuthAppControllerTest do
end end
test "success", %{conn: conn} do test "success", %{conn: conn} do
base_url = Web.base_url() base_url = Endpoint.url()
app_name = "Trusted app" app_name = "Trusted app"
response = response =
@ -58,7 +58,7 @@ defmodule Pleroma.Web.AdminAPI.OAuthAppControllerTest do
end end
test "with trusted", %{conn: conn} do test "with trusted", %{conn: conn} do
base_url = Web.base_url() base_url = Endpoint.url()
app_name = "Trusted app" app_name = "Trusted app"
response = response =

View file

@ -14,9 +14,9 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
alias Pleroma.Repo alias Pleroma.Repo
alias Pleroma.Tests.ObanHelpers alias Pleroma.Tests.ObanHelpers
alias Pleroma.User alias Pleroma.User
alias Pleroma.Web
alias Pleroma.Web.ActivityPub.Relay alias Pleroma.Web.ActivityPub.Relay
alias Pleroma.Web.CommonAPI alias Pleroma.Web.CommonAPI
alias Pleroma.Web.Endpoint
alias Pleroma.Web.MediaProxy alias Pleroma.Web.MediaProxy
setup_all do setup_all do
@ -403,7 +403,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
end end
test "pagination works correctly with service users", %{conn: conn} do test "pagination works correctly with service users", %{conn: conn} do
service1 = User.get_or_create_service_actor_by_ap_id(Web.base_url() <> "/meido", "meido") service1 = User.get_or_create_service_actor_by_ap_id(Endpoint.url() <> "/meido", "meido")
insert_list(25, :user) insert_list(25, :user)

View file

@ -514,7 +514,7 @@ defmodule Pleroma.Web.CommonAPITest do
{:ok, activity} = CommonAPI.post(user, %{status: "hey :blank:"}) {:ok, activity} = CommonAPI.post(user, %{status: "hey :blank:"})
assert %{"blank" => url} = Object.normalize(activity).data["emoji"] assert %{"blank" => url} = Object.normalize(activity).data["emoji"]
assert url == "#{Pleroma.Web.base_url()}/emoji/blank.png" assert url == "#{Pleroma.Web.Endpoint.url()}/emoji/blank.png"
end end
test "deactivated users can't post" do test "deactivated users can't post" do

View file

@ -127,10 +127,10 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
"These are public toots tagged with #pleromaart. You can interact with them if you have an account anywhere in the fediverse." "These are public toots tagged with #pleromaart. You can interact with them if you have an account anywhere in the fediverse."
assert xpath(xml, ~x"//channel/link/text()") == assert xpath(xml, ~x"//channel/link/text()") ==
'#{Pleroma.Web.base_url()}/tags/pleromaart.rss' '#{Pleroma.Web.Endpoint.url()}/tags/pleromaart.rss'
assert xpath(xml, ~x"//channel/webfeeds:logo/text()") == assert xpath(xml, ~x"//channel/webfeeds:logo/text()") ==
'#{Pleroma.Web.base_url()}/static/logo.svg' '#{Pleroma.Web.Endpoint.url()}/static/logo.svg'
assert xpath(xml, ~x"//channel/item/title/text()"l) == [ assert xpath(xml, ~x"//channel/item/title/text()"l) == [
'42 This is :moominmamm...', '42 This is :moominmamm...',

View file

@ -217,7 +217,9 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
|> get("/users/#{user.nickname}") |> get("/users/#{user.nickname}")
assert conn.status == 302 assert conn.status == 302
assert redirected_to(conn) == "#{Pleroma.Web.base_url()}/users/#{user.nickname}/feed.atom"
assert redirected_to(conn) ==
"#{Pleroma.Web.Endpoint.url()}/users/#{user.nickname}/feed.atom"
end end
test "with non-html / non-json format, it returns error when user is not found", %{conn: conn} do test "with non-html / non-json format, it returns error when user is not found", %{conn: conn} do

View file

@ -14,8 +14,8 @@ defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do
assert result = json_response_and_validate_schema(conn, 200) assert result = json_response_and_validate_schema(conn, 200)
email = Pleroma.Config.get([:instance, :email]) email = Pleroma.Config.get([:instance, :email])
thumbnail = Pleroma.Web.base_url() <> Pleroma.Config.get([:instance, :instance_thumbnail]) thumbnail = Pleroma.Web.Endpoint.url() <> Pleroma.Config.get([:instance, :instance_thumbnail])
background = Pleroma.Web.base_url() <> Pleroma.Config.get([:instance, :background_image]) background = Pleroma.Web.Endpoint.url() <> Pleroma.Config.get([:instance, :background_image])
# Note: not checking for "max_toot_chars" since it's optional # Note: not checking for "max_toot_chars" since it's optional
assert %{ assert %{

View file

@ -6,8 +6,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
use Pleroma.Web.ConnCase use Pleroma.Web.ConnCase
alias Pleroma.Object alias Pleroma.Object
alias Pleroma.Web
alias Pleroma.Web.CommonAPI alias Pleroma.Web.CommonAPI
alias Pleroma.Web.Endpoint
import Pleroma.Factory import Pleroma.Factory
import ExUnit.CaptureLog import ExUnit.CaptureLog
import Tesla.Mock import Tesla.Mock
@ -61,7 +61,7 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
assert account["id"] == to_string(user_three.id) assert account["id"] == to_string(user_three.id)
assert results["hashtags"] == [ assert results["hashtags"] == [
%{"name" => "private", "url" => "#{Web.base_url()}/tag/private"} %{"name" => "private", "url" => "#{Endpoint.url()}/tag/private"}
] ]
[status] = results["statuses"] [status] = results["statuses"]
@ -72,7 +72,7 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|> json_response_and_validate_schema(200) |> json_response_and_validate_schema(200)
assert results["hashtags"] == [ assert results["hashtags"] == [
%{"name" => "天子", "url" => "#{Web.base_url()}/tag/天子"} %{"name" => "天子", "url" => "#{Endpoint.url()}/tag/天子"}
] ]
[status] = results["statuses"] [status] = results["statuses"]
@ -87,8 +87,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|> json_response_and_validate_schema(200) |> json_response_and_validate_schema(200)
assert results["hashtags"] == [ assert results["hashtags"] == [
%{"name" => "explicit", "url" => "#{Web.base_url()}/tag/explicit"}, %{"name" => "explicit", "url" => "#{Endpoint.url()}/tag/explicit"},
%{"name" => "hashtags", "url" => "#{Web.base_url()}/tag/hashtags"} %{"name" => "hashtags", "url" => "#{Endpoint.url()}/tag/hashtags"}
] ]
results = results =
@ -97,9 +97,9 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|> json_response_and_validate_schema(200) |> json_response_and_validate_schema(200)
assert results["hashtags"] == [ assert results["hashtags"] == [
%{"name" => "john", "url" => "#{Web.base_url()}/tag/john"}, %{"name" => "john", "url" => "#{Endpoint.url()}/tag/john"},
%{"name" => "doe", "url" => "#{Web.base_url()}/tag/doe"}, %{"name" => "doe", "url" => "#{Endpoint.url()}/tag/doe"},
%{"name" => "JohnDoe", "url" => "#{Web.base_url()}/tag/JohnDoe"} %{"name" => "JohnDoe", "url" => "#{Endpoint.url()}/tag/JohnDoe"}
] ]
results = results =
@ -108,9 +108,9 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|> json_response_and_validate_schema(200) |> json_response_and_validate_schema(200)
assert results["hashtags"] == [ assert results["hashtags"] == [
%{"name" => "accident", "url" => "#{Web.base_url()}/tag/accident"}, %{"name" => "accident", "url" => "#{Endpoint.url()}/tag/accident"},
%{"name" => "prone", "url" => "#{Web.base_url()}/tag/prone"}, %{"name" => "prone", "url" => "#{Endpoint.url()}/tag/prone"},
%{"name" => "AccidentProne", "url" => "#{Web.base_url()}/tag/AccidentProne"} %{"name" => "AccidentProne", "url" => "#{Endpoint.url()}/tag/AccidentProne"}
] ]
results = results =
@ -119,7 +119,7 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|> json_response_and_validate_schema(200) |> json_response_and_validate_schema(200)
assert results["hashtags"] == [ assert results["hashtags"] == [
%{"name" => "shpuld", "url" => "#{Web.base_url()}/tag/shpuld"} %{"name" => "shpuld", "url" => "#{Endpoint.url()}/tag/shpuld"}
] ]
results = results =
@ -136,18 +136,18 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|> json_response_and_validate_schema(200) |> json_response_and_validate_schema(200)
assert results["hashtags"] == [ assert results["hashtags"] == [
%{"name" => "nascar", "url" => "#{Web.base_url()}/tag/nascar"}, %{"name" => "nascar", "url" => "#{Endpoint.url()}/tag/nascar"},
%{"name" => "ban", "url" => "#{Web.base_url()}/tag/ban"}, %{"name" => "ban", "url" => "#{Endpoint.url()}/tag/ban"},
%{"name" => "display", "url" => "#{Web.base_url()}/tag/display"}, %{"name" => "display", "url" => "#{Endpoint.url()}/tag/display"},
%{"name" => "confederate", "url" => "#{Web.base_url()}/tag/confederate"}, %{"name" => "confederate", "url" => "#{Endpoint.url()}/tag/confederate"},
%{"name" => "flag", "url" => "#{Web.base_url()}/tag/flag"}, %{"name" => "flag", "url" => "#{Endpoint.url()}/tag/flag"},
%{"name" => "all", "url" => "#{Web.base_url()}/tag/all"}, %{"name" => "all", "url" => "#{Endpoint.url()}/tag/all"},
%{"name" => "events", "url" => "#{Web.base_url()}/tag/events"}, %{"name" => "events", "url" => "#{Endpoint.url()}/tag/events"},
%{"name" => "properties", "url" => "#{Web.base_url()}/tag/properties"}, %{"name" => "properties", "url" => "#{Endpoint.url()}/tag/properties"},
%{ %{
"name" => "NascarBanDisplayConfederateFlagAllEventsProperties", "name" => "NascarBanDisplayConfederateFlagAllEventsProperties",
"url" => "url" =>
"#{Web.base_url()}/tag/NascarBanDisplayConfederateFlagAllEventsProperties" "#{Endpoint.url()}/tag/NascarBanDisplayConfederateFlagAllEventsProperties"
} }
] ]
end end
@ -163,8 +163,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|> json_response_and_validate_schema(200) |> json_response_and_validate_schema(200)
assert results["hashtags"] == [ assert results["hashtags"] == [
%{"name" => "text", "url" => "#{Web.base_url()}/tag/text"}, %{"name" => "text", "url" => "#{Endpoint.url()}/tag/text"},
%{"name" => "with", "url" => "#{Web.base_url()}/tag/with"} %{"name" => "with", "url" => "#{Endpoint.url()}/tag/with"}
] ]
end end

View file

@ -562,12 +562,12 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
AccountView.render("show.json", %{user: user, skip_visibility_check: true}) AccountView.render("show.json", %{user: user, skip_visibility_check: true})
|> Enum.all?(fn |> Enum.all?(fn
{key, url} when key in [:avatar, :avatar_static, :header, :header_static] -> {key, url} when key in [:avatar, :avatar_static, :header, :header_static] ->
String.starts_with?(url, Pleroma.Web.base_url()) String.starts_with?(url, Pleroma.Web.Endpoint.url())
{:emojis, emojis} -> {:emojis, emojis} ->
Enum.all?(emojis, fn %{url: url, static_url: static_url} -> Enum.all?(emojis, fn %{url: url, static_url: static_url} ->
String.starts_with?(url, Pleroma.Web.base_url()) && String.starts_with?(url, Pleroma.Web.Endpoint.url()) &&
String.starts_with?(static_url, Pleroma.Web.base_url()) String.starts_with?(static_url, Pleroma.Web.Endpoint.url())
end) end)
_ -> _ ->

View file

@ -42,7 +42,7 @@ defmodule Pleroma.Web.MediaProxyTest do
assert String.starts_with?( assert String.starts_with?(
encoded, encoded,
Config.get([:media_proxy, :base_url], Pleroma.Web.base_url()) Config.get([:media_proxy, :base_url], Pleroma.Web.Endpoint.url())
) )
assert String.ends_with?(encoded, "/logo.png") assert String.ends_with?(encoded, "/logo.png")

View file

@ -182,7 +182,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|> response(200) |> response(200)
assert resp =~ assert resp =~
"<meta content=\"#{Pleroma.Web.base_url()}/notice/#{note_activity.id}\" property=\"og:url\">" "<meta content=\"#{Pleroma.Web.Endpoint.url()}/notice/#{note_activity.id}\" property=\"og:url\">"
user = insert(:user) user = insert(:user)

View file

@ -25,7 +25,7 @@ defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
assert response.resp_body == assert response.resp_body ==
~s(<?xml version="1.0" encoding="UTF-8"?><XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><Link rel="lrdd" template="#{ ~s(<?xml version="1.0" encoding="UTF-8"?><XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><Link rel="lrdd" template="#{
Pleroma.Web.base_url() Pleroma.Web.Endpoint.url()
}/.well-known/webfinger?resource={uri}" type="application/xrd+xml" /></XRD>) }/.well-known/webfinger?resource={uri}" type="application/xrd+xml" /></XRD>)
end end

View file

@ -17,7 +17,7 @@ defmodule Pleroma.Web.WebFingerTest do
test "returns a link to the xml lrdd" do test "returns a link to the xml lrdd" do
host_info = WebFinger.host_meta() host_info = WebFinger.host_meta()
assert String.contains?(host_info, Pleroma.Web.base_url()) assert String.contains?(host_info, Pleroma.Web.Endpoint.url())
end end
end end