projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'develop' into stable
[akkoma]
/
lib
/
pleroma
/
collections
/
fetcher.ex
diff --git
a/lib/pleroma/collections/fetcher.ex
b/lib/pleroma/collections/fetcher.ex
index 382defff41b815d68958a1c67e4be3c2fa0722cb..a2fcb7794c66b7f321a1cea09b5c34f20ca5aca1 100644
(file)
--- a/
lib/pleroma/collections/fetcher.ex
+++ b/
lib/pleroma/collections/fetcher.ex
@@
-9,11
+9,9
@@
defmodule Akkoma.Collections.Fetcher do
"""
alias Pleroma.Object.Fetcher
alias Pleroma.Config
"""
alias Pleroma.Object.Fetcher
alias Pleroma.Config
+ require Logger
- def fetch_collection_by_ap_id(ap_id) when is_binary(ap_id) do
- fetch_collection(ap_id)
- end
-
+ @spec fetch_collection(String.t() | map()) :: {:ok, [Pleroma.Object.t()]} | {:error, any()}
def fetch_collection(ap_id) when is_binary(ap_id) do
with {:ok, page} <- Fetcher.fetch_and_contain_remote_object_from_id(ap_id) do
{:ok, objects_from_collection(page)}
def fetch_collection(ap_id) when is_binary(ap_id) do
with {:ok, page} <- Fetcher.fetch_and_contain_remote_object_from_id(ap_id) do
{:ok, objects_from_collection(page)}
@@
-25,7
+23,7
@@
defmodule Akkoma.Collections.Fetcher do
end
def fetch_collection(%{"type" => type} = page)
end
def fetch_collection(%{"type" => type} = page)
- when type in ["Collection", "OrderedCollection"] do
+ when type in ["Collection", "OrderedCollection"
, "CollectionPage", "OrderedCollectionPage"
] do
{:ok, objects_from_collection(page)}
end
{:ok, objects_from_collection(page)}
end
@@
-37,12
+35,13
@@
defmodule Akkoma.Collections.Fetcher do
when is_list(items) and type in ["Collection", "CollectionPage"],
do: items
when is_list(items) and type in ["Collection", "CollectionPage"],
do: items
- defp objects_from_collection(%{"type" =>
"OrderedCollection", "orderedItems" => items}
)
- when is_list(items),
- do:
items
+ defp objects_from_collection(%{"type" =>
type, "orderedItems" => items} = page
)
+ when is_list(items)
and type in ["OrderedCollection", "OrderedCollectionPage"]
,
+ do:
maybe_next_page(page, items)
- defp objects_from_collection(%{"type" => "Collection", "items" => items}) when is_list(items),
- do: items
+ defp objects_from_collection(%{"type" => type, "items" => items} = page)
+ when is_list(items) and type in ["Collection", "CollectionPage"],
+ do: maybe_next_page(page, items)
defp objects_from_collection(%{"type" => type, "first" => first})
when is_binary(first) and type in ["Collection", "OrderedCollection"] do
defp objects_from_collection(%{"type" => type, "first" => first})
when is_binary(first) and type in ["Collection", "OrderedCollection"] do
@@
-54,17
+53,27
@@
defmodule Akkoma.Collections.Fetcher do
fetch_page_items(id)
end
fetch_page_items(id)
end
+ defp objects_from_collection(_page), do: []
+
defp fetch_page_items(id, items \\ []) do
if Enum.count(items) >= Config.get([:activitypub, :max_collection_objects]) do
items
else
defp fetch_page_items(id, items \\ []) do
if Enum.count(items) >= Config.get([:activitypub, :max_collection_objects]) do
items
else
- {:ok, page} = Fetcher.fetch_and_contain_remote_object_from_id(id)
- objects = items_in_page(page)
+ with {:ok, page} <- Fetcher.fetch_and_contain_remote_object_from_id(id) do
+
objects = items_in_page(page)
- if Enum.count(objects) > 0 do
- maybe_next_page(page, items ++ objects)
+ if Enum.count(objects) > 0 do
+ maybe_next_page(page, items ++ objects)
+ else
+ items
+ end
else
else
- items
+ {:error, {"Object has been deleted", _, _}} ->
+ items
+
+ {:error, error} ->
+ Logger.error("Could not fetch page #{id} - #{inspect(error)}")
+ {:error, error}
end
end
end
end
end
end