You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.1 KiB
41 lines
1.1 KiB
4 years ago
|
# Pleroma: A lightweight social networking server
|
||
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||
|
|
||
4 years ago
|
defmodule Pleroma.Web.MediaProxy.Invalidation.Http do
|
||
4 years ago
|
@moduledoc false
|
||
4 years ago
|
@behaviour Pleroma.Web.MediaProxy.Invalidation
|
||
|
|
||
4 years ago
|
require Logger
|
||
|
|
||
4 years ago
|
@impl Pleroma.Web.MediaProxy.Invalidation
|
||
4 years ago
|
def purge(urls, opts \\ []) do
|
||
4 years ago
|
method = Keyword.get(opts, :method, :purge)
|
||
|
headers = Keyword.get(opts, :headers, [])
|
||
|
options = Keyword.get(opts, :options, [])
|
||
4 years ago
|
|
||
4 years ago
|
Logger.debug("Running cache purge: #{inspect(urls)}")
|
||
|
|
||
4 years ago
|
Enum.each(urls, fn url ->
|
||
4 years ago
|
with {:error, error} <- do_purge(method, url, headers, options) do
|
||
|
Logger.error("Error while cache purge: url - #{url}, error: #{inspect(error)}")
|
||
|
end
|
||
4 years ago
|
end)
|
||
|
|
||
4 years ago
|
{:ok, urls}
|
||
4 years ago
|
end
|
||
4 years ago
|
|
||
|
defp do_purge(method, url, headers, options) do
|
||
|
case Pleroma.HTTP.request(method, url, "", headers, options) do
|
||
|
{:ok, %{status: status} = env} when 400 <= status and status < 500 ->
|
||
|
{:error, env}
|
||
|
|
||
4 years ago
|
{:error, _} = error ->
|
||
4 years ago
|
error
|
||
|
|
||
|
_ ->
|
||
|
{:ok, "success"}
|
||
|
end
|
||
|
end
|
||
4 years ago
|
end
|