+ defp create_name(uuid, ext, type) do
+ case type do
+ "application/octet-stream" ->
+ String.downcase(Enum.join([uuid, ext], "."))
+
+ "audio/mpeg" ->
+ String.downcase(Enum.join([uuid, "mp3"], "."))
+
+ _ ->
+ String.downcase(Enum.join([uuid, List.last(String.split(type, "/"))], "."))
+ end
+ end
+
+ defp get_uuid(file, should_dedupe) do
+ if should_dedupe do
+ Base.encode16(:crypto.hash(:sha256, File.read!(file.path)))
+ else
+ UUID.generate()
+ end
+ end
+
+ defp get_name(file, uuid, type, should_dedupe) do
+ if should_dedupe do
+ create_name(uuid, List.last(String.split(file.filename, ".")), type)
+ else
+ unless String.contains?(file.filename, ".") do
+ case type do
+ "image/png" -> file.filename <> ".png"
+ "image/jpeg" -> file.filename <> ".jpg"
+ "image/gif" -> file.filename <> ".gif"
+ "video/webm" -> file.filename <> ".webm"
+ "video/mp4" -> file.filename <> ".mp4"
+ "audio/mpeg" -> file.filename <> ".mp3"
+ "audio/ogg" -> file.filename <> ".ogg"
+ "audio/wav" -> file.filename <> ".wav"
+ _ -> file.filename
+ end
+ else
+ file.filename
+ end
+ end
+ end
+
+ defp get_upload_path(uuid, should_dedupe) do
+ if should_dedupe do
+ upload_path()
+ else
+ Path.join(upload_path(), uuid)
+ end
+ end
+
+ defp get_url(name, uuid, should_dedupe) do
+ if should_dedupe do
+ url_for(:cow_uri.urlencode(name))
+ else
+ url_for(Path.join(uuid, :cow_uri.urlencode(name)))
+ end
+ end
+