diff --git a/lib/pleroma/web/activity_pub/activity_pub_controller.ex b/lib/pleroma/web/activity_pub/activity_pub_controller.ex index 080030eb5..31e905724 100644 --- a/lib/pleroma/web/activity_pub/activity_pub_controller.ex +++ b/lib/pleroma/web/activity_pub/activity_pub_controller.ex @@ -479,17 +479,19 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do {new_user, for_user} end - # TODO: Add support for "object" field @doc """ Endpoint based on Parameters: - (required) `file`: data of the media + - (optionnal) `object`: object which will be used as a base for the response - (optionnal) `description`: description of the media, intended for accessibility Response: - HTTP Code: 201 Created - HTTP Body: ActivityPub object to be inserted into another's `attachment` field + + Note: Will not point to a URL with a `Location` header because no standalone Activity has been created """ def upload_media(%{assigns: %{user: user}} = conn, %{"file" => file} = data) do with {:ok, object} <- @@ -498,11 +500,24 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do actor: User.ap_id(user), description: Map.get(data, "description") ) do - Logger.debug(inspect(object)) + object_data = + (data["object"] || %{}) + |> Map.drop([ + "attachment", + "attributedTo", + "audience", + "url", + "id", + "to", + "bto", + "cc", + "bcc" + ]) + |> Map.merge(object.data) conn |> put_status(:created) - |> json(object.data) + |> json(object_data) end end end diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs index 6a3e48b5e..4a322ba9c 100644 --- a/test/web/activity_pub/activity_pub_controller_test.exs +++ b/test/web/activity_pub/activity_pub_controller_test.exs @@ -942,15 +942,26 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do filename: "an_image.jpg" } + base_object = %{ + "generator" => "#cofe machine", + "id" => "http://invalid.host/foo/bar" + } + conn = conn |> assign(:user, user) - |> post("/api/ap/upload_media", %{"file" => image, "description" => desc}) + |> post("/api/ap/upload_media", %{ + "file" => image, + "description" => desc, + "object" => base_object + }) assert object = json_response(conn, :created) assert object["name"] == desc assert object["type"] == "Document" assert object["actor"] == user.ap_id + assert object["generator"] == base_object["generator"] + refute object["id"] == base_object["id"] end end end