mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-18 10:59:17 +00:00
fetcher: move local object checking into a reusable function
This commit is contained in:
parent
34cdbcbb64
commit
9f29930440
|
@ -255,4 +255,8 @@ def update_data(%Object{data: data} = object, attrs \\ %{}) do
|
||||||
|> Object.change(%{data: Map.merge(data || %{}, attrs)})
|
|> Object.change(%{data: Map.merge(data || %{}, attrs)})
|
||||||
|> Repo.update()
|
|> Repo.update()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def local?(%Object{data: %{"id" => id}}) do
|
||||||
|
String.starts_with?(id, Pleroma.Web.base_url() <> "/")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -49,7 +49,7 @@ defp reinject_object(struct, data) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def refetch_object(%Object{data: %{"id" => id}} = object) do
|
def refetch_object(%Object{data: %{"id" => id}} = object) do
|
||||||
with {:local, false} <- {:local, String.starts_with?(id, Pleroma.Web.base_url() <> "/")},
|
with {:local, false} <- {:local, Object.local?(object)},
|
||||||
{:ok, data} <- fetch_and_contain_remote_object_from_id(id),
|
{:ok, data} <- fetch_and_contain_remote_object_from_id(id),
|
||||||
{:ok, object} <- reinject_object(object, data) do
|
{:ok, object} <- reinject_object(object, data) do
|
||||||
{:ok, object}
|
{:ok, object}
|
||||||
|
|
Loading…
Reference in a new issue