forked from AkkomaGang/akkoma
updates
This commit is contained in:
parent
074fa790ba
commit
e94c3442f4
8 changed files with 31 additions and 27 deletions
|
@ -57,7 +57,7 @@ def run(["migrate_local", target_uploader | args]) do
|
||||||
|
|
||||||
File.exists?(root_path) ->
|
File.exists?(root_path) ->
|
||||||
file = Path.basename(id)
|
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}
|
{%Pleroma.Upload{id: hash, name: file, path: file, tempfile: root_path}, root_path}
|
||||||
|
|
||||||
true ->
|
true ->
|
||||||
|
|
|
@ -214,4 +214,6 @@ defp url_from_spec(base_url, {:file, path}) do
|
||||||
[base_url, "media", path]
|
[base_url, "media", path]
|
||||||
|> Path.join()
|
|> Path.join()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp url_from_spec(_base_url, {:url, url}), do: url
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
defmodule Pleroma.Upload.Filter.Dedupe do
|
defmodule Pleroma.Upload.Filter.Dedupe do
|
||||||
@behaviour Pleroma.Upload.Filter
|
@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()
|
extension = String.split(name, ".") |> List.last()
|
||||||
shasum = :crypto.hash(:sha256, File.read!(upload.tempfile)) |> Base.encode16(case: :lower)
|
shasum = :crypto.hash(:sha256, File.read!(upload.tempfile)) |> Base.encode16(case: :lower)
|
||||||
filename = shasum <> "." <> extension
|
filename = shasum <> "." <> extension
|
||||||
{:ok, %Pleroma.Upload{upload | id: shasum, path: filename}}
|
{:ok, %Upload{upload | id: shasum, path: filename}}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -63,7 +63,8 @@ def right_add(conn, %{"permission_group" => permission_group, "nickname" => nick
|
||||||
info_cng = User.Info.admin_api_update(user.info, info)
|
info_cng = User.Info.admin_api_update(user.info, info)
|
||||||
|
|
||||||
cng =
|
cng =
|
||||||
Ecto.Changeset.change(user)
|
user
|
||||||
|
|> Ecto.Changeset.change()
|
||||||
|> Ecto.Changeset.put_embed(:info, info_cng)
|
|> Ecto.Changeset.put_embed(:info, info_cng)
|
||||||
|
|
||||||
{:ok, _user} = User.update_and_set_cache(cng)
|
{:ok, _user} = User.update_and_set_cache(cng)
|
||||||
|
|
|
@ -37,11 +37,11 @@ def get_retry_params(retries) do
|
||||||
|
|
||||||
def handle_cast({:maybe_enqueue, data, transport, retries}, %{dropped: drop_count} = state) do
|
def handle_cast({:maybe_enqueue, data, transport, retries}, %{dropped: drop_count} = state) do
|
||||||
case get_retry_params(retries) do
|
case get_retry_params(retries) do
|
||||||
{:retry, _timeout} ->
|
{:retry, timeout} ->
|
||||||
Process.send_after(
|
Process.send_after(
|
||||||
__MODULE__,
|
__MODULE__,
|
||||||
{:send, data, transport, retries},
|
{:send, data, transport, retries},
|
||||||
growth_function(retries)
|
timeout
|
||||||
)
|
)
|
||||||
|
|
||||||
{:noreply, state}
|
{:noreply, state}
|
||||||
|
|
|
@ -11,6 +11,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonSocket do
|
||||||
timeout: :infinity
|
timeout: :infinity
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@spec connect(params :: map(), Phoenix.Socket.t()) :: {:ok, Phoenix.Socket.t()} | :error
|
||||||
def connect(%{"access_token" => token} = params, socket) do
|
def connect(%{"access_token" => token} = params, socket) do
|
||||||
with %Token{user_id: user_id} <- Repo.get_by(Token, token: token),
|
with %Token{user_id: user_id} <- Repo.get_by(Token, token: token),
|
||||||
%User{} = user <- Repo.get(User, user_id),
|
%User{} = user <- Repo.get(User, user_id),
|
||||||
|
@ -52,11 +53,15 @@ def connect(%{"stream" => stream} = params, socket)
|
||||||
_ -> stream
|
_ -> stream
|
||||||
end
|
end
|
||||||
|
|
||||||
with socket <- assign(socket, :topic, topic) do
|
socket =
|
||||||
|
socket
|
||||||
|
|> assign(:topic, topic)
|
||||||
|
|
||||||
Pleroma.Web.Streamer.add_socket(topic, socket)
|
Pleroma.Web.Streamer.add_socket(topic, socket)
|
||||||
{:ok, socket}
|
{:ok, socket}
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
def connect(_params, _socket), do: :error
|
||||||
|
|
||||||
def id(_), do: nil
|
def id(_), do: nil
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ def remote(conn, params = %{"sig" => sig64, "url" => url64}) do
|
||||||
with config <- Pleroma.Config.get([:media_proxy], []),
|
with config <- Pleroma.Config.get([:media_proxy], []),
|
||||||
true <- Keyword.get(config, :enabled, false),
|
true <- Keyword.get(config, :enabled, false),
|
||||||
{:ok, url} <- MediaProxy.decode_url(sig64, url64),
|
{: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
|
: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))
|
ReverseProxy.call(conn, url, Keyword.get(config, :proxy_opts, @default_proxy_opts))
|
||||||
else
|
else
|
||||||
|
@ -31,9 +30,10 @@ def filename_matches(has_filename, path, url) do
|
||||||
|
|
||||||
path = URI.decode(path)
|
path = URI.decode(path)
|
||||||
|
|
||||||
cond do
|
if has_filename && filename && Path.basename(path) != filename do
|
||||||
has_filename && filename && Path.basename(path) != filename -> {:wrong_filename, filename}
|
{:wrong_filename, filename}
|
||||||
true -> :ok
|
else
|
||||||
|
:ok
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -375,19 +375,14 @@ def fetch_activity_from_html_url(url) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_activity_from_url(url) do
|
def fetch_activity_from_url(url) do
|
||||||
try do
|
with {:ok, [_ | _] = activities} <- fetch_activity_from_atom_url(url) do
|
||||||
with {:ok, activities} when activities != [] <- fetch_activity_from_atom_url(url) do
|
|
||||||
{:ok, activities}
|
{:ok, activities}
|
||||||
else
|
else
|
||||||
_e ->
|
_e -> fetch_activity_from_html_url(url)
|
||||||
with {:ok, activities} <- fetch_activity_from_html_url(url) do
|
|
||||||
{:ok, activities}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
rescue
|
rescue
|
||||||
e ->
|
e ->
|
||||||
Logger.debug("Couldn't get #{url}: #{inspect(e)}")
|
Logger.debug("Couldn't get #{url}: #{inspect(e)}")
|
||||||
{:error, "Couldn't get #{url}: #{inspect(e)}"}
|
{:error, "Couldn't get #{url}: #{inspect(e)}"}
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue