Collection importing route (WIP)
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
c39fae12bc
commit
822b9edbfe
4 changed files with 38 additions and 2 deletions
|
@ -65,6 +65,15 @@ def import_one(%{"type" => type} = object, %User{} = user, opts \\ []) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def import_collection(%{
|
||||||
|
"type" => type,
|
||||||
|
"orderedItems" => objects
|
||||||
|
}, user)
|
||||||
|
when type in ["OrderedCollection", "Collection"] do
|
||||||
|
objects
|
||||||
|
|> Enum.each(&import_one(&1, user))
|
||||||
|
end
|
||||||
|
|
||||||
defp strip_ap_id(object), do: object |> Map.drop(["id"])
|
defp strip_ap_id(object), do: object |> Map.drop(["id"])
|
||||||
|
|
||||||
defp rewrite_actor(object, user) do
|
defp rewrite_actor(object, user) do
|
||||||
|
|
|
@ -58,12 +58,26 @@ def mutes_operation do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def collection_operation do
|
||||||
|
%Operation{
|
||||||
|
tags: ["Data import"],
|
||||||
|
summary: "Import collection",
|
||||||
|
operationId: "UserImportController.collection",
|
||||||
|
requestBody: request_body("Parameters", import_request(), required: true),
|
||||||
|
responses: %{
|
||||||
|
200 => ok_response(),
|
||||||
|
500 => Operation.response("Error", "application/json", ApiError)
|
||||||
|
},
|
||||||
|
security: [%{"oAuth" => ["write:statuses"]}]
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
defp import_request do
|
defp import_request do
|
||||||
%Schema{
|
%Schema{
|
||||||
type: :object,
|
type: :object,
|
||||||
required: [:list],
|
required: [:collection],
|
||||||
properties: %{
|
properties: %{
|
||||||
list: %Schema{
|
collection: %Schema{
|
||||||
description:
|
description:
|
||||||
"STRING or FILE containing a whitespace-separated list of accounts to import.",
|
"STRING or FILE containing a whitespace-separated list of accounts to import.",
|
||||||
anyOf: [
|
anyOf: [
|
||||||
|
|
|
@ -14,6 +14,7 @@ defmodule Pleroma.Web.PleromaAPI.UserImportController do
|
||||||
plug(OAuthScopesPlug, %{scopes: ["follow", "write:follows"]} when action == :follow)
|
plug(OAuthScopesPlug, %{scopes: ["follow", "write:follows"]} when action == :follow)
|
||||||
plug(OAuthScopesPlug, %{scopes: ["follow", "write:blocks"]} when action == :blocks)
|
plug(OAuthScopesPlug, %{scopes: ["follow", "write:blocks"]} when action == :blocks)
|
||||||
plug(OAuthScopesPlug, %{scopes: ["follow", "write:mutes"]} when action == :mutes)
|
plug(OAuthScopesPlug, %{scopes: ["follow", "write:mutes"]} when action == :mutes)
|
||||||
|
plug(OAuthScopesPlug, %{scopes: ["follow", "write:statuses"]} when action == :collection)
|
||||||
|
|
||||||
plug(Pleroma.Web.ApiSpec.CastAndValidate, replace_params: false)
|
plug(Pleroma.Web.ApiSpec.CastAndValidate, replace_params: false)
|
||||||
defdelegate open_api_operation(action), to: ApiSpec.UserImportOperation
|
defdelegate open_api_operation(action), to: ApiSpec.UserImportOperation
|
||||||
|
@ -74,6 +75,17 @@ defp do_mute(%{assigns: %{user: user}} = conn, list) do
|
||||||
json(conn, "job started")
|
json(conn, "job started")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
collection
|
||||||
|
|> Jason.decode!()
|
||||||
|
|> Pleroma.Web.ActivityPub.Importer.import_collection(user)
|
||||||
|
json(conn, "job started")
|
||||||
|
end
|
||||||
|
|
||||||
defp prepare_user_identifiers(list) do
|
defp prepare_user_identifiers(list) do
|
||||||
list
|
list
|
||||||
|> String.split()
|
|> String.split()
|
||||||
|
|
|
@ -567,6 +567,7 @@ defmodule Pleroma.Web.Router do
|
||||||
post("/mutes_import", UserImportController, :mutes)
|
post("/mutes_import", UserImportController, :mutes)
|
||||||
post("/blocks_import", UserImportController, :blocks)
|
post("/blocks_import", UserImportController, :blocks)
|
||||||
post("/follow_import", UserImportController, :follow)
|
post("/follow_import", UserImportController, :follow)
|
||||||
|
post("/collection_import", UserImportController, :collection)
|
||||||
|
|
||||||
get("/accounts/mfa", TwoFactorAuthenticationController, :settings)
|
get("/accounts/mfa", TwoFactorAuthenticationController, :settings)
|
||||||
get("/accounts/mfa/backup_codes", TwoFactorAuthenticationController, :backup_codes)
|
get("/accounts/mfa/backup_codes", TwoFactorAuthenticationController, :backup_codes)
|
||||||
|
|
Loading…
Reference in a new issue