Skip to content
Snippets Groups Projects
Commit 641c24cd authored by lain's avatar lain
Browse files

Add media upload endpoint.

parent 31849390
No related branches found
No related tags found
No related merge requests found
......@@ -199,6 +199,15 @@ def relationships(%{assigns: %{user: user}} = conn, %{"id" => id}) do
render conn, AccountView, "relationships.json", %{user: user, targets: targets}
end
def upload(%{assigns: %{user: user}} = conn, %{"file" => file}) do
with {:ok, object} <- ActivityPub.upload(file) do
data = object.data
|> Map.put("id", object.id)
render conn, StatusView, "attachment.json", %{attachment: data}
end
end
def empty_array(conn, _) do
Logger.debug("Unimplemented, returning an empty array")
json(conn, [])
......
......@@ -55,6 +55,8 @@ def user_fetcher(username) do
post "/statuses/:id/unfavourite", MastodonAPIController, :unfav_status
get "/notifications", MastodonAPIController, :notifications
post "/media", MastodonAPIController, :upload
end
scope "/api/v1", Pleroma.Web.MastodonAPI do
......
......@@ -213,4 +213,18 @@ test "account fetching", %{conn: conn} do
assert %{"error" => "Can't find user"} = json_response(conn, 404)
end
test "media upload", %{conn: conn} do
file = %Plug.Upload{content_type: "image/jpg", path: Path.absname("test/fixtures/image.jpg"), filename: "an_image.jpg"}
user = insert(:user)
conn = conn
|> assign(:user, user)
|> post("/api/v1/media", %{"file" => file})
assert media = json_response(conn, 200)
assert media["type"] == "image"
end
end
......@@ -76,5 +76,9 @@ test "attachments" do
}
assert expected == StatusView.render("attachment.json", %{attachment: object})
# If theres a "id", use that instead of the generated one
object = Map.put(object, "id", 2)
assert %{id: 2} = StatusView.render("attachment.json", %{attachment: object})
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment