projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Use proper lang attributes in htmls
[akkoma]
/
lib
/
pleroma
/
web
/
media_proxy
/
invalidation.ex
diff --git
a/lib/pleroma/web/media_proxy/invalidation.ex
b/lib/pleroma/web/media_proxy/invalidation.ex
index 371aa8ae0bcd9469b5bb9aea810551fde2c6ca11..cb2db5ce9ddef7c5179eac190546d920f9eec681 100644
(file)
--- a/
lib/pleroma/web/media_proxy/invalidation.ex
+++ b/
lib/pleroma/web/media_proxy/invalidation.ex
@@
-1,20
+1,40
@@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.MediaProxy.Invalidation do
defmodule Pleroma.Web.MediaProxy.Invalidation do
- @callback purge(list(String.t()), map()) :: {:ok, String.t()} | {:error, String.t()}
+ @moduledoc false
+
+ @callback purge(list(String.t()), Keyword.t()) :: {:ok, list(String.t())} | {:error, String.t()}
alias Pleroma.Config
alias Pleroma.Config
+ alias Pleroma.Web.MediaProxy
+
+ @spec enabled?() :: boolean()
+ def enabled?, do: Config.get([:media_proxy, :invalidation, :enabled])
+ @spec purge(list(String.t()) | String.t()) :: {:ok, list(String.t())} | {:error, String.t()}
def purge(urls) do
def purge(urls) do
- [:media_proxy, :invalidation, :enabled]
- |> Config.get()
- |> do_purge(urls)
+ prepared_urls = prepare_urls(urls)
+
+ if enabled?() do
+ do_purge(prepared_urls)
+ else
+ {:ok, prepared_urls}
+ end
end
end
- defp do_purge(
true,
urls) do
+ defp do_purge(urls) do
provider = Config.get([:media_proxy, :invalidation, :provider])
options = Config.get(provider)
provider.purge(urls, options)
provider = Config.get([:media_proxy, :invalidation, :provider])
options = Config.get(provider)
provider.purge(urls, options)
- :ok
end
end
- defp do_purge(_, _), do: :ok
+ def prepare_urls(urls) do
+ urls
+ |> List.wrap()
+ |> Enum.map(fn url -> [MediaProxy.url(url), MediaProxy.preview_url(url)] end)
+ |> List.flatten()
+ |> Enum.uniq()
+ end
end
end