Skip to content

Commit

Permalink
Add some logging and fixed extra index.html postfix
Browse files Browse the repository at this point in the history
  • Loading branch information
mellelieuwes committed Nov 23, 2023
1 parent d89aad8 commit 8bb79a3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion core/systems/feldspar/app_page.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defmodule Systems.Feldspar.AppPage do
@impl true
def mount(%{"id" => app_id}, _session, socket) do
app_url = Feldspar.Public.get_public_url(app_id) <> "/index.html"
Logger.info("Starting feldspar app from: #{app_url}")
Logger.info("[Feldspar.AppPage] Starting feldspar app from: #{app_url}")

{
:ok,
Expand Down
13 changes: 10 additions & 3 deletions core/systems/feldspar/s3.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
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)
Expand All @@ -10,7 +12,7 @@ defmodule Systems.Feldspar.S3 do
def get_public_url(id) do
settings = s3_settings()
public_url = Access.get(settings, :public_url)
"#{public_url}/#{object_key(id)}/index.html"
"#{public_url}/#{object_key(id)}"
end

def remove(id) do
Expand Down Expand Up @@ -50,6 +52,8 @@ defmodule Systems.Feldspar.S3 do
data
)
|> backend().request!()
else
Logger.info("[Feldspar.S3] Skip uploading: #{name}")
end
end

Expand All @@ -62,8 +66,11 @@ defmodule Systems.Feldspar.S3 do
def is_regular_file(_), do: false

defp object_key(id) do
prefix = Access.get(s3_settings(), :prefix, "")
"#{prefix}#{id}"
prefix = Access.get(s3_settings(), :prefix, nil)

[prefix, id]
|> Enum.filter(&(&1 != nil))
|> Enum.join("/")
end

defp s3_settings do
Expand Down
4 changes: 2 additions & 2 deletions core/test/systems/feldspar/s3_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ defmodule Systems.Feldspar.S3Test do
end
end

describe "get_public_url/1" do
describe "get_public_url/1 (without prefix)" do
test "returns URL" do
id = Ecto.UUID.generate()
url = S3.get_public_url(id)
assert "http://example.com/#{id}/index.html" == url
assert "http://example.com/#{id}" == url
end
end

Expand Down

0 comments on commit 8bb79a3

Please sign in to comment.