2018-12-23 21:04:54 +01:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2017-03-30 16:08:49 +02:00
|
|
|
defmodule Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter do
|
|
|
|
use Pleroma.Web.TwitterAPI.Representers.BaseRepresenter
|
|
|
|
alias Pleroma.Object
|
|
|
|
|
2018-02-11 17:21:06 +01:00
|
|
|
def to_map(%Object{data: %{"url" => [url | _]}} = object, _opts) do
|
2017-03-30 16:08:49 +02:00
|
|
|
data = object.data
|
2018-03-30 15:01:53 +02:00
|
|
|
|
2017-03-30 16:08:49 +02:00
|
|
|
%{
|
2017-11-22 19:06:07 +01:00
|
|
|
url: url["href"] |> Pleroma.Web.MediaProxy.url(),
|
2018-07-12 19:06:28 +02:00
|
|
|
mimetype: url["mediaType"] || url["mimeType"],
|
2017-03-30 17:07:03 +02:00
|
|
|
id: data["uuid"],
|
2018-08-25 02:03:25 +02:00
|
|
|
oembed: false,
|
|
|
|
description: data["name"]
|
2017-03-30 16:08:49 +02:00
|
|
|
}
|
|
|
|
end
|
2017-03-30 17:07:03 +02:00
|
|
|
|
2018-02-11 17:21:06 +01:00
|
|
|
def to_map(%Object{data: %{"url" => url} = data}, _opts) when is_binary(url) do
|
|
|
|
%{
|
|
|
|
url: url |> Pleroma.Web.MediaProxy.url(),
|
2018-09-19 06:58:17 +02:00
|
|
|
mimetype: data["mediaType"] || data["mimeType"],
|
2018-02-11 17:21:06 +01:00
|
|
|
id: data["uuid"],
|
2018-08-25 02:03:25 +02:00
|
|
|
oembed: false,
|
|
|
|
description: data["name"]
|
2018-02-11 17:21:06 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_map(%Object{}, _opts) do
|
|
|
|
%{}
|
|
|
|
end
|
|
|
|
|
2017-03-30 17:07:03 +02:00
|
|
|
# If we only get the naked data, wrap in an object
|
|
|
|
def to_map(%{} = data, opts) do
|
|
|
|
to_map(%Object{data: data}, opts)
|
|
|
|
end
|
2017-03-30 16:08:49 +02:00
|
|
|
end
|