AP C2S, uploadMedia: Add support for object parameter
This commit is contained in:
parent
93bdc55306
commit
6d0d6a654e
|
@ -479,17 +479,19 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do
|
||||||
{new_user, for_user}
|
{new_user, for_user}
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: Add support for "object" field
|
|
||||||
@doc """
|
@doc """
|
||||||
Endpoint based on <https://www.w3.org/wiki/SocialCG/ActivityPub/MediaUpload>
|
Endpoint based on <https://www.w3.org/wiki/SocialCG/ActivityPub/MediaUpload>
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
- (required) `file`: data of the media
|
- (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
|
- (optionnal) `description`: description of the media, intended for accessibility
|
||||||
|
|
||||||
Response:
|
Response:
|
||||||
- HTTP Code: 201 Created
|
- HTTP Code: 201 Created
|
||||||
- HTTP Body: ActivityPub object to be inserted into another's `attachment` field
|
- 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
|
def upload_media(%{assigns: %{user: user}} = conn, %{"file" => file} = data) do
|
||||||
with {:ok, object} <-
|
with {:ok, object} <-
|
||||||
|
@ -498,11 +500,24 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do
|
||||||
actor: User.ap_id(user),
|
actor: User.ap_id(user),
|
||||||
description: Map.get(data, "description")
|
description: Map.get(data, "description")
|
||||||
) do
|
) 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
|
conn
|
||||||
|> put_status(:created)
|
|> put_status(:created)
|
||||||
|> json(object.data)
|
|> json(object_data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -942,15 +942,26 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
||||||
filename: "an_image.jpg"
|
filename: "an_image.jpg"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
base_object = %{
|
||||||
|
"generator" => "#cofe machine",
|
||||||
|
"id" => "http://invalid.host/foo/bar"
|
||||||
|
}
|
||||||
|
|
||||||
conn =
|
conn =
|
||||||
conn
|
conn
|
||||||
|> assign(:user, user)
|
|> 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 = json_response(conn, :created)
|
||||||
assert object["name"] == desc
|
assert object["name"] == desc
|
||||||
assert object["type"] == "Document"
|
assert object["type"] == "Document"
|
||||||
assert object["actor"] == user.ap_id
|
assert object["actor"] == user.ap_id
|
||||||
|
assert object["generator"] == base_object["generator"]
|
||||||
|
refute object["id"] == base_object["id"]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue