--- /dev/null
+defmodule Pleroma.Web.OEmbed.OEmbedController do
+ use Pleroma.Web, :controller
+
+ alias Pleroma.Repo
+
+ def url(conn, %{ "url" => uri} ) do
+ conn
+ |> put_resp_content_type("application/json")
+ |> json(%{ status: "success"} )
+ end
+end
\ No newline at end of file
end
end
+ def metadata(url), do: oembed_links(url)
+
+ def oembed_links(url) do
+ Enum.map(["xml", "json"], fn format ->
+ href = oembed_path(url, format)
+ "<link rel=\"alternate\" type=\"application/#{format}+oembed\" href=\"#{href}\""
+ end)
+ |> Enum.join("\r\n")
+ end
+
def feed_path(user) do
"#{user.ap_id}/feed.atom"
end
"#{Web.base_url()}/ostatus_subscribe?acct={uri}"
end
+ def oembed_path(url, format) do
+ query = URI.encode_query(%{url: url, format: format})
+ "#{Web.base_url()}/oembed?#{query}"
+ end
+
def handle_incoming(xml_string) do
with doc when doc != :error <- parse_document(xml_string) do
entries = :xmerl_xpath.string('//entry', doc)
alias Pleroma.Web.ActivityPub.ObjectView
alias Pleroma.Web.ActivityPub.ActivityPubController
alias Pleroma.Web.ActivityPub.ActivityPub
+ alias Pleroma.Router.Helpers, as: Routes
plug(Pleroma.Web.FederatingPlug when action in [:salmon_incoming])
action_fallback(:errors)
%User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]) do
case format = get_format(conn) do
"html" ->
- conn
- |> put_resp_content_type("text/html")
- |> send_file(200, Application.app_dir(:pleroma, "priv/static/index.html"))
+ serve_static_with_meta(conn, activity)
_ ->
represent_activity(conn, format, activity, user)
end
end
+ defp serve_static_with_meta(conn, activity) do
+ {:ok, index_content } = File.read(Application.app_dir(:pleroma, "priv/static/index.html"))
+ links = OStatus.metadata(request_url(conn))
+ response = String.replace(index_content, "<!--server-generated-meta-->", links)
+ conn
+ |> put_resp_content_type("text/html")
+ |> send_resp(200, response)
+ end
+
defp represent_activity(
conn,
"activity+json",
plug(:accepts, ["xml", "atom", "html", "activity+json"])
end
+ pipeline :oembed do
+ plug(:accepts, ["json", "xml"])
+ end
+
scope "/", Pleroma.Web do
pipe_through(:ostatus)
post("/push/subscriptions/:id", Websub.WebsubController, :websub_incoming)
end
+ scope "/", Pleroma.Web do
+ pipe_through(:oembed)
+
+ get("/oembed", OEmbed.OEmbedController, :url)
+ end
+
pipeline :activitypub do
plug(:accepts, ["activity+json"])
plug(Pleroma.Web.Plugs.HTTPSignaturePlug)