diff --git a/apps/storage/lib/match_storage/s3_match_storage.ex b/apps/storage/lib/match_storage/s3_match_storage.ex index fddc929..7f4edfe 100644 --- a/apps/storage/lib/match_storage/s3_match_storage.ex +++ b/apps/storage/lib/match_storage/s3_match_storage.ex @@ -6,15 +6,19 @@ defmodule Storage.MatchStorage.S3MatchStorage do "" end - # check for to get all pages next_continuation_token + @doc """ + Lists all files at the given path. + + iex > Storage.MatchStorage.S3MatchStorage.list_files("matches") + """ @impl true - def list_matches() do + def list_files(path) do {:ok, %{:body => %{:contents => contents, next_continuation_token: next_continuation_token}}} = - ExAws.S3.list_objects_v2("matches") + ExAws.S3.list_objects_v2(path) |> ExAws.request() if next_continuation_token do - list_matches(contents, next_continuation_token) + list_files(path, contents, next_continuation_token) # |> Enum.map(fn %{key: key} -> key end) else contents @@ -22,18 +26,18 @@ defmodule Storage.MatchStorage.S3MatchStorage do end end - @spec list_matches(list(String.t()), String.t()) :: list(String.t()) - defp list_matches(acc, continuation_token) do + @spec list_files(String.t(), list(String.t()), String.t()) :: list(String.t()) + defp list_files(path, acc, continuation_token) do resp = {:ok, %{:body => %{:contents => contents, next_continuation_token: next_continuation_token}}} = - ExAws.S3.list_objects_v2("matches", continuation_token: continuation_token) + ExAws.S3.list_objects_v2(path, continuation_token: continuation_token) |> ExAws.request() if next_continuation_token == "" do acc ++ contents else - list_matches(acc ++ contents, next_continuation_token) + list_files(path, acc ++ contents, next_continuation_token) end end