reverse proxy / uploads
[akkoma] / lib / pleroma / uploaders / uploader.ex
1 defmodule Pleroma.Uploaders.Uploader do
2 @moduledoc """
3 Defines the contract to put and get an uploaded file to any backend.
4 """
5
6 @doc """
7 Instructs how to get the file from the backend.
8
9 Used by `Pleroma.Plugs.UploadedMedia`.
10 """
11 @type get_method :: {:static_dir, directory :: String.t()} | {:url, url :: String.t()}
12 @callback get_file(file :: String.t()) :: {:ok, get_method()}
13
14 @doc """
15 Put a file to the backend.
16
17 Returns:
18
19 * `{:ok, spec}` where spec is:
20 * `{:file, filename :: String.t}` to handle reads with `get_file/1` (recommended)
21
22 This allows to correctly proxy or redirect requests to the backend, while allowing to migrate backends without breaking any URL.
23
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.
26
27 """
28 @callback put_file(
29 name :: String.t(),
30 uuid :: String.t(),
31 file :: File.t(),
32 content_type :: String.t(),
33 options :: Map.t()
34 ) :: {:ok, {:file, String.t()} | {:url, String.t()}} | {:error, String.t()}
35 end