From 8d2d7a8859754ab4beffcc43a87218631b07f378 Mon Sep 17 00:00:00 2001 From: Thurloat Date: Tue, 28 Aug 2018 09:57:41 -0300 Subject: [PATCH] Implement uploader behaviour run formatter <# --- config/config.exs | 6 ++---- lib/pleroma/upload.ex | 9 +++++---- lib/pleroma/uploaders/local.ex | 2 +- lib/pleroma/uploaders/s3.ex | 2 +- lib/pleroma/uploaders/swift.ex | 1 + 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/config/config.exs b/config/config.exs index fe4bfe8a0..fa36209ac 100644 --- a/config/config.exs +++ b/config/config.exs @@ -14,11 +14,9 @@ config :pleroma, Pleroma.Upload, uploader: Pleroma.Uploaders.Local, strip_exif: false -config :pleroma, Pleroma.Uploaders.Local, - uploads: "uploads" +config :pleroma, Pleroma.Uploaders.Local, uploads: "uploads" -config :pleroma, Pleroma.Uploaders.S3, - s3_bucket: nil +config :pleroma, Pleroma.Uploaders.S3, s3_bucket: nil config :pleroma, :emoji, shortcode_globs: ["/emoji/custom/**/*.png"] diff --git a/lib/pleroma/upload.ex b/lib/pleroma/upload.ex index e3ad6757b..e786693ad 100644 --- a/lib/pleroma/upload.ex +++ b/lib/pleroma/upload.ex @@ -1,17 +1,17 @@ defmodule Pleroma.Upload do alias Ecto.UUID - def store(%Plug.Upload{} = file, should_dedupe) do - settings = Application.get_env(:pleroma, Pleroma.Upload) - storage_backend = Keyword.fetch!(settings, :storage_backend) + @storage_backend Application.get_env(:pleroma, Pleroma.Upload) + |> Keyword.fetch!(:uploader) + def store(%Plug.Upload{} = file, should_dedupe) do content_type = get_content_type(file.path) uuid = get_uuid(file, should_dedupe) name = get_name(file, uuid, content_type, should_dedupe) 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", @@ -25,6 +25,7 @@ defmodule Pleroma.Upload do "name" => name } end + """ # XXX: does this code actually work? i am skeptical. --kaniini def store(%{"img" => "data:image/" <> image_data}, should_dedupe) do diff --git a/lib/pleroma/uploaders/local.ex b/lib/pleroma/uploaders/local.ex index 1ba68776f..b089c8f14 100644 --- a/lib/pleroma/uploaders/local.ex +++ b/lib/pleroma/uploaders/local.ex @@ -1,9 +1,9 @@ defmodule Pleroma.Uploaders.Local do + @behaviour Pleroma.Uploaders.Uploader alias Pleroma.Web def put_file(name, uuid, file, _content_type, should_dedupe) do - upload_folder = get_upload_path(uuid, should_dedupe) url_path = get_url(name, uuid, should_dedupe) diff --git a/lib/pleroma/uploaders/s3.ex b/lib/pleroma/uploaders/s3.ex index ea9e49cbf..e18deb6b3 100644 --- a/lib/pleroma/uploaders/s3.ex +++ b/lib/pleroma/uploaders/s3.ex @@ -1,7 +1,7 @@ defmodule Pleroma.Uploaders.S3 do + @behaviour Pleroma.Uploaders.Uploader def put_file(name, uuid, path, content_type, _should_dedupe) do - settings = Application.get_env(:pleroma, Pleroma.Uploaders.S3) bucket = Keyword.fetch!(settings, :bucket) public_endpoint = Keyword.fetch!(settings, :public_endpoint) diff --git a/lib/pleroma/uploaders/swift.ex b/lib/pleroma/uploaders/swift.ex index e69de29bb..8b1378917 100644 --- a/lib/pleroma/uploaders/swift.ex +++ b/lib/pleroma/uploaders/swift.ex @@ -0,0 +1 @@ + -- 2.45.2