1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Upload.Filter do
7 Upload Filter behaviour
9 This behaviour allows to run filtering actions just before a file is uploaded. This allows to:
11 * morph in place the temporary file
12 * change any field of a `Pleroma.Upload` struct
13 * cancel/stop the upload
18 @callback filter(Pleroma.Upload.t()) :: :ok | {:ok, Pleroma.Upload.t()} | {:error, any()}
20 @spec filter([module()], Pleroma.Upload.t()) :: {:ok, Pleroma.Upload.t()} | {:error, any()}
22 def filter([], upload) do
26 def filter([filter | rest], upload) do
27 case filter.filter(upload) do
35 Logger.error("#{__MODULE__}: Filter #{filter} failed: #{inspect(error)}")