summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMark Felder <feld@feld.me>2024-10-27 21:52:42 -0400
committerMark Felder <feld@feld.me>2024-10-27 21:52:42 -0400
commit7d5ef8173735015c473fbc292a7f4b23d3e504a1 (patch)
treed3df021015cf7e0aa2706494553f1b3fe1be2ca2 /lib
parent2d591aedaeda3d80e9c1b31c0c83eae954849f36 (diff)
downloadpleroma-7d5ef8173735015c473fbc292a7f4b23d3e504a1.tar.gz
pleroma-7d5ef8173735015c473fbc292a7f4b23d3e504a1.zip
Fix /api/v2/media returning the wrong status code for media processed synchronously
The API should return a 202 only if data cannot be returned yet and a followup GET /api/v1/media/:id should be called to retrieve it. This is something Mastodon does when it needs to transcode large media files. It does not apply to Pleroma and causes apps to waste an API call when posting a status which causes apps to appear to hang on higher latency environments, such as on mobile networks. https://docs.joinmastodon.org/methods/media/#v2
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/api_spec/operations/media_operation.ex2
-rw-r--r--lib/pleroma/web/mastodon_api/controllers/media_controller.ex4
2 files changed, 2 insertions, 4 deletions
diff --git a/lib/pleroma/web/api_spec/operations/media_operation.ex b/lib/pleroma/web/api_spec/operations/media_operation.ex
index e6df21246..588b42e06 100644
--- a/lib/pleroma/web/api_spec/operations/media_operation.ex
+++ b/lib/pleroma/web/api_spec/operations/media_operation.ex
@@ -121,7 +121,7 @@ defmodule Pleroma.Web.ApiSpec.MediaOperation do
security: [%{"oAuth" => ["write:media"]}],
requestBody: Helpers.request_body("Parameters", create_request()),
responses: %{
- 202 => Operation.response("Media", "application/json", Attachment),
+ 200 => Operation.response("Media", "application/json", Attachment),
400 => Operation.response("Media", "application/json", ApiError),
422 => Operation.response("Media", "application/json", ApiError),
500 => Operation.response("Media", "application/json", ApiError)
diff --git a/lib/pleroma/web/mastodon_api/controllers/media_controller.ex b/lib/pleroma/web/mastodon_api/controllers/media_controller.ex
index 056bad844..41056d389 100644
--- a/lib/pleroma/web/mastodon_api/controllers/media_controller.ex
+++ b/lib/pleroma/web/mastodon_api/controllers/media_controller.ex
@@ -53,9 +53,7 @@ defmodule Pleroma.Web.MastodonAPI.MediaController do
) do
attachment_data = Map.put(object.data, "id", object.id)
- conn
- |> put_status(202)
- |> render("attachment.json", %{attachment: attachment_data})
+ render(conn, "attachment.json", %{attachment: attachment_data})
end
end