diff options
author | Thurloat <thurloat@gmail.com> | 2018-08-28 19:48:03 -0300 |
---|---|---|
committer | Thurloat <thurloat@gmail.com> | 2018-08-28 19:48:03 -0300 |
commit | dad39b24a1bca0341d5cf47cc4a32ea66219c654 (patch) | |
tree | b9be2b8b0460e65edb22e33b5893e4fdf4dd6347 /lib/pleroma/uploaders | |
parent | 8d2d7a8859754ab4beffcc43a87218631b07f378 (diff) | |
download | pleroma-dad39b24a1bca0341d5cf47cc4a32ea66219c654.tar.gz |
add the behaviour, work on actually making it work.
Diffstat (limited to 'lib/pleroma/uploaders')
-rw-r--r-- | lib/pleroma/uploaders/local.ex | 6 | ||||
-rw-r--r-- | lib/pleroma/uploaders/uploader.ex | 26 |
2 files changed, 29 insertions, 3 deletions
diff --git a/lib/pleroma/uploaders/local.ex b/lib/pleroma/uploaders/local.ex index b089c8f14..39dca49c9 100644 --- a/lib/pleroma/uploaders/local.ex +++ b/lib/pleroma/uploaders/local.ex @@ -3,7 +3,7 @@ defmodule Pleroma.Uploaders.Local do alias Pleroma.Web - def put_file(name, uuid, file, _content_type, should_dedupe) do + def put_file(name, uuid, tmpfile, _content_type, should_dedupe) do upload_folder = get_upload_path(uuid, should_dedupe) url_path = get_url(name, uuid, should_dedupe) @@ -12,9 +12,9 @@ defmodule Pleroma.Uploaders.Local do result_file = Path.join(upload_folder, name) if File.exists?(result_file) do - File.rm!(file.path) + File.rm!(tmpfile) else - File.cp!(file.path, result_file) + File.cp!(tmpfile, result_file) end url_path diff --git a/lib/pleroma/uploaders/uploader.ex b/lib/pleroma/uploaders/uploader.ex new file mode 100644 index 000000000..7380320af --- /dev/null +++ b/lib/pleroma/uploaders/uploader.ex @@ -0,0 +1,26 @@ +defmodule Pleroma.Uploaders.Uploader do + @moduledoc """ + Defines the contract to put an uploaded file to any backend. + """ + + @doc """ + Put a file to the backend. + + Returns a `String.t` containing the path of the uploaded file. + """ + @callback put_file( + name :: String.t(), + uuid :: String.t(), + file :: File.t(), + content_type :: String.t(), + should_dedupe :: Boolean.t() + ) :: String.t() + + @callback put_file( + name :: String.t(), + uuid :: String.t(), + image_data :: String.t(), + content_type :: String.t(), + should_dedupe :: String.t() + ) :: String.t() +end |