Support keep_unlisted param
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
0a2c1fef16
commit
a8224e3e40
4 changed files with 27 additions and 6 deletions
|
@ -71,14 +71,19 @@ def import_collection(
|
|||
"type" => type,
|
||||
"orderedItems" => objects
|
||||
},
|
||||
user
|
||||
%User{} = user,
|
||||
opts \\ []
|
||||
)
|
||||
when type in ["OrderedCollection", "Collection"] do
|
||||
objects
|
||||
|> Enum.each(fn object ->
|
||||
BackgroundWorker.enqueue(
|
||||
"import_object",
|
||||
%{"user_id" => user.id, "object" => object}
|
||||
%{
|
||||
"user_id" => user.id,
|
||||
"object" => object,
|
||||
"keep_unlisted" => opts[:keep_unlisted] || false
|
||||
}
|
||||
)
|
||||
end)
|
||||
end
|
||||
|
|
|
@ -84,6 +84,9 @@ defp import_request do
|
|||
%Schema{type: :string, format: :binary},
|
||||
%Schema{type: :string}
|
||||
]
|
||||
},
|
||||
keep_unlisted: %Schema{
|
||||
type: :boolean
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,10 +79,16 @@ def collection(%{body_params: %{list: %Plug.Upload{path: path}}} = conn, _) do
|
|||
collection(%Plug.Conn{conn | body_params: %{list: File.read!(path)}}, %{})
|
||||
end
|
||||
|
||||
def collection(%{assigns: %{user: user}, body_params: %{collection: collection}} = conn, _) do
|
||||
def collection(
|
||||
%{assigns: %{user: user}, body_params: %{collection: collection} = params} = conn,
|
||||
_
|
||||
) do
|
||||
collection
|
||||
|> Jason.decode!()
|
||||
|> Pleroma.Web.ActivityPub.Importer.import_collection(user)
|
||||
|> Pleroma.Web.ActivityPub.Importer.import_collection(user,
|
||||
keep_unlisted: Map.get(params, :keep_unlisted, false)
|
||||
)
|
||||
|
||||
json(conn, "job started")
|
||||
end
|
||||
|
||||
|
|
|
@ -50,9 +50,16 @@ def perform(%Job{args: %{"op" => "delete_instance", "host" => host}}) do
|
|||
Instance.perform(:delete_instance, host)
|
||||
end
|
||||
|
||||
def perform(%Job{args: %{"op" => "import_object", "user_id" => user_id, "object" => object}}) do
|
||||
def perform(%Job{
|
||||
args: %{
|
||||
"op" => "import_object",
|
||||
"user_id" => user_id,
|
||||
"object" => object,
|
||||
"keep_unlisted" => keep_unlisted
|
||||
}
|
||||
}) do
|
||||
user = User.get_by_id(user_id)
|
||||
Importer.import_one(object, user)
|
||||
Importer.import_one(object, user, keep_unlisted: keep_unlisted)
|
||||
end
|
||||
|
||||
@impl Oban.Worker
|
||||
|
|
Loading…
Reference in a new issue