2018-12-10 05:25:33 -07:00
|
|
|
defmodule Pleroma.Web.OEmbed.OEmbedController do
|
|
|
|
use Pleroma.Web, :controller
|
|
|
|
|
2018-12-10 12:08:02 -07:00
|
|
|
alias Pleroma.Web.OEmbed
|
|
|
|
alias Pleroma.Web.OEmbed.{NoteView, ActivityRepresenter}
|
|
|
|
alias Pleroma.Web.MediaProxy
|
2018-12-10 05:25:33 -07:00
|
|
|
alias Pleroma.Repo
|
2018-12-10 12:08:02 -07:00
|
|
|
alias Pleroma.User
|
2018-12-10 05:25:33 -07:00
|
|
|
|
2018-12-10 12:08:02 -07:00
|
|
|
def url(conn, %{ "url" => url} ) do
|
|
|
|
case format = get_format(conn) do
|
|
|
|
_ ->
|
|
|
|
result = OEmbed.recognize_path(url)
|
|
|
|
render_oembed(conn, format, result)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def render_oembed(conn, format \\ "json", result)
|
|
|
|
def render_oembed(conn, "json", result) do
|
2018-12-10 05:25:33 -07:00
|
|
|
conn
|
|
|
|
|> put_resp_content_type("application/json")
|
2018-12-10 12:08:02 -07:00
|
|
|
|> json(NoteView.render("note.json", result))
|
|
|
|
end
|
|
|
|
|
|
|
|
def render_oembed(conn, "xml", result) do
|
|
|
|
conn
|
|
|
|
|> put_resp_content_type("application/xml")
|
|
|
|
|> NoteView.render("note.json", result)
|
|
|
|
|
2018-12-10 05:25:33 -07:00
|
|
|
end
|
2018-12-10 12:08:02 -07:00
|
|
|
end
|