forked from AkkomaGang/akkoma
Twitter Representers: Handle Mastodon attachments.
This commit is contained in:
parent
ae1ec858f4
commit
ce31f3a922
2 changed files with 34 additions and 2 deletions
|
@ -2,9 +2,8 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter do
|
||||||
use Pleroma.Web.TwitterAPI.Representers.BaseRepresenter
|
use Pleroma.Web.TwitterAPI.Representers.BaseRepresenter
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
|
|
||||||
def to_map(%Object{} = object, _opts) do
|
def to_map(%Object{data: %{"url" => [url | _]}} = object, _opts) do
|
||||||
data = object.data
|
data = object.data
|
||||||
url = List.first(data["url"])
|
|
||||||
%{
|
%{
|
||||||
url: url["href"] |> Pleroma.Web.MediaProxy.url(),
|
url: url["href"] |> Pleroma.Web.MediaProxy.url(),
|
||||||
mimetype: url["mediaType"],
|
mimetype: url["mediaType"],
|
||||||
|
@ -13,6 +12,19 @@ def to_map(%Object{} = object, _opts) do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def to_map(%Object{data: %{"url" => url} = data}, _opts) when is_binary(url) do
|
||||||
|
%{
|
||||||
|
url: url |> Pleroma.Web.MediaProxy.url(),
|
||||||
|
mimetype: data["mediaType"],
|
||||||
|
id: data["uuid"],
|
||||||
|
oembed: false
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_map(%Object{}, _opts) do
|
||||||
|
%{}
|
||||||
|
end
|
||||||
|
|
||||||
# If we only get the naked data, wrap in an object
|
# If we only get the naked data, wrap in an object
|
||||||
def to_map(%{} = data, opts) do
|
def to_map(%{} = data, opts) do
|
||||||
to_map(%Object{data: data}, opts)
|
to_map(%Object{data: data}, opts)
|
||||||
|
|
|
@ -28,4 +28,24 @@ test "represent an image attachment" do
|
||||||
|
|
||||||
assert expected_object == ObjectRepresenter.to_map(object)
|
assert expected_object == ObjectRepresenter.to_map(object)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "represents mastodon-style attachments" do
|
||||||
|
object = %Object{
|
||||||
|
id: nil,
|
||||||
|
data: %{
|
||||||
|
"mediaType" => "image/png",
|
||||||
|
"name" => "blabla", "type" => "Document",
|
||||||
|
"url" => "http://mastodon.example.org/system/media_attachments/files/000/000/001/original/8619f31c6edec470.png"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
expected_object = %{
|
||||||
|
url: "http://mastodon.example.org/system/media_attachments/files/000/000/001/original/8619f31c6edec470.png",
|
||||||
|
mimetype: "image/png",
|
||||||
|
oembed: false,
|
||||||
|
id: nil
|
||||||
|
}
|
||||||
|
|
||||||
|
assert expected_object == ObjectRepresenter.to_map(object)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue