Add methods to S3 storage to list all matches
This commit is contained in:
parent
7feb550540
commit
2f444e4218
@ -8,8 +8,42 @@ defmodule Scrapper.Storage.S3MatchStorage do
|
|||||||
""
|
""
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
# check for to get all pages next_continuation_token
|
||||||
|
def list_matches() do
|
||||||
|
{:ok, %{:body => %{:contents => contents, next_continuation_token: next_continuation_token}}} =
|
||||||
|
ExAws.S3.list_objects_v2("matches")
|
||||||
|
|> ExAws.request()
|
||||||
|
|
||||||
|
if next_continuation_token do
|
||||||
|
list_matches(contents, next_continuation_token)
|
||||||
|
# |> Enum.map(fn %{key: key} -> key end)
|
||||||
|
else
|
||||||
|
contents
|
||||||
|
# |> Enum.map(fn %{key: key} -> key end)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@spec list_matches(list(String.t()), String.t()) :: list(String.t())
|
||||||
|
def list_matches(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.request()
|
||||||
|
|
||||||
|
if next_continuation_token == "" do
|
||||||
|
acc ++ contents
|
||||||
|
else
|
||||||
|
list_matches(acc ++ contents, next_continuation_token)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def download_match(destination_path, url) do
|
||||||
|
ExAws.S3.download_file(url, destination_path)
|
||||||
|
|> ExAws.request()
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
iex> Scrapper.Storage.S3MatchStorage.store_match "1", "content"
|
iex> Scrapper.Storage.S3MatchStorage.store_match "1", "content"
|
||||||
"""
|
"""
|
||||||
@spec store_match(String.t(), String.t()) :: none()
|
@spec store_match(String.t(), String.t()) :: none()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user