From 8bb79a32765841af26f758d84e3f132329edd24e Mon Sep 17 00:00:00 2001 From: emielvdveen Date: Thu, 23 Nov 2023 14:36:31 +0100 Subject: [PATCH] Add some logging and fixed extra index.html postfix --- core/systems/feldspar/app_page.ex | 2 +- core/systems/feldspar/s3.ex | 13 ++++++++++--- core/test/systems/feldspar/s3_test.exs | 4 ++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/core/systems/feldspar/app_page.ex b/core/systems/feldspar/app_page.ex index e597541f4..084b6fd28 100644 --- a/core/systems/feldspar/app_page.ex +++ b/core/systems/feldspar/app_page.ex @@ -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, diff --git a/core/systems/feldspar/s3.ex b/core/systems/feldspar/s3.ex index 0eef78afe..98a3fbaac 100644 --- a/core/systems/feldspar/s3.ex +++ b/core/systems/feldspar/s3.ex @@ -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) @@ -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 @@ -50,6 +52,8 @@ defmodule Systems.Feldspar.S3 do data ) |> backend().request!() + else + Logger.info("[Feldspar.S3] Skip uploading: #{name}") end end @@ -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 diff --git a/core/test/systems/feldspar/s3_test.exs b/core/test/systems/feldspar/s3_test.exs index 34bcecaa3..88e8ef206 100644 --- a/core/test/systems/feldspar/s3_test.exs +++ b/core/test/systems/feldspar/s3_test.exs @@ -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