added example cache purge script
This commit is contained in:
parent
cb40602a16
commit
3f8d68bdf3
5 changed files with 64 additions and 16 deletions
16
lib/pleroma/web/media_proxy/invalidations/http.ex
Normal file
16
lib/pleroma/web/media_proxy/invalidations/http.ex
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
defmodule Pleroma.Web.MediaProxy.Invalidation.Http do
|
||||
@behaviour Pleroma.Web.MediaProxy.Invalidation
|
||||
|
||||
@impl Pleroma.Web.MediaProxy.Invalidation
|
||||
def purge(urls, opts) do
|
||||
method = Map.get(opts, :http_method, :purge)
|
||||
headers = Map.get(opts, :http_headers, [])
|
||||
options = Map.get(opts, :http_options, [])
|
||||
|
||||
Enum.each(urls, fn url ->
|
||||
Pleroma.HTTP.request(method, url, "", headers, options)
|
||||
end)
|
||||
|
||||
{:ok, "success"}
|
||||
end
|
||||
end
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
defmodule Pleroma.Web.MediaProxy.Invalidation.Nginx do
|
||||
@behaviour Pleroma.Web.MediaProxy.Invalidation
|
||||
|
||||
@impl Pleroma.Web.MediaProxy.Invalidation
|
||||
def purge(urls, _opts) do
|
||||
Enum.each(urls, fn url ->
|
||||
Pleroma.HTTP.request(:purge, url, "", [], [])
|
||||
end)
|
||||
|
||||
{:ok, "success"}
|
||||
end
|
||||
end
|
||||
|
|
@ -2,9 +2,14 @@ defmodule Pleroma.Web.MediaProxy.Invalidation.Script do
|
|||
@behaviour Pleroma.Web.MediaProxy.Invalidation
|
||||
|
||||
@impl Pleroma.Web.MediaProxy.Invalidation
|
||||
def purge(urls, %{script_path: script_path} = options) do
|
||||
script_args = List.wrap(Map.get(options, :script_args, []))
|
||||
System.cmd(Path.expand(script_path), [urls] ++ script_args)
|
||||
def purge(urls, %{script_path: script_path} = _options) do
|
||||
args =
|
||||
urls
|
||||
|> List.wrap()
|
||||
|> Enum.uniq()
|
||||
|> Enum.join(" ")
|
||||
|
||||
System.cmd(Path.expand(script_path), [args])
|
||||
{:ok, "success"}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue