Skip to content

Commit

Permalink
Fixed mime type S3 issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mellelieuwes committed Nov 23, 2023
1 parent 109bf9d commit f596e7b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 34 deletions.
19 changes: 7 additions & 12 deletions core/config/dev.exs
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import Config

# Setup for MinIO
config :ex_aws, :s3,
scheme: "http://",
host: "localhost",
port: 9000

# Only in tests, remove the complexity from the password hashing algorithm
config :bcrypt_elixir, :log_rounds, 1

Expand Down Expand Up @@ -83,12 +77,13 @@ config :core,
:admins,
["e.vanderveen@eyra.co"]

config :core, :s3, bucket: "eylixir"

# For Minio (local S3)
config :ex_aws,
access_key_id: "my_access_key",
secret_access_key: "a_super_secret"
# # For Minio (local S3)
# config :ex_aws,
# scheme: "http://",
# host: "localhost",
# port: 9000
# access_key_id: "my_access_key",
# secret_access_key: "a_super_secret"

config :core, :feldspar,
backend: Systems.Feldspar.LocalFS,
Expand Down
5 changes: 4 additions & 1 deletion core/systems/assignment/start_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ defmodule Systems.Assignment.StartView do
def compose(:description, %{work_item: {%{description: description}, _}}), do: description

@impl true
def compose(:icon, %{work_item: {%{group: group}, _}}), do: group
def compose(:icon, %{work_item: {%{group: nil}, _}}), do: nil

@impl true
def compose(:icon, %{work_item: {%{group: group}, _}}), do: String.downcase(group)

defp start_action({%{tool_ref: tool_ref}, _task} = item) do
Project.ToolRefModel.tool(tool_ref)
Expand Down
36 changes: 15 additions & 21 deletions core/systems/feldspar/s3.ex
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
defmodule Systems.Feldspar.S3 do
alias ExAws.S3

require Logger

def store(zip_file) do
id = Ecto.UUID.generate()
:ok = upload_zip_content(zip_file, id)
id
end

def get_public_url(id) do
settings = s3_settings() |> dbg()
public_url = Access.get(settings, :public_url) |> dbg()
"#{public_url}/#{object_key(id)}" |> dbg()
settings = s3_settings()
public_url = Access.get(settings, :public_url)
"#{public_url}/#{object_key(id)}"
end

def remove(id) do
Expand All @@ -39,8 +37,7 @@ defmodule Systems.Feldspar.S3 do
contents
|> Enum.map(fn {:zip_file, file, info, _, _, _} -> {file, info} end)
|> Task.async_stream(&upload_file(&1, zip_handle, target, s3_settings()),
max_concurrency: 10,
timeout: 60000
max_concurrency: 10
)
|> Stream.run()
end
Expand All @@ -56,9 +53,6 @@ defmodule Systems.Feldspar.S3 do
content_type: content_type(name)
)
|> backend().request!()
|> dbg()
else
Logger.info("[Feldspar.S3] Skip uploading: #{name}")
end
end

Expand Down Expand Up @@ -87,21 +81,21 @@ defmodule Systems.Feldspar.S3 do
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 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()
|> content_type()
|> mime_type()
end
end

0 comments on commit f596e7b

Please sign in to comment.