Fix uploads of files without a detectable mime-type and no file extension
This commit is contained in:
parent
c55ffe6448
commit
207343e472
1 changed files with 19 additions and 14 deletions
|
@ -61,22 +61,27 @@ defmodule Majic.Extension do
|
|||
subtype? = Keyword.get(options, :subtype_as_extension, false)
|
||||
exts = MIME.extensions(mime_type) ++ subtype_extension(subtype?, mime_type)
|
||||
old_ext = String.downcase(Path.extname(name))
|
||||
basename = Path.basename(name, old_ext)
|
||||
"." <> old = old_ext
|
||||
|
||||
if old in exts do
|
||||
Enum.join([basename, old])
|
||||
unless old_ext == "" do
|
||||
basename = Path.basename(name, old_ext)
|
||||
"." <> old = old_ext
|
||||
|
||||
if old in exts do
|
||||
Enum.join([basename, ".", old])
|
||||
else
|
||||
ext = List.first(exts)
|
||||
|
||||
ext_list =
|
||||
cond do
|
||||
ext && append? -> [old, ext]
|
||||
!ext -> []
|
||||
ext -> [ext]
|
||||
end
|
||||
|
||||
Enum.join([basename] ++ ext_list, ".")
|
||||
end
|
||||
else
|
||||
ext = List.first(exts)
|
||||
|
||||
ext_list =
|
||||
cond do
|
||||
ext && append? -> [old, ext]
|
||||
!ext -> []
|
||||
ext -> [ext]
|
||||
end
|
||||
|
||||
Enum.join([basename] ++ ext_list, ".")
|
||||
name
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue