View Source Mobilizon.Web.Upload.Uploader behaviour (Mobilizon v5.0.0-beta.1)

Defines the contract to put and get an uploaded file to any backend.

Summary

Callbacks

Instructs how to get the file from the backend.

Put a file to the backend.

Types

@type file_spec() :: {:file | :url, String.t()}
@type get_method() ::
  {:static_dir, directory :: String.t()} | {:url, url :: String.t()}

Callbacks

@callback get_file(file :: String.t()) :: {:ok, get_method()}

Instructs how to get the file from the backend.

Used by Mobilizon.Web.Plugs.UploadedMedia.

Link to this callback

http_callback(t, map)

View Source (optional)
@callback http_callback(Plug.Conn.t(), map()) ::
  {:ok, Plug.Conn.t()}
  | {:ok, Plug.Conn.t(), file_spec()}
  | {:error, Plug.Conn.t(), String.t()}
@callback put_file(Mobilizon.Web.Upload.t()) ::
  :ok | {:ok, file_spec()} | {:error, atom()} | :wait_callback

Put a file to the backend.

Returns:

  • :ok which assumes {:ok, upload.path}

  • {:ok, spec} where spec is:

    • {:file, filename :: String.t} to handle reads with get_file/1 (recommended)

    This allows to correctly proxy or redirect requests to the backend, while allowing to migrate backends without breaking any URL.

  • {url, url :: String.t} to bypass get_file/2 and use the url directly in the activity.

  • {:error, String.t} error information if the file failed to be saved to the backend.

  • :wait_callback will wait for an http post request at /api/pleroma/upload_callback/:upload_path and call the uploader's http_callback/3 method.

@callback remove_file(file_spec()) :: :ok | {:ok, file_spec()} | {:error, atom()}

Functions

Link to this function

put_file(uploader, upload)

View Source
@spec put_file(module(), Mobilizon.Web.Upload.t()) ::
  {:ok, file_spec()} | {:error, atom()}
Link to this function

remove_file(uploader, path)

View Source
@spec remove_file(module(), String.t()) :: {:ok, String.t()} | {:error, atom()}