make path for listing files configurable
This commit is contained in:
parent
2338114757
commit
d4f7a4dc1a
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user