File.exists?(root_path) ->
file = Path.basename(id)
- [hash, _ext] = String.split(id, ".")
+ hash = Path.rootname(id)
{%Pleroma.Upload{id: hash, name: file, path: file, tempfile: root_path}, root_path}
true ->
[base_url, "media", path]
|> Path.join()
end
+
+ defp url_from_spec(_base_url, {:url, url}), do: url
end
defmodule Pleroma.Upload.Filter.Dedupe do
@behaviour Pleroma.Upload.Filter
+ alias Pleroma.Upload
- def filter(upload = %Pleroma.Upload{name: name, tempfile: _path}) do
+ def filter(upload = %Upload{name: name}) do
extension = String.split(name, ".") |> List.last()
shasum = :crypto.hash(:sha256, File.read!(upload.tempfile)) |> Base.encode16(case: :lower)
filename = shasum <> "." <> extension
- {:ok, %Pleroma.Upload{upload | id: shasum, path: filename}}
+ {:ok, %Upload{upload | id: shasum, path: filename}}
end
end
info_cng = User.Info.admin_api_update(user.info, info)
cng =
- Ecto.Changeset.change(user)
+ user
+ |> Ecto.Changeset.change()
|> Ecto.Changeset.put_embed(:info, info_cng)
{:ok, _user} = User.update_and_set_cache(cng)
def handle_cast({:maybe_enqueue, data, transport, retries}, %{dropped: drop_count} = state) do
case get_retry_params(retries) do
- {:retry, _timeout} ->
+ {:retry, timeout} ->
Process.send_after(
__MODULE__,
{:send, data, transport, retries},
- growth_function(retries)
+ timeout
)
{:noreply, state}
timeout: :infinity
)
+ @spec connect(params :: map(), Phoenix.Socket.t()) :: {:ok, Phoenix.Socket.t()} | :error
def connect(%{"access_token" => token} = params, socket) do
with %Token{user_id: user_id} <- Repo.get_by(Token, token: token),
%User{} = user <- Repo.get(User, user_id),
_ -> stream
end
- with socket <- assign(socket, :topic, topic) do
- Pleroma.Web.Streamer.add_socket(topic, socket)
- {:ok, socket}
- end
+ socket =
+ socket
+ |> assign(:topic, topic)
+
+ Pleroma.Web.Streamer.add_socket(topic, socket)
+ {:ok, socket}
end
+ def connect(_params, _socket), do: :error
+
def id(_), do: nil
def handle(:text, message, _state) do
with config <- Pleroma.Config.get([:media_proxy], []),
true <- Keyword.get(config, :enabled, false),
{:ok, url} <- MediaProxy.decode_url(sig64, url64),
- _filename <- Path.basename(URI.parse(url).path),
:ok <- filename_matches(Map.has_key?(params, "filename"), conn.request_path, url) do
ReverseProxy.call(conn, url, Keyword.get(config, :proxy_opts, @default_proxy_opts))
else
path = URI.decode(path)
- cond do
- has_filename && filename && Path.basename(path) != filename -> {:wrong_filename, filename}
- true -> :ok
+ if has_filename && filename && Path.basename(path) != filename do
+ {:wrong_filename, filename}
+ else
+ :ok
end
end
end
end
def fetch_activity_from_url(url) do
- try do
- with {:ok, activities} when activities != [] <- fetch_activity_from_atom_url(url) do
- {:ok, activities}
- else
- _e ->
- with {:ok, activities} <- fetch_activity_from_html_url(url) do
- {:ok, activities}
- end
- end
- rescue
- e ->
- Logger.debug("Couldn't get #{url}: #{inspect(e)}")
- {:error, "Couldn't get #{url}: #{inspect(e)}"}
+ with {:ok, [_ | _] = activities} <- fetch_activity_from_atom_url(url) do
+ {:ok, activities}
+ else
+ _e -> fetch_activity_from_html_url(url)
end
+ rescue
+ e ->
+ Logger.debug("Couldn't get #{url}: #{inspect(e)}")
+ {:error, "Couldn't get #{url}: #{inspect(e)}"}
end
end