updates
authorMaksim Pechnikov <parallel588@gmail.com>
Mon, 10 Dec 2018 06:39:57 +0000 (09:39 +0300)
committerMaksim Pechnikov <parallel588@gmail.com>
Mon, 10 Dec 2018 10:27:37 +0000 (13:27 +0300)
lib/mix/tasks/pleroma/uploads.ex
lib/pleroma/upload.ex
lib/pleroma/upload/filter/dedupe.ex
lib/pleroma/web/admin_api/admin_api_controller.ex
lib/pleroma/web/federator/retry_queue.ex
lib/pleroma/web/mastodon_api/mastodon_socket.ex
lib/pleroma/web/media_proxy/controller.ex
lib/pleroma/web/ostatus/ostatus.ex

index 45bfd254cff53db4143822ae2aab7e697d214318..c6b8401303406e795cbdc390fd67ff85ce39c6e0 100644 (file)
@@ -57,7 +57,7 @@ defmodule Mix.Tasks.Pleroma.Uploads do
 
           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 ->
index 77cba2cd2fff9bdf64c57a5dfe75a3f565559786..07031ac58527190667c731ed92131fcb38cb7646 100644 (file)
@@ -214,4 +214,6 @@ defmodule Pleroma.Upload do
     [base_url, "media", path]
     |> Path.join()
   end
+
+  defp url_from_spec(_base_url, {:url, url}), do: url
 end
index 81ddd9b295a6f6fb4fa8873b2f375950655d5cec..0657b2c8db53f0188cc7d4de255762a7c327ffc6 100644 (file)
@@ -1,10 +1,11 @@
 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
index 451a879002f4d5d83efedf07438d86bd72db8191..06c3c7c817a61c908e859254845aba44bbfc620c 100644 (file)
@@ -63,7 +63,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
     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)
index 3997d68a79146e5290435430dc45b1217bb4be08..510b4315d4fabd5b0a7a8eace29ccec041b5db42 100644 (file)
@@ -37,11 +37,11 @@ defmodule Pleroma.Web.Federator.RetryQueue do
 
   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}
index d85f2a4628176446aeba8ecee4b68a61242c78a4..755ac5730b5d7fef946e74d16b7bd08194a30802 100644 (file)
@@ -11,6 +11,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonSocket do
     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),
@@ -52,12 +53,16 @@ defmodule Pleroma.Web.MastodonAPI.MastodonSocket do
         _ -> 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
index ce4f15be0eca326bd85904514b7994bca325bddf..63140feb99a2bbce660b2fb12ac375a214c5ae59 100644 (file)
@@ -8,7 +8,6 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyController 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
@@ -31,9 +30,10 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyController do
 
     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
index 3ad2e7591273337489f84a5f519ba06f259d3b1f..c6440c20e9daa1d1248494fb201fe7aed7785b6a 100644 (file)
@@ -375,19 +375,14 @@ defmodule Pleroma.Web.OStatus do
   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