Implement uploader behaviour

run formatter <#
This commit is contained in:
Thurloat 2018-08-28 09:57:41 -03:00
parent 0df558a6a5
commit 8d2d7a8859
5 changed files with 10 additions and 10 deletions

View File

@ -14,11 +14,9 @@ config :pleroma, Pleroma.Upload,
uploader: Pleroma.Uploaders.Local, uploader: Pleroma.Uploaders.Local,
strip_exif: false strip_exif: false
config :pleroma, Pleroma.Uploaders.Local, config :pleroma, Pleroma.Uploaders.Local, uploads: "uploads"
uploads: "uploads"
config :pleroma, Pleroma.Uploaders.S3, config :pleroma, Pleroma.Uploaders.S3, s3_bucket: nil
s3_bucket: nil
config :pleroma, :emoji, shortcode_globs: ["/emoji/custom/**/*.png"] config :pleroma, :emoji, shortcode_globs: ["/emoji/custom/**/*.png"]

View File

@ -1,17 +1,17 @@
defmodule Pleroma.Upload do defmodule Pleroma.Upload do
alias Ecto.UUID alias Ecto.UUID
def store(%Plug.Upload{} = file, should_dedupe) do @storage_backend Application.get_env(:pleroma, Pleroma.Upload)
settings = Application.get_env(:pleroma, Pleroma.Upload) |> Keyword.fetch!(:uploader)
storage_backend = Keyword.fetch!(settings, :storage_backend)
def store(%Plug.Upload{} = file, should_dedupe) do
content_type = get_content_type(file.path) content_type = get_content_type(file.path)
uuid = get_uuid(file, should_dedupe) uuid = get_uuid(file, should_dedupe)
name = get_name(file, uuid, content_type, should_dedupe) name = get_name(file, uuid, content_type, should_dedupe)
strip_exif_data(content_type, file.path) strip_exif_data(content_type, file.path)
url_path = storage_backend.put_file(name, uuid, content_type) url_path = @storage_backend.put_file(name, uuid, file, content_type, should_dedupe)
%{ %{
"type" => "Document", "type" => "Document",
@ -25,6 +25,7 @@ defmodule Pleroma.Upload do
"name" => name "name" => name
} }
end end
""" """
# XXX: does this code actually work? i am skeptical. --kaniini # XXX: does this code actually work? i am skeptical. --kaniini
def store(%{"img" => "data:image/" <> image_data}, should_dedupe) do def store(%{"img" => "data:image/" <> image_data}, should_dedupe) do

View File

@ -1,9 +1,9 @@
defmodule Pleroma.Uploaders.Local do defmodule Pleroma.Uploaders.Local do
@behaviour Pleroma.Uploaders.Uploader
alias Pleroma.Web alias Pleroma.Web
def put_file(name, uuid, file, _content_type, should_dedupe) do def put_file(name, uuid, file, _content_type, should_dedupe) do
upload_folder = get_upload_path(uuid, should_dedupe) upload_folder = get_upload_path(uuid, should_dedupe)
url_path = get_url(name, uuid, should_dedupe) url_path = get_url(name, uuid, should_dedupe)

View File

@ -1,7 +1,7 @@
defmodule Pleroma.Uploaders.S3 do defmodule Pleroma.Uploaders.S3 do
@behaviour Pleroma.Uploaders.Uploader
def put_file(name, uuid, path, content_type, _should_dedupe) do def put_file(name, uuid, path, content_type, _should_dedupe) do
settings = Application.get_env(:pleroma, Pleroma.Uploaders.S3) settings = Application.get_env(:pleroma, Pleroma.Uploaders.S3)
bucket = Keyword.fetch!(settings, :bucket) bucket = Keyword.fetch!(settings, :bucket)
public_endpoint = Keyword.fetch!(settings, :public_endpoint) public_endpoint = Keyword.fetch!(settings, :public_endpoint)

View File

@ -0,0 +1 @@