From 97651e88e919bcc6485d39c7a1b7ef50c29629da Mon Sep 17 00:00:00 2001 From: rustra Date: Tue, 28 Jan 2020 19:18:33 +0100 Subject: [PATCH] Implement Credo software design suggestions --- lib/federation/activity_pub/activity_pub.ex | 17 +++++++++-------- lib/federation/activity_pub/audience.ex | 7 ++++--- lib/federation/activity_pub/relay.ex | 4 +++- .../activity_stream/converter/actor.ex | 6 ++++-- .../activity_stream/converter/picture.ex | 9 ++++++--- .../activity_stream/converter/utils.ex | 6 ++++-- lib/federation/web_finger/web_finger.ex | 8 +++++--- lib/graphql/resolvers/person.ex | 8 +++++--- lib/mix/tasks/mobilizon/actors.ex | 5 ++++- lib/mix/tasks/mobilizon/users.ex | 5 ++++- lib/mobilizon.ex | 12 ++++++------ lib/mobilizon/actors/actor.ex | 6 +++--- lib/mobilizon/actors/actors.ex | 6 ++++-- lib/mobilizon/actors/follower.ex | 4 +++- lib/mobilizon/addresses/address.ex | 5 +++-- lib/mobilizon/media/media.ex | 4 +++- lib/mobilizon/reports/report.ex | 4 +++- lib/service/formatter/formatter.ex | 4 +++- lib/web/email/admin.ex | 4 ++-- lib/web/email/email.ex | 6 ++++-- lib/web/email/event.ex | 4 ++-- lib/web/email/participation.ex | 6 +++--- lib/web/email/user.ex | 6 +++--- lib/web/plugs/uploaded_media.ex | 6 ++++-- lib/web/proxy/media_proxy.ex | 10 ++++++---- lib/web/proxy/reverse_proxy.ex | 4 +++- lib/web/upload/upload.ex | 5 +++-- .../activity_pub/transmogrifier_test.exs | 6 ++++-- test/federation/web_finger/web_finger_test.exs | 6 ++++-- test/graphql/resolvers/person_test.exs | 9 +++++---- test/graphql/resolvers/picture_test.exs | 5 +++-- test/support/conn_case.ex | 4 +++- test/support/factory.ex | 5 ++--- .../activity_pub_controller_test.exs | 5 ++--- .../controllers/webfinger_controller_test.exs | 4 +++- test/web/proxy/media_proxy_test.exs | 14 +++++++------- test/web/upload/upload_test.exs | 14 +++++++------- 37 files changed, 146 insertions(+), 97 deletions(-) diff --git a/lib/federation/activity_pub/activity_pub.ex b/lib/federation/activity_pub/activity_pub.ex index d97b9d538..5bbced443 100644 --- a/lib/federation/activity_pub/activity_pub.ex +++ b/lib/federation/activity_pub/activity_pub.ex @@ -32,6 +32,7 @@ defmodule Mobilizon.Federation.ActivityPub do alias Mobilizon.GraphQL.API.Utils, as: APIUtils + alias Mobilizon.Web.Endpoint alias Mobilizon.Web.Email.{Admin, Mailer} require Logger @@ -318,7 +319,7 @@ defmodule Mobilizon.Federation.ActivityPub do Convertible.model_to_as(%{follow | actor: follower, target_actor: followed}), {:ok, follow_activity} <- create_activity(follow_as_data, local), activity_unfollow_id <- - activity_id || "#{Mobilizon.Web.Endpoint.url()}/unfollow/#{follow_id}/activity", + activity_id || "#{Endpoint.url()}/unfollow/#{follow_id}/activity", unfollow_data <- make_unfollow_data(follower, followed, follow_activity, activity_unfollow_id), {:ok, activity} <- create_activity(unfollow_data, local), @@ -483,7 +484,7 @@ defmodule Mobilizon.Federation.ActivityPub do # If it's an exclusion it should be something else "actor" => actor_url, "object" => event_url, - "id" => "#{Mobilizon.Web.Endpoint.url()}/leave/event/#{participant.id}" + "id" => "#{Endpoint.url()}/leave/event/#{participant.id}" }, audience <- Audience.calculate_to_and_cc_from_mentions(participant), @@ -778,7 +779,7 @@ defmodule Mobilizon.Federation.ActivityPub do make_accept_join_data( follower_as_data, Map.merge(additional, %{ - "id" => "#{Mobilizon.Web.Endpoint.url()}/accept/follow/#{follower.id}", + "id" => "#{Endpoint.url()}/accept/follow/#{follower.id}", "to" => [follower.actor.url], "cc" => [], "actor" => follower.target_actor.url @@ -797,7 +798,7 @@ defmodule Mobilizon.Federation.ActivityPub do defp accept_join(%Participant{} = participant, additional) do with {:ok, %Participant{} = participant} <- Events.update_participant(participant, %{role: :participant}), - Absinthe.Subscription.publish(Mobilizon.Web.Endpoint, participant.actor, + Absinthe.Subscription.publish(Endpoint, participant.actor, event_person_participation_changed: participant.actor.id ), participant_as_data <- Convertible.model_to_as(participant), @@ -807,7 +808,7 @@ defmodule Mobilizon.Federation.ActivityPub do make_accept_join_data( participant_as_data, Map.merge(Map.merge(audience, additional), %{ - "id" => "#{Mobilizon.Web.Endpoint.url()}/accept/join/#{participant.id}" + "id" => "#{Endpoint.url()}/accept/join/#{participant.id}" }) ) do {:ok, participant, update_data} @@ -823,7 +824,7 @@ defmodule Mobilizon.Federation.ActivityPub do defp reject_join(%Participant{} = participant, additional) do with {:ok, %Participant{} = participant} <- Events.update_participant(participant, %{approved: false, role: :rejected}), - Absinthe.Subscription.publish(Mobilizon.Web.Endpoint, participant.actor, + Absinthe.Subscription.publish(Endpoint, participant.actor, event_person_participation_changed: participant.actor.id ), participant_as_data <- Convertible.model_to_as(participant), @@ -839,7 +840,7 @@ defmodule Mobilizon.Federation.ActivityPub do reject_data |> Map.merge(audience) |> Map.merge(%{ - "id" => "#{Mobilizon.Web.Endpoint.url()}/reject/join/#{participant.id}" + "id" => "#{Endpoint.url()}/reject/join/#{participant.id}" }) do {:ok, participant, update_data} else @@ -866,7 +867,7 @@ defmodule Mobilizon.Federation.ActivityPub do reject_data |> Map.merge(audience) |> Map.merge(%{ - "id" => "#{Mobilizon.Web.Endpoint.url()}/reject/follow/#{follower.id}" + "id" => "#{Endpoint.url()}/reject/follow/#{follower.id}" }) do {:ok, follower, update_data} else diff --git a/lib/federation/activity_pub/audience.ex b/lib/federation/activity_pub/audience.ex index 7f7566865..d8992f2b8 100644 --- a/lib/federation/activity_pub/audience.ex +++ b/lib/federation/activity_pub/audience.ex @@ -7,6 +7,7 @@ defmodule Mobilizon.Federation.ActivityPub.Audience do alias Mobilizon.Actors.Actor alias Mobilizon.Events.{Comment, Event, Participant} alias Mobilizon.Share + alias Mobilizon.Storage.Repo require Logger @@ -108,7 +109,7 @@ defmodule Mobilizon.Federation.ActivityPub.Audience do end def calculate_to_and_cc_from_mentions(%Participant{} = participant) do - participant = Mobilizon.Storage.Repo.preload(participant, [:actor, :event]) + participant = Repo.preload(participant, [:actor, :event]) actor_participants_urls = participant.event.id @@ -132,13 +133,13 @@ defmodule Mobilizon.Federation.ActivityPub.Audience do defp add_event_author(nil), do: [] defp add_event_author(%Event{} = event) do - [Mobilizon.Storage.Repo.preload(event, [:organizer_actor]).organizer_actor.url] + [Repo.preload(event, [:organizer_actor]).organizer_actor.url] end defp add_comment_author(nil), do: nil defp add_comment_author(%Comment{} = comment) do - case Mobilizon.Storage.Repo.preload(comment, [:actor]) do + case Repo.preload(comment, [:actor]) do %Comment{actor: %Actor{url: url}} -> url diff --git a/lib/federation/activity_pub/relay.ex b/lib/federation/activity_pub/relay.ex index 800fe98d2..682a498a6 100644 --- a/lib/federation/activity_pub/relay.ex +++ b/lib/federation/activity_pub/relay.ex @@ -17,6 +17,8 @@ defmodule Mobilizon.Federation.ActivityPub.Relay do alias Mobilizon.GraphQL.API.Follows + alias Mobilizon.Web.Endpoint + require Logger def init() do @@ -28,7 +30,7 @@ defmodule Mobilizon.Federation.ActivityPub.Relay do @spec get_actor() :: Actor.t() | {:error, Ecto.Changeset.t()} def get_actor do with {:ok, %Actor{} = actor} <- - Actors.get_or_create_instance_actor_by_url("#{Mobilizon.Web.Endpoint.url()}/relay") do + Actors.get_or_create_instance_actor_by_url("#{Endpoint.url()}/relay") do actor end end diff --git a/lib/federation/activity_stream/converter/actor.ex b/lib/federation/activity_stream/converter/actor.ex index f3bcf00a6..17c04880b 100644 --- a/lib/federation/activity_stream/converter/actor.ex +++ b/lib/federation/activity_stream/converter/actor.ex @@ -11,6 +11,8 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Actor do alias Mobilizon.Federation.ActivityPub.Utils alias Mobilizon.Federation.ActivityStream.{Converter, Convertible} + alias Mobilizon.Web.MediaProxy + @behaviour Converter defimpl Convertible, for: ActorModel do @@ -29,14 +31,14 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Actor do data["icon"]["url"] && %{ "name" => data["icon"]["name"] || "avatar", - "url" => Mobilizon.Web.MediaProxy.url(data["icon"]["url"]) + "url" => MediaProxy.url(data["icon"]["url"]) } banner = data["image"]["url"] && %{ "name" => data["image"]["name"] || "banner", - "url" => Mobilizon.Web.MediaProxy.url(data["image"]["url"]) + "url" => MediaProxy.url(data["image"]["url"]) } actor_data = %{ diff --git a/lib/federation/activity_stream/converter/picture.ex b/lib/federation/activity_stream/converter/picture.ex index 6fdc01736..fc7d69792 100644 --- a/lib/federation/activity_stream/converter/picture.ex +++ b/lib/federation/activity_stream/converter/picture.ex @@ -6,8 +6,11 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Picture do internal one, and back. """ + alias Mobilizon.Media alias Mobilizon.Media.Picture, as: PictureModel + alias Mobilizon.Web.Upload + @doc """ Convert a picture struct to an ActivityStream representation. """ @@ -34,9 +37,9 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Picture do when is_bitstring(picture_url) do with {:ok, %HTTPoison.Response{body: body}} <- HTTPoison.get(picture_url), {:ok, %{name: name, url: url, content_type: content_type, size: size}} <- - Mobilizon.Web.Upload.store(%{body: body, name: name}), - {:picture_exists, nil} <- {:picture_exists, Mobilizon.Media.get_picture_by_url(url)} do - Mobilizon.Media.create_picture(%{ + Upload.store(%{body: body, name: name}), + {:picture_exists, nil} <- {:picture_exists, Media.get_picture_by_url(url)} do + Media.create_picture(%{ "file" => %{ "url" => url, "name" => name, diff --git a/lib/federation/activity_stream/converter/utils.ex b/lib/federation/activity_stream/converter/utils.ex index 7cd7203d2..a47cc6f79 100644 --- a/lib/federation/activity_stream/converter/utils.ex +++ b/lib/federation/activity_stream/converter/utils.ex @@ -11,6 +11,8 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Utils do alias Mobilizon.Federation.ActivityPub + alias Mobilizon.Web.Endpoint + require Logger @spec fetch_tags([String.t()]) :: [Tag.t()] @@ -40,7 +42,7 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Utils do def build_tags(tags) do Enum.map(tags, fn %Tag{} = tag -> %{ - "href" => Mobilizon.Web.Endpoint.url() <> "/tags/#{tag.slug}", + "href" => Endpoint.url() <> "/tags/#{tag.slug}", "name" => "##{tag.title}", "type" => "Hashtag" } @@ -60,7 +62,7 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Utils do defp build_mention(%Actor{} = actor) do %{ "href" => actor.url, - "name" => "@#{Mobilizon.Actors.Actor.preferred_username_and_domain(actor)}", + "name" => "@#{Actor.preferred_username_and_domain(actor)}", "type" => "Mention" } end diff --git a/lib/federation/web_finger/web_finger.ex b/lib/federation/web_finger/web_finger.ex index 1aec9a27a..4f3d28599 100644 --- a/lib/federation/web_finger/web_finger.ex +++ b/lib/federation/web_finger/web_finger.ex @@ -13,11 +13,13 @@ defmodule Mobilizon.Federation.WebFinger do alias Mobilizon.Federation.WebFinger.XmlBuilder + alias Mobilizon.Web.Endpoint + require Jason require Logger def host_meta do - base_url = Mobilizon.Web.Endpoint.url() + base_url = Endpoint.url() { :XRD, @@ -35,7 +37,7 @@ defmodule Mobilizon.Federation.WebFinger do end def webfinger(resource, "JSON") do - host = Mobilizon.Web.Endpoint.host() + host = Endpoint.host() regex = ~r/(acct:)?(?\w+)@#{host}/ with %{"name" => name} <- Regex.named_captures(regex, resource), @@ -59,7 +61,7 @@ defmodule Mobilizon.Federation.WebFinger do @spec represent_actor(Actor.t(), String.t()) :: struct() def represent_actor(actor, "JSON") do %{ - "subject" => "acct:#{actor.preferred_username}@#{Mobilizon.Web.Endpoint.host()}", + "subject" => "acct:#{actor.preferred_username}@#{Endpoint.host()}", "aliases" => [actor.url], "links" => [ %{"rel" => "self", "type" => "application/activity+json", "href" => actor.url}, diff --git a/lib/graphql/resolvers/person.ex b/lib/graphql/resolvers/person.ex index b16a1f76d..899c996ca 100644 --- a/lib/graphql/resolvers/person.ex +++ b/lib/graphql/resolvers/person.ex @@ -12,6 +12,8 @@ defmodule Mobilizon.GraphQL.Resolvers.Person do alias Mobilizon.Federation.ActivityPub + alias Mobilizon.Web.{MediaProxy, Upload} + @doc """ Get a person """ @@ -157,7 +159,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Person do pic = args[key][:picture] with {:ok, %{name: name, url: url, content_type: content_type, size: _size}} <- - Mobilizon.Web.Upload.store(pic.file, type: key, description: pic.alt) do + Upload.store(pic.file, type: key, description: pic.alt) do Map.put(args, key, %{"name" => name, "url" => url, "mediaType" => content_type}) end else @@ -236,7 +238,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Person do @spec proxify_avatar(Actor.t()) :: Actor.t() defp proxify_avatar(%Actor{avatar: %{url: avatar_url} = avatar} = actor) do - actor |> Map.put(:avatar, avatar |> Map.put(:url, Mobilizon.Web.MediaProxy.url(avatar_url))) + actor |> Map.put(:avatar, avatar |> Map.put(:url, MediaProxy.url(avatar_url))) end @spec proxify_avatar(Actor.t()) :: Actor.t() @@ -244,7 +246,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Person do @spec proxify_banner(Actor.t()) :: Actor.t() defp proxify_banner(%Actor{banner: %{url: banner_url} = banner} = actor) do - actor |> Map.put(:banner, banner |> Map.put(:url, Mobilizon.Web.MediaProxy.url(banner_url))) + actor |> Map.put(:banner, banner |> Map.put(:url, MediaProxy.url(banner_url))) end @spec proxify_banner(Actor.t()) :: Actor.t() diff --git a/lib/mix/tasks/mobilizon/actors.ex b/lib/mix/tasks/mobilizon/actors.ex index ec032daa2..1e3bb1ce2 100644 --- a/lib/mix/tasks/mobilizon/actors.ex +++ b/lib/mix/tasks/mobilizon/actors.ex @@ -2,13 +2,16 @@ defmodule Mix.Tasks.Mobilizon.Actors do @moduledoc """ Tasks to manage actors """ + use Mix.Task + alias Mix.Tasks + @shortdoc "Manages Mobilizon actors" @impl Mix.Task def run(_) do Mix.shell().info("\nAvailable tasks:") - Mix.Tasks.Help.run(["--search", "mobilizon.actors."]) + Tasks.Help.run(["--search", "mobilizon.actors."]) end end diff --git a/lib/mix/tasks/mobilizon/users.ex b/lib/mix/tasks/mobilizon/users.ex index 6365b5519..e61a4e77a 100644 --- a/lib/mix/tasks/mobilizon/users.ex +++ b/lib/mix/tasks/mobilizon/users.ex @@ -2,13 +2,16 @@ defmodule Mix.Tasks.Mobilizon.Users do @moduledoc """ Tasks to manage users """ + use Mix.Task + alias Mix.Tasks + @shortdoc "Manages Mobilizon users" @impl Mix.Task def run(_) do Mix.shell().info("\nAvailable tasks:") - Mix.Tasks.Help.run(["--search", "mobilizon.users."]) + Tasks.Help.run(["--search", "mobilizon.users."]) end end diff --git a/lib/mobilizon.ex b/lib/mobilizon.ex index b5f0589b6..1cd2529c8 100644 --- a/lib/mobilizon.ex +++ b/lib/mobilizon.ex @@ -14,7 +14,7 @@ defmodule Mobilizon do import Cachex.Spec - alias Mobilizon.Config + alias Mobilizon.{Config, Storage, Web} alias Mobilizon.Federation.ActivityPub alias Mobilizon.Service.Export.{Feed, ICalendar} @@ -26,7 +26,7 @@ defmodule Mobilizon do @spec user_agent :: String.t() def user_agent do - info = "#{Mobilizon.Web.Endpoint.url()} <#{Config.get([:instance, :email], "")}>" + info = "#{Web.Endpoint.url()} <#{Config.get([:instance, :email], "")}>" "#{named_version()}; #{info}" end @@ -36,9 +36,9 @@ defmodule Mobilizon do def start(_type, _args) do children = [ # supervisors - Mobilizon.Storage.Repo, - Mobilizon.Web.Endpoint, - {Absinthe.Subscription, [Mobilizon.Web.Endpoint]}, + Storage.Repo, + Web.Endpoint, + {Absinthe.Subscription, [Web.Endpoint]}, {Oban, Application.get_env(:mobilizon, Oban)}, # workers Guardian.DB.Token.SweeperServer, @@ -55,7 +55,7 @@ defmodule Mobilizon do @spec config_change(keyword, keyword, [atom]) :: :ok def config_change(changed, _new, removed) do - Mobilizon.Web.Endpoint.config_change(changed, removed) + Web.Endpoint.config_change(changed, removed) :ok end diff --git a/lib/mobilizon/actors/actor.ex b/lib/mobilizon/actors/actor.ex index 6857039b1..52d55790b 100644 --- a/lib/mobilizon/actors/actor.ex +++ b/lib/mobilizon/actors/actor.ex @@ -336,7 +336,7 @@ defmodule Mobilizon.Actors.Actor do |> put_change(:followers_url, build_url(username, :followers)) |> put_change(:following_url, build_url(username, :following)) |> put_change(:inbox_url, build_url(username, :inbox)) - |> put_change(:shared_inbox_url, "#{Mobilizon.Web.Endpoint.url()}/inbox") + |> put_change(:shared_inbox_url, "#{Endpoint.url()}/inbox") |> put_change(:url, build_url(username, :page)) end @@ -376,10 +376,10 @@ defmodule Mobilizon.Actors.Actor do "keys" => Crypto.generate_rsa_2048_private_key(), "preferred_username" => preferred_username, "domain" => nil, - "inbox_url" => "#{Mobilizon.Web.Endpoint.url()}/inbox", + "inbox_url" => "#{Endpoint.url()}/inbox", "followers_url" => "#{url}/followers", "following_url" => "#{url}/following", - "shared_inbox_url" => "#{Mobilizon.Web.Endpoint.url()}/inbox", + "shared_inbox_url" => "#{Endpoint.url()}/inbox", "type" => :Application } end diff --git a/lib/mobilizon/actors/actors.ex b/lib/mobilizon/actors/actors.ex index 5b43d3bc0..be0945793 100644 --- a/lib/mobilizon/actors/actors.ex +++ b/lib/mobilizon/actors/actors.ex @@ -16,6 +16,8 @@ defmodule Mobilizon.Actors do alias Mobilizon.Federation.ActivityPub + alias Mobilizon.Web.Upload + require Logger defenum(ActorType, :actor_type, [ @@ -755,7 +757,7 @@ defmodule Mobilizon.Actors do @spec safe_remove_file(String.t(), Actor.t()) :: {:ok, Actor.t()} defp safe_remove_file(url, %Actor{} = actor) do - case Mobilizon.Web.Upload.remove(url) do + case Upload.remove(url) do {:ok, _value} -> {:ok, actor} @@ -774,7 +776,7 @@ defmodule Mobilizon.Actors do with %Ecto.Changeset{changes: %{url: new_url}} <- changes[key], %{url: old_url} <- data |> Map.from_struct() |> Map.get(key), false <- new_url == old_url do - Mobilizon.Web.Upload.remove(old_url) + Upload.remove(old_url) end end end) diff --git a/lib/mobilizon/actors/follower.ex b/lib/mobilizon/actors/follower.ex index a397677d8..e77bc0154 100644 --- a/lib/mobilizon/actors/follower.ex +++ b/lib/mobilizon/actors/follower.ex @@ -9,6 +9,8 @@ defmodule Mobilizon.Actors.Follower do alias Mobilizon.Actors.Actor + alias Mobilizon.Web.Endpoint + @type t :: %__MODULE__{ approved: boolean, url: String.t(), @@ -65,6 +67,6 @@ defmodule Mobilizon.Actors.Follower do changeset |> put_change(:id, uuid) - |> put_change(:url, "#{Mobilizon.Web.Endpoint.url()}/follow/#{uuid}") + |> put_change(:url, "#{Endpoint.url()}/follow/#{uuid}") end end diff --git a/lib/mobilizon/addresses/address.ex b/lib/mobilizon/addresses/address.ex index c7a4f2fdb..5706748a6 100644 --- a/lib/mobilizon/addresses/address.ex +++ b/lib/mobilizon/addresses/address.ex @@ -9,6 +9,8 @@ defmodule Mobilizon.Addresses.Address do alias Mobilizon.Events.Event + alias Mobilizon.Web.Endpoint + @type t :: %__MODULE__{ country: String.t(), locality: String.t(), @@ -65,8 +67,7 @@ defmodule Mobilizon.Addresses.Address do @spec set_url(Ecto.Changeset.t()) :: Ecto.Changeset.t() defp set_url(%Ecto.Changeset{changes: changes} = changeset) do - url = - Map.get(changes, :url, "#{Mobilizon.Web.Endpoint.url()}/address/#{Ecto.UUID.generate()}") + url = Map.get(changes, :url, "#{Endpoint.url()}/address/#{Ecto.UUID.generate()}") put_change(changeset, :url, url) end diff --git a/lib/mobilizon/media/media.ex b/lib/mobilizon/media/media.ex index ccb336a74..549f84bd6 100644 --- a/lib/mobilizon/media/media.ex +++ b/lib/mobilizon/media/media.ex @@ -10,6 +10,8 @@ defmodule Mobilizon.Media do alias Mobilizon.Media.{File, Picture} alias Mobilizon.Storage.Repo + alias Mobilizon.Web.Upload + @doc """ Gets a single picture. """ @@ -62,7 +64,7 @@ defmodule Mobilizon.Media do Multi.new() |> Multi.delete(:picture, picture) |> Multi.run(:remove, fn _repo, %{picture: %Picture{file: %File{url: url}}} -> - Mobilizon.Web.Upload.remove(url) + Upload.remove(url) end) |> Repo.transaction() diff --git a/lib/mobilizon/reports/report.ex b/lib/mobilizon/reports/report.ex index 8aa90840c..c766c1ac5 100644 --- a/lib/mobilizon/reports/report.ex +++ b/lib/mobilizon/reports/report.ex @@ -11,6 +11,8 @@ defmodule Mobilizon.Reports.Report do alias Mobilizon.Events.{Comment, Event} alias Mobilizon.Reports.{Note, ReportStatus} + alias Mobilizon.Web.Endpoint + @type t :: %__MODULE__{ content: String.t(), status: ReportStatus.t(), @@ -71,7 +73,7 @@ defmodule Mobilizon.Reports.Report do @spec maybe_generate_url(Ecto.Changeset.t()) :: Ecto.Changeset.t() defp maybe_generate_url(%Ecto.Changeset{} = changeset) do with res when res in [:error, {:data, nil}] <- fetch_field(changeset, :url), - url <- "#{Mobilizon.Web.Endpoint.url()}/report/#{Ecto.UUID.generate()}" do + url <- "#{Endpoint.url()}/report/#{Ecto.UUID.generate()}" do put_change(changeset, :url, url) else _ -> changeset diff --git a/lib/service/formatter/formatter.ex b/lib/service/formatter/formatter.ex index 6cfc4dcea..a15b1c2b8 100644 --- a/lib/service/formatter/formatter.ex +++ b/lib/service/formatter/formatter.ex @@ -12,6 +12,8 @@ defmodule Mobilizon.Service.Formatter do alias Mobilizon.Actors.Actor alias Mobilizon.Service.Formatter.HTML + alias Mobilizon.Web.Endpoint + @link_regex ~r"((?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~%:/?#[\]@!\$&'\(\)\*\+,;=.]+)|[0-9a-z+\-\.]+:[0-9a-z$-_.+!*'(),]+"ui @markdown_characters_regex ~r/(`|\*|_|{|}|[|]|\(|\)|#|\+|-|\.|!)/ @@ -52,7 +54,7 @@ defmodule Mobilizon.Service.Formatter do def hashtag_handler("#" <> tag = tag_text, _buffer, _opts, acc) do tag = String.downcase(tag) - url = "#{Mobilizon.Web.Endpoint.url()}/tag/#{tag}" + url = "#{Endpoint.url()}/tag/#{tag}" link = "" {link, %{acc | tags: MapSet.put(acc.tags, {tag_text, tag})}} diff --git a/lib/web/email/admin.ex b/lib/web/email/admin.ex index b17349471..00268acc8 100644 --- a/lib/web/email/admin.ex +++ b/lib/web/email/admin.ex @@ -13,11 +13,11 @@ defmodule Mobilizon.Web.Email.Admin do alias Mobilizon.Reports.Report alias Mobilizon.Users.User - alias Mobilizon.Web.Email + alias Mobilizon.Web.{Email, Gettext} @spec report(User.t(), Report.t(), String.t()) :: Bamboo.Email.t() def report(%User{email: email}, %Report{} = report, locale \\ "en") do - Mobilizon.Web.Gettext.put_locale(locale) + Gettext.put_locale(locale) subject = gettext( diff --git a/lib/web/email/email.ex b/lib/web/email/email.ex index c0e1b788c..f61395bba 100644 --- a/lib/web/email/email.ex +++ b/lib/web/email/email.ex @@ -7,6 +7,8 @@ defmodule Mobilizon.Web.Email do alias Mobilizon.Config + alias Mobilizon.Web.EmailView + @spec base_email(keyword()) :: Bamboo.Email.t() def base_email(args) do instance = Config.instance_config() @@ -16,7 +18,7 @@ defmodule Mobilizon.Web.Email do |> from({Config.instance_name(), Config.instance_email_from()}) |> put_header("Reply-To", Config.instance_email_reply_to()) |> assign(:instance, instance) - |> put_html_layout({Mobilizon.Web.EmailView, "email.html"}) - |> put_text_layout({Mobilizon.Web.EmailView, "email.text"}) + |> put_html_layout({EmailView, "email.html"}) + |> put_text_layout({EmailView, "email.text"}) end end diff --git a/lib/web/email/event.ex b/lib/web/email/event.ex index 3b8150e0b..ee069b564 100644 --- a/lib/web/email/event.ex +++ b/lib/web/email/event.ex @@ -15,7 +15,7 @@ defmodule Mobilizon.Web.Email.Event do alias Mobilizon.Storage.Repo alias Mobilizon.Users.User - alias Mobilizon.Web.Email + alias Mobilizon.Web.{Gettext, Email} @important_changes [:title, :begins_on, :ends_on, :status] @@ -29,7 +29,7 @@ defmodule Mobilizon.Web.Email.Event do changes, locale \\ "en" ) do - Mobilizon.Web.Gettext.put_locale(locale) + Gettext.put_locale(locale) subject = gettext( diff --git a/lib/web/email/participation.ex b/lib/web/email/participation.ex index df9096ccc..83464dd2c 100644 --- a/lib/web/email/participation.ex +++ b/lib/web/email/participation.ex @@ -13,7 +13,7 @@ defmodule Mobilizon.Web.Email.Participation do alias Mobilizon.Actors.Actor alias Mobilizon.Events.Participant - alias Mobilizon.Web.Email + alias Mobilizon.Web.{Email, Gettext} @doc """ Send emails to local user @@ -46,7 +46,7 @@ defmodule Mobilizon.Web.Email.Participation do %Participant{event: event, role: :rejected}, locale ) do - Mobilizon.Web.Gettext.put_locale(locale) + Gettext.put_locale(locale) subject = gettext( @@ -67,7 +67,7 @@ defmodule Mobilizon.Web.Email.Participation do %Participant{event: event, role: :participant}, locale ) do - Mobilizon.Web.Gettext.put_locale(locale) + Gettext.put_locale(locale) subject = gettext( diff --git a/lib/web/email/user.ex b/lib/web/email/user.ex index de6091d63..33b04621e 100644 --- a/lib/web/email/user.ex +++ b/lib/web/email/user.ex @@ -13,7 +13,7 @@ defmodule Mobilizon.Web.Email.User do alias Mobilizon.Storage.Repo alias Mobilizon.Users.User - alias Mobilizon.Web.Email + alias Mobilizon.Web.{Email, Gettext} require Logger @@ -22,7 +22,7 @@ defmodule Mobilizon.Web.Email.User do %User{email: email, confirmation_token: confirmation_token}, locale \\ "en" ) do - Mobilizon.Web.Gettext.put_locale(locale) + Gettext.put_locale(locale) subject = gettext( @@ -42,7 +42,7 @@ defmodule Mobilizon.Web.Email.User do %User{email: email, reset_password_token: reset_password_token}, locale \\ "en" ) do - Mobilizon.Web.Gettext.put_locale(locale) + Gettext.put_locale(locale) subject = gettext( diff --git a/lib/web/plugs/uploaded_media.ex b/lib/web/plugs/uploaded_media.ex index 53b9e43a5..7f592aa02 100644 --- a/lib/web/plugs/uploaded_media.ex +++ b/lib/web/plugs/uploaded_media.ex @@ -14,6 +14,8 @@ defmodule Mobilizon.Web.Plugs.UploadedMedia do alias Mobilizon.Config + alias Mobilizon.Web.{ReverseProxy, Upload} + require Logger # no slashes @@ -41,7 +43,7 @@ defmodule Mobilizon.Web.Plugs.UploadedMedia do conn end - config = Config.get([Mobilizon.Web.Upload]) + config = Config.get([Upload]) with uploader <- Keyword.fetch!(config, :uploader), proxy_remote = Keyword.get(config, :proxy_remote, false), @@ -76,7 +78,7 @@ defmodule Mobilizon.Web.Plugs.UploadedMedia do end defp get_media(conn, {:url, url}, true, _) do - Mobilizon.Web.ReverseProxy.call(conn, url, Config.get([Mobilizon.Upload, :proxy_opts], [])) + ReverseProxy.call(conn, url, Config.get([Mobilizon.Upload, :proxy_opts], [])) end defp get_media(conn, {:url, url}, _, _) do diff --git a/lib/web/proxy/media_proxy.ex b/lib/web/proxy/media_proxy.ex index 35611c844..7fbd9d59b 100644 --- a/lib/web/proxy/media_proxy.ex +++ b/lib/web/proxy/media_proxy.ex @@ -10,6 +10,8 @@ defmodule Mobilizon.Web.MediaProxy do alias Mobilizon.Config + alias Mobilizon.Web.Endpoint + @base64_opts [padding: false] def url(nil), do: nil @@ -22,7 +24,7 @@ defmodule Mobilizon.Web.MediaProxy do config = Application.get_env(:mobilizon, :media_proxy, []) if !Keyword.get(config, :enabled, false) or - String.starts_with?(url, Mobilizon.Web.Endpoint.url()) do + String.starts_with?(url, Endpoint.url()) do url else encode_url(url) @@ -30,7 +32,7 @@ defmodule Mobilizon.Web.MediaProxy do end def encode_url(url) do - secret = Application.get_env(:mobilizon, Mobilizon.Web.Endpoint)[:secret_key_base] + secret = Application.get_env(:mobilizon, Endpoint)[:secret_key_base] # Must preserve `%2F` for compatibility with S3 # https://git.pleroma.social/pleroma/pleroma/issues/580 @@ -52,7 +54,7 @@ defmodule Mobilizon.Web.MediaProxy do end def decode_url(sig, url) do - secret = Application.get_env(:mobilizon, Mobilizon.Web.Endpoint)[:secret_key_base] + secret = Application.get_env(:mobilizon, Endpoint)[:secret_key_base] sig = Base.url_decode64!(sig, @base64_opts) local_sig = :crypto.hmac(:sha, secret, url) @@ -69,7 +71,7 @@ defmodule Mobilizon.Web.MediaProxy do def build_url(sig_base64, url_base64, filename \\ nil) do [ - Config.get([:media_proxy, :base_url], Mobilizon.Web.Endpoint.url()), + Config.get([:media_proxy, :base_url], Endpoint.url()), "proxy", sig_base64, url_base64, diff --git a/lib/web/proxy/reverse_proxy.ex b/lib/web/proxy/reverse_proxy.ex index f0f68c08b..46a488ccb 100644 --- a/lib/web/proxy/reverse_proxy.ex +++ b/lib/web/proxy/reverse_proxy.ex @@ -69,6 +69,8 @@ defmodule Mobilizon.Web.ReverseProxy do alias Plug.Conn + alias Mobilizon.Web.MediaProxy + require Logger @type option :: @@ -111,7 +113,7 @@ defmodule Mobilizon.Web.ReverseProxy do req_headers = build_req_headers(conn.req_headers, opts) opts = - if filename = Mobilizon.Web.MediaProxy.filename(url) do + if filename = MediaProxy.filename(url) do Keyword.put_new(opts, :attachment_name, filename) else opts diff --git a/lib/web/upload/upload.ex b/lib/web/upload/upload.ex index ae2845d7b..bfb636aaa 100644 --- a/lib/web/upload/upload.ex +++ b/lib/web/upload/upload.ex @@ -36,6 +36,7 @@ defmodule Mobilizon.Web.Upload do alias Mobilizon.Config + alias Mobilizon.Web.Endpoint alias Mobilizon.Web.Upload.{Filter, MIME, Uploader} require Logger @@ -91,7 +92,7 @@ defmodule Mobilizon.Web.Upload do def remove(url, opts \\ []) do with opts <- get_opts(opts), %URI{path: "/media/" <> path, host: host} <- URI.parse(url), - {:same_host, true} <- {:same_host, host == Mobilizon.Web.Endpoint.host()} do + {:same_host, true} <- {:same_host, host == Endpoint.host()} do Uploader.remove_file(opts.uploader, path) else %URI{} = _uri -> @@ -129,7 +130,7 @@ defmodule Mobilizon.Web.Upload do Keyword.get( opts, :base_url, - Config.get([__MODULE__, :base_url], Mobilizon.Web.Endpoint.url()) + Config.get([__MODULE__, :base_url], Endpoint.url()) ) } end diff --git a/test/federation/activity_pub/transmogrifier_test.exs b/test/federation/activity_pub/transmogrifier_test.exs index f2f57be3e..fd65c52ea 100644 --- a/test/federation/activity_pub/transmogrifier_test.exs +++ b/test/federation/activity_pub/transmogrifier_test.exs @@ -22,6 +22,8 @@ defmodule Mobilizon.Federation.ActivityPub.TransmogrifierTest do alias Mobilizon.GraphQL.API + alias Mobilizon.Web.Endpoint + setup_all do HTTPoison.start() end @@ -961,7 +963,7 @@ defmodule Mobilizon.Federation.ActivityPub.TransmogrifierTest do } expected_tag = %{ - "href" => Mobilizon.Web.Endpoint.url() <> "/tags/2hu", + "href" => Endpoint.url() <> "/tags/2hu", "type" => "Hashtag", "name" => "#2hu" } @@ -996,7 +998,7 @@ defmodule Mobilizon.Federation.ActivityPub.TransmogrifierTest do {:ok, activity, _} = API.Comments.create_comment(%{actor_id: actor.id, text: "#2hu"}) expected_tag = %{ - "href" => Mobilizon.Web.Endpoint.url() <> "/tags/2hu", + "href" => Endpoint.url() <> "/tags/2hu", "type" => "Hashtag", "name" => "#2hu" } diff --git a/test/federation/web_finger/web_finger_test.exs b/test/federation/web_finger/web_finger_test.exs index a995c4d39..6aba2c594 100644 --- a/test/federation/web_finger/web_finger_test.exs +++ b/test/federation/web_finger/web_finger_test.exs @@ -11,6 +11,8 @@ defmodule Mobilizon.Federation.WebFingerTest do alias Mobilizon.Federation.WebFinger + alias Mobilizon.Web.Endpoint + @mastodon_account "tcit@social.tcit.fr" @mastodon_account_username "tcit" @pleroma_account "lain@pleroma.soykaf.com" @@ -24,7 +26,7 @@ defmodule Mobilizon.Federation.WebFingerTest do test "returns a link to the xml lrdd" do host_info = WebFinger.host_meta() - assert String.contains?(host_info, Mobilizon.Web.Endpoint.url()) + assert String.contains?(host_info, Endpoint.url()) end end @@ -34,7 +36,7 @@ defmodule Mobilizon.Federation.WebFingerTest do {:ok, result} = WebFinger.webfinger( - "#{actor.preferred_username}@#{Mobilizon.Web.Endpoint.host()}", + "#{actor.preferred_username}@#{Endpoint.host()}", "JSON" ) diff --git a/test/graphql/resolvers/person_test.exs b/test/graphql/resolvers/person_test.exs index 200944263..1f576c684 100644 --- a/test/graphql/resolvers/person_test.exs +++ b/test/graphql/resolvers/person_test.exs @@ -9,6 +9,8 @@ defmodule Mobilizon.GraphQL.Resolvers.PersonTest do alias Mobilizon.GraphQL.AbsintheHelpers + alias Mobilizon.Web.Endpoint + @non_existent_username "nonexistent" describe "Person Resolver" do @@ -120,8 +122,7 @@ defmodule Mobilizon.GraphQL.Resolvers.PersonTest do assert json_response(res, 200)["data"]["loggedPerson"]["preferredUsername"] == actor.preferred_username - assert json_response(res, 200)["data"]["loggedPerson"]["avatar"]["url"] =~ - Mobilizon.Web.Endpoint.url() + assert json_response(res, 200)["data"]["loggedPerson"]["avatar"]["url"] =~ Endpoint.url() end test "create_person/3 creates a new identity", context do @@ -255,7 +256,7 @@ defmodule Mobilizon.GraphQL.Resolvers.PersonTest do "The beautiful atlantic way" assert json_response(res, 200)["data"]["createPerson"]["banner"]["url"] =~ - Mobilizon.Web.Endpoint.url() <> "/media/" + Endpoint.url() <> "/media/" end test "update_person/3 updates an existing identity", context do @@ -325,7 +326,7 @@ defmodule Mobilizon.GraphQL.Resolvers.PersonTest do assert res_person["banner"]["id"] assert res_person["banner"]["name"] == "The beautiful atlantic way" - assert res_person["banner"]["url"] =~ Mobilizon.Web.Endpoint.url() <> "/media/" + assert res_person["banner"]["url"] =~ Endpoint.url() <> "/media/" end test "update_person/3 should fail to update a not owned identity", context do diff --git a/test/graphql/resolvers/picture_test.exs b/test/graphql/resolvers/picture_test.exs index b2a61538e..c4ab3858d 100644 --- a/test/graphql/resolvers/picture_test.exs +++ b/test/graphql/resolvers/picture_test.exs @@ -8,6 +8,8 @@ defmodule Mobilizon.GraphQL.Resolvers.PictureTest do alias Mobilizon.GraphQL.AbsintheHelpers + alias Mobilizon.Web.Endpoint + setup %{conn: conn} do user = insert(:user) actor = insert(:actor, user: user) @@ -42,8 +44,7 @@ defmodule Mobilizon.GraphQL.Resolvers.PictureTest do assert json_response(res, 200)["data"]["picture"]["size"] == 13_120 - assert json_response(res, 200)["data"]["picture"]["url"] =~ - Mobilizon.Web.Endpoint.url() + assert json_response(res, 200)["data"]["picture"]["url"] =~ Endpoint.url() end test "picture/3 returns nothing on a non-existent picture", context do diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex index ee76c8fa9..8b1862108 100644 --- a/test/support/conn_case.ex +++ b/test/support/conn_case.ex @@ -20,6 +20,8 @@ defmodule Mobilizon.Web.ConnCase do alias Mobilizon.Storage.Repo alias Mobilizon.Users.User + alias Mobilizon.Web.Auth + using do quote do # Import conveniences for testing with connections @@ -30,7 +32,7 @@ defmodule Mobilizon.Web.ConnCase do @endpoint Mobilizon.Web.Endpoint def auth_conn(%Plug.Conn{} = conn, %User{} = user) do - {:ok, token, _claims} = Mobilizon.Web.Auth.Guardian.encode_and_sign(user) + {:ok, token, _claims} = Auth.Guardian.encode_and_sign(user) conn |> Plug.Conn.put_req_header("authorization", "Bearer #{token}") diff --git a/test/support/factory.ex b/test/support/factory.ex index 00674c50e..87bd5f935 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -8,9 +8,8 @@ defmodule Mobilizon.Factory do alias Mobilizon.Actors.Actor alias Mobilizon.Crypto - alias Mobilizon.Web.Endpoint + alias Mobilizon.Web.{Endpoint, Upload} alias Mobilizon.Web.Router.Helpers, as: Routes - alias Mobilizon.Web.Upload def user_factory do %Mobilizon.Users.User{ @@ -60,7 +59,7 @@ defmodule Mobilizon.Factory do target_actor: build(:actor), actor: build(:actor), id: uuid, - url: "#{Mobilizon.Web.Endpoint.url()}/follows/#{uuid}" + url: "#{Endpoint.url()}/follows/#{uuid}" } end diff --git a/test/web/controllers/activity_pub_controller_test.exs b/test/web/controllers/activity_pub_controller_test.exs index bd4ad85f9..8de6fa884 100644 --- a/test/web/controllers/activity_pub_controller_test.exs +++ b/test/web/controllers/activity_pub_controller_test.exs @@ -16,8 +16,7 @@ defmodule Mobilizon.Web.ActivityPubControllerTest do alias Mobilizon.Federation.ActivityPub alias Mobilizon.Web.ActivityPub.ActorView - alias Mobilizon.Web.Endpoint - alias Mobilizon.Web.PageView + alias Mobilizon.Web.{Endpoint, PageView} alias Mobilizon.Web.Router.Helpers, as: Routes setup_all do @@ -104,7 +103,7 @@ defmodule Mobilizon.Web.ActivityPubControllerTest do conn = conn |> assign(:valid_signature, true) - |> post("#{Mobilizon.Web.Endpoint.url()}/inbox", data) + |> post("#{Endpoint.url()}/inbox", data) assert "ok" == json_response(conn, 200) :timer.sleep(500) diff --git a/test/web/controllers/webfinger_controller_test.exs b/test/web/controllers/webfinger_controller_test.exs index 03a26b6c6..5d407bdbe 100644 --- a/test/web/controllers/webfinger_controller_test.exs +++ b/test/web/controllers/webfinger_controller_test.exs @@ -11,6 +11,8 @@ defmodule Mobilizon.Web.WebFingerControllerTest do alias Mobilizon.Actors.Actor alias Mobilizon.Federation.WebFinger + alias Mobilizon.Web.Endpoint + setup_all do Mobilizon.Config.put([:instance, :federating], true) @@ -22,7 +24,7 @@ defmodule Mobilizon.Web.WebFingerControllerTest do assert response(conn, 200) == "" assert {"content-type", "application/xrd+xml; charset=utf-8"} in conn.resp_headers diff --git a/test/web/proxy/media_proxy_test.exs b/test/web/proxy/media_proxy_test.exs index 60363db66..ced609d9f 100644 --- a/test/web/proxy/media_proxy_test.exs +++ b/test/web/proxy/media_proxy_test.exs @@ -10,7 +10,7 @@ defmodule Mobilizon.Web.MediaProxyTest do alias Mobilizon.Config - alias Mobilizon.Web.MediaProxyController + alias Mobilizon.Web.{Endpoint, MediaProxyController} setup do enabled = Config.get([:media_proxy, :enabled]) @@ -35,8 +35,8 @@ defmodule Mobilizon.Web.MediaProxyTest do end test "ignores local url" do - local_url = Mobilizon.Web.Endpoint.url() <> "/hello" - local_root = Mobilizon.Web.Endpoint.url() + local_url = Endpoint.url() <> "/hello" + local_root = Endpoint.url() assert url(local_url) == local_url assert url(local_root) == local_root end @@ -47,7 +47,7 @@ defmodule Mobilizon.Web.MediaProxyTest do assert String.starts_with?( encoded, - Config.get([:media_proxy, :base_url], Mobilizon.Web.Endpoint.url()) + Config.get([:media_proxy, :base_url], Endpoint.url()) ) assert String.ends_with?(encoded, "/logo.png") @@ -84,16 +84,16 @@ defmodule Mobilizon.Web.MediaProxyTest do end test "validates signature" do - secret_key_base = Config.get([Mobilizon.Web.Endpoint, :secret_key_base]) + secret_key_base = Config.get([Endpoint, :secret_key_base]) on_exit(fn -> - Config.put([Mobilizon.Web.Endpoint, :secret_key_base], secret_key_base) + Config.put([Endpoint, :secret_key_base], secret_key_base) end) encoded = url("https://pleroma.social") Config.put( - [Mobilizon.Web.Endpoint, :secret_key_base], + [Endpoint, :secret_key_base], "00000000000000000000000000000000000000000000000" ) diff --git a/test/web/upload/upload_test.exs b/test/web/upload/upload_test.exs index b2845a929..f5cc995be 100644 --- a/test/web/upload/upload_test.exs +++ b/test/web/upload/upload_test.exs @@ -8,7 +8,7 @@ defmodule Mobilizon.UploadTest do alias Mobilizon.Config - alias Mobilizon.Web.Upload + alias Mobilizon.Web.{Endpoint, Upload} alias Mobilizon.Web.Upload.Uploader describe "Storing a file with the Local uploader" do @@ -31,7 +31,7 @@ defmodule Mobilizon.UploadTest do size: 13_227 } = data - assert String.starts_with?(url, Mobilizon.Web.Endpoint.url() <> "/media/") + assert String.starts_with?(url, Endpoint.url() <> "/media/") end test "returns a media url with configured base_url" do @@ -59,10 +59,10 @@ defmodule Mobilizon.UploadTest do filename: "an [image.jpg" } - {:ok, data} = Upload.store(file, filters: [Mobilizon.Web.Upload.Filter.Dedupe]) + {:ok, data} = Upload.store(file, filters: [Upload.Filter.Dedupe]) assert data.url == - Mobilizon.Web.Endpoint.url() <> + Endpoint.url() <> "/media/590523d60d3831ec92d05cdd871078409d5780903910efec5cd35ab1b0f19d11.jpg" end @@ -88,7 +88,7 @@ defmodule Mobilizon.UploadTest do filename: "an [image.jpg" } - {:ok, data} = Upload.store(file, filters: [Mobilizon.Web.Upload.Filter.Dedupe]) + {:ok, data} = Upload.store(file, filters: [Upload.Filter.Dedupe]) assert data.content_type == "image/jpeg" end @@ -140,7 +140,7 @@ defmodule Mobilizon.UploadTest do filename: "an [image.jpg" } - {:ok, data} = Upload.store(file, filters: [Mobilizon.Web.Upload.Filter.AnonymizeFilename]) + {:ok, data} = Upload.store(file, filters: [Upload.Filter.AnonymizeFilename]) refute data.name == "an [image.jpg" end @@ -212,7 +212,7 @@ defmodule Mobilizon.UploadTest do content_type: "image/jpeg" } = data - assert String.starts_with?(url, Mobilizon.Web.Endpoint.url() <> "/media/") + assert String.starts_with?(url, Endpoint.url() <> "/media/") %URI{path: "/media/" <> path} = URI.parse(url) {Config.get!([Uploader.Local, :uploads]) <> "/" <> path, url}