Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into pleroma-ipfs_uploader

This commit is contained in:
Lain Soykaf 2024-05-27 16:23:40 +04:00
commit 825b4122a5
1352 changed files with 57482 additions and 9217 deletions

View file

@ -6,7 +6,8 @@ defmodule Pleroma.Uploaders.S3 do
@behaviour Pleroma.Uploaders.Uploader
require Logger
alias Pleroma.Config
@ex_aws_impl Application.compile_env(:pleroma, [__MODULE__, :ex_aws_impl], ExAws)
@config_impl Application.compile_env(:pleroma, [__MODULE__, :config_impl], Pleroma.Config)
# The file name is re-encoded with S3's constraints here to comply with previous
# links with less strict filenames
@ -22,7 +23,7 @@ defmodule Pleroma.Uploaders.S3 do
@impl true
def put_file(%Pleroma.Upload{} = upload) do
config = Config.get([__MODULE__])
config = @config_impl.get([__MODULE__])
bucket = Keyword.get(config, :bucket)
streaming = Keyword.get(config, :streaming_enabled)
@ -56,7 +57,7 @@ defmodule Pleroma.Uploaders.S3 do
])
end
case ExAws.request(op) do
case @ex_aws_impl.request(op) do
{:ok, _} ->
{:ok, {:file, s3_name}}
@ -69,9 +70,9 @@ defmodule Pleroma.Uploaders.S3 do
@impl true
def delete_file(file) do
[__MODULE__, :bucket]
|> Config.get()
|> @config_impl.get()
|> ExAws.S3.delete_object(file)
|> ExAws.request()
|> @ex_aws_impl.request()
|> case do
{:ok, %{status_code: 204}} -> :ok
error -> {:error, inspect(error)}
@ -83,3 +84,7 @@ defmodule Pleroma.Uploaders.S3 do
String.replace(name, @regex, "-")
end
end
defmodule Pleroma.Uploaders.S3.ExAwsAPI do
@callback request(op :: ExAws.Operation.t()) :: {:ok, ExAws.Operation.t()} | {:error, term()}
end

View file

@ -5,8 +5,6 @@
defmodule Pleroma.Uploaders.Uploader do
import Pleroma.Web.Gettext
@mix_env Mix.env()
@moduledoc """
Defines the contract to put and get an uploaded file to any backend.
"""
@ -40,7 +38,7 @@ defmodule Pleroma.Uploaders.Uploader do
@callback delete_file(file :: String.t()) :: :ok | {:error, String.t()}
@callback http_callback(Plug.Conn.t(), Map.t()) ::
@callback http_callback(Plug.Conn.t(), map()) ::
{:ok, Plug.Conn.t()}
| {:ok, Plug.Conn.t(), file_spec()}
| {:error, Plug.Conn.t(), String.t()}
@ -75,10 +73,5 @@ defmodule Pleroma.Uploaders.Uploader do
end
end
defp callback_timeout do
case @mix_env do
:test -> 1_000
_ -> 30_000
end
end
defp callback_timeout, do: Application.get_env(:pleroma, __MODULE__)[:timeout]
end