From 04ca222739e7305a255793bc84799dc88fd960ac Mon Sep 17 00:00:00 2001 From: emielvdveen Date: Fri, 24 Nov 2023 12:03:09 +0100 Subject: [PATCH] Added MIMI library to take care of S3 mime types fort Feldspar --- core/mix.exs | 2 ++ core/mix.lock | 1 + core/systems/feldspar/s3.ex | 20 ++------------------ 3 files changed, 5 insertions(+), 18 deletions(-) diff --git a/core/mix.exs b/core/mix.exs index 7107797b8..56427eed7 100644 --- a/core/mix.exs +++ b/core/mix.exs @@ -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"}, diff --git a/core/mix.lock b/core/mix.lock index 969020334..04465695a 100644 --- a/core/mix.lock +++ b/core/mix.lock @@ -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"}, diff --git a/core/systems/feldspar/s3.ex b/core/systems/feldspar/s3.ex index 84e8743e0..15ff5a1e7 100644 --- a/core/systems/feldspar/s3.ex +++ b/core/systems/feldspar/s3.ex @@ -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 @@ -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