object_representer.ex 809 Bytes
Newer Older
lain's avatar
lain committed
1
2
3
4
defmodule Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter do
  use Pleroma.Web.TwitterAPI.Representers.BaseRepresenter
  alias Pleroma.Object

5
  def to_map(%Object{data: %{"url" => [url | _]}} = object, _opts) do
lain's avatar
lain committed
6
7
    data = object.data
    %{
href's avatar
href committed
8
      url: url["href"] |> Pleroma.Web.MediaProxy.url(),
lain's avatar
lain committed
9
      mimetype: url["mediaType"],
lain's avatar
lain committed
10
      id: data["uuid"],
lain's avatar
lain committed
11
12
13
      oembed: false
    }
  end
lain's avatar
lain committed
14

15
16
17
18
19
20
21
22
23
24
25
26
27
  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

lain's avatar
lain committed
28
29
30
31
  # If we only get the naked data, wrap in an object
  def to_map(%{} = data, opts) do
    to_map(%Object{data: data}, opts)
  end
lain's avatar
lain committed
32
end