Skip to content

Commit

Permalink
feat: add max_size for file
Browse files Browse the repository at this point in the history
  • Loading branch information
AfonsoMartins26 committed Oct 4, 2024
1 parent fdb3bf3 commit db121fe
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/atomic/uploader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,29 @@ defmodule Atomic.Uploader do
use Waffle.Definition
use Waffle.Ecto.Definition

def validate({file, _}) do
def validate(file, _) do
file_extension = file.file_name |> Path.extname() |> String.downcase()

case Enum.member?(extension_whitelist(), file_extension) do
true -> :ok
false -> {:error, "invalid file extension"}
true ->
if file.size <= max_size() do
:ok
else
{:error, "file size exceeds maximum allowed size"}
end

false ->
{:error, "invalid file extension"}
end
end

def extension_whitelist do
Keyword.get(unquote(opts), :extensions, [])
end

def max_size do
Keyword.get(unquote(opts), :max_size, 500)
end
end
end
end

0 comments on commit db121fe

Please sign in to comment.