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
|
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
|
@impl true
|
||||||
def list_matches() do
|
def list_files(path) do
|
||||||
{:ok, %{:body => %{:contents => contents, next_continuation_token: next_continuation_token}}} =
|
{:ok, %{:body => %{:contents => contents, next_continuation_token: next_continuation_token}}} =
|
||||||
ExAws.S3.list_objects_v2("matches")
|
ExAws.S3.list_objects_v2(path)
|
||||||
|> ExAws.request()
|
|> ExAws.request()
|
||||||
|
|
||||||
if next_continuation_token do
|
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)
|
# |> Enum.map(fn %{key: key} -> key end)
|
||||||
else
|
else
|
||||||
contents
|
contents
|
||||||
@ -22,18 +26,18 @@ defmodule Storage.MatchStorage.S3MatchStorage do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec list_matches(list(String.t()), String.t()) :: list(String.t())
|
@spec list_files(String.t(), list(String.t()), String.t()) :: list(String.t())
|
||||||
defp list_matches(acc, continuation_token) do
|
defp list_files(path, acc, continuation_token) do
|
||||||
resp =
|
resp =
|
||||||
{:ok,
|
{:ok,
|
||||||
%{:body => %{:contents => contents, next_continuation_token: next_continuation_token}}} =
|
%{: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()
|
|> ExAws.request()
|
||||||
|
|
||||||
if next_continuation_token == "" do
|
if next_continuation_token == "" do
|
||||||
acc ++ contents
|
acc ++ contents
|
||||||
else
|
else
|
||||||
list_matches(acc ++ contents, next_continuation_token)
|
list_files(path, acc ++ contents, next_continuation_token)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user