mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-12-04 16:48:00 +01:00
image upload mime validation - shows you what it thinks the mime type is (#79)
This commit is contained in:
parent
603c8d4867
commit
ae6640e9d3
3 changed files with 7 additions and 2 deletions
|
@ -155,7 +155,8 @@ defmodule Philomena.Images.Image do
|
||||||
|> validate_length(:image_name, max: 255, count: :bytes)
|
|> validate_length(:image_name, max: 255, count: :bytes)
|
||||||
|> validate_inclusion(
|
|> validate_inclusion(
|
||||||
:image_mime_type,
|
:image_mime_type,
|
||||||
~W(image/gif image/jpeg image/png image/svg+xml video/webm)
|
~W(image/gif image/jpeg image/png image/svg+xml video/webm),
|
||||||
|
message: "(#{attrs["image_mime_type"]}) is invalid"
|
||||||
)
|
)
|
||||||
|> unsafe_validate_unique([:image_orig_sha512_hash], Repo)
|
|> unsafe_validate_unique([:image_orig_sha512_hash], Repo)
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,5 +33,5 @@ defmodule Philomena.Mime do
|
||||||
when mime in ~W(image/gif image/jpeg image/png image/svg+xml video/webm),
|
when mime in ~W(image/gif image/jpeg image/png image/svg+xml video/webm),
|
||||||
do: {:ok, mime}
|
do: {:ok, mime}
|
||||||
|
|
||||||
def true_mime(_mime), do: :error
|
def true_mime(mime), do: {:unsupported_mime, mime}
|
||||||
end
|
end
|
||||||
|
|
|
@ -43,6 +43,10 @@ defmodule Philomena.Uploader do
|
||||||
|
|
||||||
changeset_fn.(model_or_changeset, attributes)
|
changeset_fn.(model_or_changeset, attributes)
|
||||||
else
|
else
|
||||||
|
{:unsupported_mime, mime} ->
|
||||||
|
attributes = prefix_attributes(%{"mime_type" => mime}, field_name)
|
||||||
|
changeset_fn.(model_or_changeset, attributes)
|
||||||
|
|
||||||
_error ->
|
_error ->
|
||||||
changeset_fn.(model_or_changeset, %{})
|
changeset_fn.(model_or_changeset, %{})
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue