2020-05-18 00:22:26 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-05-15 12:34:46 -06:00
|
|
|
defmodule Pleroma.Web.MediaProxy.Invalidation.Script do
|
2020-05-18 00:22:26 -06:00
|
|
|
@moduledoc false
|
|
|
|
|
2020-05-15 12:34:46 -06:00
|
|
|
@behaviour Pleroma.Web.MediaProxy.Invalidation
|
|
|
|
|
2020-05-18 00:22:26 -06:00
|
|
|
require Logger
|
|
|
|
|
2020-05-15 12:34:46 -06:00
|
|
|
@impl Pleroma.Web.MediaProxy.Invalidation
|
2020-05-16 06:16:33 -06:00
|
|
|
def purge(urls, %{script_path: script_path} = _options) do
|
|
|
|
args =
|
|
|
|
urls
|
|
|
|
|> List.wrap()
|
|
|
|
|> Enum.uniq()
|
|
|
|
|> Enum.join(" ")
|
|
|
|
|
2020-05-18 00:22:26 -06:00
|
|
|
path = Path.expand(script_path)
|
|
|
|
|
|
|
|
Logger.debug("Running cache purge: #{inspect(urls)}, #{path}")
|
|
|
|
|
|
|
|
case do_purge(path, [args]) do
|
|
|
|
{result, exit_status} when exit_status > 0 ->
|
|
|
|
Logger.error("Error while cache purge: #{inspect(result)}")
|
|
|
|
{:error, inspect(result)}
|
|
|
|
|
|
|
|
_ ->
|
|
|
|
{:ok, "success"}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def purge(_, _), do: {:error, "not found script path"}
|
|
|
|
|
|
|
|
defp do_purge(path, args) do
|
|
|
|
System.cmd(path, args)
|
|
|
|
rescue
|
|
|
|
error -> {inspect(error), 1}
|
2020-05-15 12:34:46 -06:00
|
|
|
end
|
|
|
|
end
|