Remove unused functions

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2021-10-05 15:29:06 +02:00
parent 5d8d2e80a5
commit f4284e1d3a
41 changed files with 114 additions and 714 deletions

View File

@@ -36,22 +36,6 @@ defmodule Mobilizon.Web.Upload.MIME do
end)
end
def bin_mime_type(binary, filename) do
with {:ok, content_type} <- bin_mime_type(binary),
filename <- fix_extension(filename, content_type) do
{:ok, content_type, filename}
end
end
@spec bin_mime_type(binary()) :: {:ok, String.t()} | {:error, :unknown_mime}
def bin_mime_type(<<head::binary-size(@read_bytes), _::binary>>) do
{:ok, check_mime_type(head)}
end
def bin_mime_type(_), do: {:error, :unknown_mime}
def mime_type(<<_::binary>>), do: {:ok, @default}
defp fix_extension(filename, content_type)
when is_binary(filename) and is_binary(content_type) do
parts = String.split(filename, ".")

View File

@@ -94,19 +94,21 @@ defmodule Mobilizon.Web.Upload do
end
end
@spec remove(String.t(), Keyword.t()) ::
{:ok, String.t()} | {:error, atom} | {:error, String.t()}
def remove(url, opts \\ []) do
with opts <- get_opts(opts),
%URI{path: "/media/" <> path, host: host} <- URI.parse(url),
{:same_host, true} <- {:same_host, host == Endpoint.host()} do
Uploader.remove_file(opts.uploader, path)
else
%URI{} = _uri ->
{:error, "URL doesn't match pattern"}
@spec remove(String.t()) :: {:ok, String.t()} | {:error, atom}
def remove(url) do
%{uploader: uploader} = get_opts([])
{:same_host, _} ->
Logger.error("Media can't be deleted because its URL doesn't match current host")
case URI.parse(url) do
%URI{path: "/media/" <> path, host: host} ->
if host == Endpoint.host() do
Uploader.remove_file(uploader, path)
else
Logger.error("Media can't be deleted because its URL doesn't match current host")
{:error, :not_same_host}
end
%URI{} = _uri ->
{:error, :url_invalid}
end
end