mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-11 03:39:13 +00:00
Object.Fetcher: Fallback to OStatus only if AP actually fails
This commit is contained in:
parent
40d0a198e2
commit
e1c08a67d6
1 changed files with 36 additions and 26 deletions
|
@ -31,14 +31,15 @@ defmodule Pleroma.Object.Fetcher do
|
||||||
{:ok, object}
|
{:ok, object}
|
||||||
else
|
else
|
||||||
Logger.info("Fetching #{id} via AP")
|
Logger.info("Fetching #{id} via AP")
|
||||||
|
{status, data} = fetch_and_contain_remote_object_from_id(id)
|
||||||
|
object = Object.normalize(data, false)
|
||||||
|
|
||||||
with {:ok, data} <- fetch_and_contain_remote_object_from_id(id),
|
if status == :ok and object == nil do
|
||||||
nil <- Object.normalize(data, false),
|
with params <- %{
|
||||||
params <- %{
|
|
||||||
"type" => "Create",
|
"type" => "Create",
|
||||||
"to" => data["to"],
|
"to" => data["to"],
|
||||||
"cc" => data["cc"],
|
"cc" => data["cc"],
|
||||||
# TODO: Should we seriously keep this attributedTo thing?
|
# Should we seriously keep this attributedTo thing?
|
||||||
"actor" => data["actor"] || data["attributedTo"],
|
"actor" => data["actor"] || data["attributedTo"],
|
||||||
"object" => data
|
"object" => data
|
||||||
},
|
},
|
||||||
|
@ -60,9 +61,17 @@ defmodule Pleroma.Object.Fetcher do
|
||||||
:error ->
|
:error ->
|
||||||
{:error, "Object containment failed."}
|
{:error, "Object containment failed."}
|
||||||
|
|
||||||
_e ->
|
e ->
|
||||||
|
e
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if status == :ok and object != nil do
|
||||||
|
{:ok, object}
|
||||||
|
else
|
||||||
|
# Only fallback when receiving a fetch/normalization error with ActivityPub
|
||||||
Logger.info("Couldn't get object via AP, trying out OStatus fetching...")
|
Logger.info("Couldn't get object via AP, trying out OStatus fetching...")
|
||||||
|
|
||||||
|
# FIXME: OStatus Object Containment?
|
||||||
case OStatus.fetch_activity_from_url(id) do
|
case OStatus.fetch_activity_from_url(id) do
|
||||||
{:ok, [activity | _]} -> {:ok, Object.normalize(activity, false)}
|
{:ok, [activity | _]} -> {:ok, Object.normalize(activity, false)}
|
||||||
e -> e
|
e -> e
|
||||||
|
@ -70,6 +79,7 @@ defmodule Pleroma.Object.Fetcher do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def fetch_object_from_id!(id, options \\ []) do
|
def fetch_object_from_id!(id, options \\ []) do
|
||||||
with {:ok, object} <- fetch_object_from_id(id, options) do
|
with {:ok, object} <- fetch_object_from_id(id, options) do
|
||||||
|
|
Loading…
Reference in a new issue