2020-01-25 00:47:30 -07:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-12 23:49:20 -07:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2020-01-25 00:47:30 -07:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Workers.RemoteFetcherWorker do
|
2023-12-26 14:28:05 -07:00
|
|
|
alias Pleroma.Instances
|
2020-01-25 00:47:30 -07:00
|
|
|
alias Pleroma.Object.Fetcher
|
|
|
|
|
|
|
|
use Pleroma.Workers.WorkerHelper, queue: "remote_fetcher"
|
|
|
|
|
|
|
|
@impl Oban.Worker
|
2020-06-23 06:09:01 -06:00
|
|
|
def perform(%Job{args: %{"op" => "fetch_remote", "id" => id} = args}) do
|
2023-12-26 14:28:05 -07:00
|
|
|
if Instances.reachable?(id) do
|
|
|
|
case Fetcher.fetch_object_from_id(id, depth: args["depth"]) do
|
|
|
|
{:ok, _object} ->
|
|
|
|
:ok
|
2023-12-26 13:54:14 -07:00
|
|
|
|
2023-12-27 19:57:47 -07:00
|
|
|
{:error, :forbidden} ->
|
2023-12-28 21:52:05 -07:00
|
|
|
{:discard, :forbidden}
|
2023-12-26 13:54:14 -07:00
|
|
|
|
2023-12-27 19:57:47 -07:00
|
|
|
{:error, :not_found} ->
|
2023-12-28 21:52:05 -07:00
|
|
|
{:discard, :not_found}
|
2023-12-26 14:05:44 -07:00
|
|
|
|
2023-12-27 20:28:41 -07:00
|
|
|
{:error, :allowed_depth} ->
|
2023-12-28 21:52:05 -07:00
|
|
|
{:discard, :allowed_depth}
|
2023-12-27 20:28:41 -07:00
|
|
|
|
2023-12-26 14:28:05 -07:00
|
|
|
_ ->
|
|
|
|
:error
|
|
|
|
end
|
|
|
|
else
|
2023-12-28 21:52:05 -07:00
|
|
|
{:discard, "Unreachable instance"}
|
2023-12-26 13:54:14 -07:00
|
|
|
end
|
2020-01-25 00:47:30 -07:00
|
|
|
end
|
|
|
|
end
|