From 1a3f15caa15af755fde7d3c196ed48c056dec510 Mon Sep 17 00:00:00 2001 From: emielvdveen Date: Thu, 23 Nov 2023 16:02:09 +0100 Subject: [PATCH] Changed content type --- core/systems/feldspar/s3.ex | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/core/systems/feldspar/s3.ex b/core/systems/feldspar/s3.ex index 5d43a84a9..1565dc527 100644 --- a/core/systems/feldspar/s3.ex +++ b/core/systems/feldspar/s3.ex @@ -50,7 +50,7 @@ defmodule Systems.Feldspar.S3 do Access.fetch!(settings, :bucket), "#{object_key(target)}/#{name}", data, - content_type: "text/html" + content_type: content_type(name) ) |> backend().request!() else @@ -82,4 +82,22 @@ defmodule Systems.Feldspar.S3 do # Allow mocking Access.get(s3_settings(), :s3_backend, ExAws) end + + defp content_type("html"), do: "text/html" + defp content_type("js"), do: "text/javascript" + defp content_type("css"), do: "text/css" + defp content_type("svg"), do: "image/svg+xml" + defp content_type("ico"), do: "image/x-icon" + defp content_type("whl"), do: " application/zip" + defp content_type("json"), do: "application/json" + defp content_type("ts"), do: "application/typescript" + defp content_type("tsx"), do: "application/typescript" + defp content_type(nil), do: "text/html" + + defp content_type(name) do + name + |> String.split(name, ".") + |> List.last() + |> content_type() + end end