Delete files when updating parent identities

Closes #127

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2019-06-05 18:29:39 +02:00
parent 10dbe14a52
commit e8cabd38d4
10 changed files with 263 additions and 25 deletions

View File

@@ -88,6 +88,16 @@ defmodule MobilizonWeb.Upload do
end
end
def remove(url, opts \\ []) do
with opts <- get_opts(opts),
%URI{path: "/media/" <> path, host: host} <- URI.parse(url),
true <- host == MobilizonWeb.Endpoint.host() do
MobilizonWeb.Uploaders.Uploader.remove_file(opts.uploader, path)
else
%URI{} = _uri -> {:error, "URL doesn't match pattern"}
end
end
def char_unescaped?(char) do
URI.char_unreserved?(char) or char == ?/
end