1 defmodule Pleroma.Uploaders.Uploader do
3 Defines the contract to put and get an uploaded file to any backend.
7 Instructs how to get the file from the backend.
9 Used by `Pleroma.Plugs.UploadedMedia`.
11 @type get_method :: {:static_dir, directory :: String.t()} | {:url, url :: String.t()}
12 @callback get_file(file :: String.t()) :: {:ok, get_method()}
15 Put a file to the backend.
19 * `:ok` which assumes `{:ok, upload.path}`
20 * `{:ok, spec}` where spec is:
21 * `{:file, filename :: String.t}` to handle reads with `get_file/1` (recommended)
23 This allows to correctly proxy or redirect requests to the backend, while allowing to migrate backends without breaking any URL.
24 * `{url, url :: String.t}` to bypass `get_file/2` and use the `url` directly in the activity.
25 * `{:error, String.t}` error information if the file failed to be saved to the backend.
29 @callback put_file(Pleroma.Upload.t()) ::
30 :ok | {:ok, {:file | :url, String.t()}} | {:error, String.t()}
32 @spec put_file(module(), Pleroma.Upload.t()) ::
33 {:ok, {:file | :url, String.t()}} | {:error, String.t()}
34 def put_file(uploader, upload) do
35 case uploader.put_file(upload) do
36 :ok -> {:ok, {:file, upload.path}}