1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.MediaProxy.Invalidation.Script do
8 @behaviour Pleroma.Web.MediaProxy.Invalidation
12 @impl Pleroma.Web.MediaProxy.Invalidation
13 def purge(urls, opts \\ []) do
21 |> Keyword.get(:script_path)
23 |> handle_result(urls)
26 defp do_purge(script_path, args) when is_binary(script_path) do
27 path = Path.expand(script_path)
28 Logger.debug("Running cache purge: #{inspect(args)}, #{inspect(path)}")
29 System.cmd(path, args)
34 defp do_purge(_, _), do: {:error, "not found script path"}
36 defp handle_result({_result, 0}, urls), do: {:ok, urls}
37 defp handle_result({:error, error}, urls), do: handle_result(error, urls)
39 defp handle_result(error, _) do
40 Logger.error("Error while cache purge: #{inspect(error)}")
41 {:error, inspect(error)}