Skip to content

Commit

Permalink
Added MIMI library to take care of S3 mime types fort Feldspar
Browse files Browse the repository at this point in the history
  • Loading branch information
mellelieuwes committed Nov 24, 2023
1 parent f596e7b commit 04ca222
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 18 deletions.
2 changes: 2 additions & 0 deletions core/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ defmodule Core.MixProject do
{:statistics, "~> 0.6.2"},
{:csv, "~> 2.4"},
{:sentry, "~> 8.0"},
{:libcluster, "~> 3.3"},
{:mime, "~> 2.0"},
# i18n
{:ex_cldr, "~> 2.25"},
{:ex_cldr_numbers, "~> 2.23"},
Expand Down
1 change: 1 addition & 0 deletions core/mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"joken": {:hex, :joken, "2.6.0", "b9dd9b6d52e3e6fcb6c65e151ad38bf4bc286382b5b6f97079c47ade6b1bcc6a", [:mix], [{:jose, "~> 1.11.5", [hex: :jose, repo: "hexpm", optional: false]}], "hexpm", "5a95b05a71cd0b54abd35378aeb1d487a23a52c324fa7efdffc512b655b5aaa7"},
"jose": {:hex, :jose, "1.11.5", "3bc2d75ffa5e2c941ca93e5696b54978323191988eb8d225c2e663ddfefd515e", [:mix, :rebar3], [], "hexpm", "dcd3b215bafe02ea7c5b23dafd3eb8062a5cd8f2d904fd9caa323d37034ab384"},
"kadabra": {:hex, :kadabra, "0.6.0", "8d8de886802f38d86d2c250eb9416e3208b5e4b78ce8409b40b4d57f21d21fc9", [:mix], [{:certifi, "~> 2.5", [hex: :certifi, repo: "hexpm", optional: false]}, {:hpack, "~> 0.2.3", [hex: :hpack_erl, repo: "hexpm", optional: false]}], "hexpm", "0cdaf72fc6205cba62da9e49ee6b24b7c50adb6d9f8b0e92b4b1847959371403"},
"libcluster": {:hex, :libcluster, "3.3.3", "a4f17721a19004cfc4467268e17cff8b1f951befe428975dd4f6f7b84d927fe0", [:mix], [{:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "7c0a2275a0bb83c07acd17dab3c3bfb4897b145106750eeccc62d302e3bdfee5"},
"logger_json": {:hex, :logger_json, "4.3.0", "41aaaab2c2e1c071bfddbcc5a3f567884fdf312d222c7f1a7e3de6ab667774f7", [:mix], [{:ecto, "~> 2.1 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "001bbc34d7c451cfeed298c8384cb3aab10b364db2eb095c466c7a1a28bee6e0"},
"luhn": {:hex, :luhn, "0.3.3", "5aa0c6a32c2db4b9db9f9b883ba8301c1ae169d57199b9e6cb1ba2707bc51d96", [:mix], [], "hexpm", "3e823a913a25aab51352c727f135278d22954874d5f0835be81ed4fec3daf78d"},
"mail": {:hex, :mail, "0.2.3", "2c6bb5f8a5f74845fa50ecd0fb45ea16b164026f285f45104f1c4c078cd616d4", [:mix], [], "hexpm", "932b398fa9c69fdf290d7ff63175826e0f1e24414d5b0763bb00a2acfc6c6bf5"},
Expand Down
20 changes: 2 additions & 18 deletions core/systems/feldspar/s3.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ defmodule Systems.Feldspar.S3 do
end
end

defp content_type(name), do: MIME.from_path(name)

@doc """
See: https://www.erlang.org/doc/man/file#type-file_info
Files types: device | directory | other | regular | symlink | undefined
Expand All @@ -80,22 +82,4 @@ defmodule Systems.Feldspar.S3 do
# Allow mocking
Access.get(s3_settings(), :s3_backend, ExAws)
end

defp mime_type("html"), do: "text/html"
defp mime_type("js"), do: "text/javascript"
defp mime_type("css"), do: "text/css"
defp mime_type("svg"), do: "image/svg+xml"
defp mime_type("ico"), do: "image/x-icon"
defp mime_type("whl"), do: " application/zip"
defp mime_type("json"), do: "application/json"
defp mime_type("ts"), do: "application/typescript"
defp mime_type("tsx"), do: "application/typescript"
defp mime_type(_), do: "text/html"

defp content_type(name) do
"#{name}"
|> String.split(".")
|> List.last()
|> mime_type()
end
end

0 comments on commit 04ca222

Please sign in to comment.