Remove oembed for now, will submit it in another MR. Fix warnings
authorraeno <just.raeno@gmail.com>
Thu, 13 Dec 2018 21:16:54 +0000 (22:16 +0100)
committerraeno <just.raeno@gmail.com>
Thu, 13 Dec 2018 21:34:15 +0000 (22:34 +0100)
config/config.exs
lib/pleroma/formatter.ex
lib/pleroma/web/oembed/activity_representer.ex [deleted file]
lib/pleroma/web/oembed/oembed.ex [deleted file]
lib/pleroma/web/oembed/oembed_controller.ex [deleted file]
lib/pleroma/web/oembed/views/note_view.ex [deleted file]
lib/pleroma/web/ostatus/metadata.ex
lib/pleroma/web/ostatus/ostatus.ex
lib/pleroma/web/ostatus/ostatus_controller.ex
lib/pleroma/web/router.ex
test/web/oembed/oembed_test.exs [deleted file]

index ad4b79f54a81d41f69a00d7e543b027decc3ce99..5477c0c0e8418426685d54ea9bdfe23bd6014307 100644 (file)
@@ -171,9 +171,7 @@ config :pleroma, :gopher,
   ip: {0, 0, 0, 0},
   port: 9999
 
-config :pleroma, :metadata,
-  oembed: false,
-  opengraph: true
+config :pleroma, :metadata, opengraph: true
 
 config :pleroma, :suggestions,
   enabled: false,
index b63f592fbc9218a84d72b3ea24dc82f0f8121a35..1d5dc0c99c7411e88a36e3b83940cde8f3809f84 100644 (file)
@@ -165,14 +165,16 @@ defmodule Pleroma.Formatter do
   end
 
   def truncate(text, opts \\ []) do
-    max_length  = opts[:max_length] || 200
-    omission    = opts[:omission] || "..."
+    max_length = opts[:max_length] || 200
+    omission = opts[:omission] || "..."
 
     cond do
       not String.valid?(text) ->
         text
+
       String.length(text) < max_length ->
         text
+
       true ->
         length_with_omission = max_length - String.length(omission)
 
diff --git a/lib/pleroma/web/oembed/activity_representer.ex b/lib/pleroma/web/oembed/activity_representer.ex
deleted file mode 100644 (file)
index 0e65090..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-defmodule Pleroma.Web.OEmbed.ActivityRepresenter do
-  alias Pleroma.{Activity, User, Object}
-  alias Pleroma.Web.OStatus.UserRepresenter
-
-  def to_simple_form(%{data: %{"object" => %{"type" => "Note"}}} = activity, user, with_author) do
-    h = fn str -> [to_charlist(str)] end
-
-    content =  if activity.data["object"]["content"] do
-      [{:content, [], h.(activity.data["object"]["content"])}]
-    else
-      []
-    end
-
-    [
-      {:version, ["1.0"]},
-      {:type, ["link"]},
-    ] ++ content
-
-  end
-
-  def wrap_with_entry(simple_form) do
-    [ { :oembed, [], simple_form } ]
-  end
-
-end
diff --git a/lib/pleroma/web/oembed/oembed.ex b/lib/pleroma/web/oembed/oembed.ex
deleted file mode 100644 (file)
index a52aa60..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-defmodule Pleroma.Web.OEmbed do
-  alias Pleroma.{Repo, Object, Activity, User}
-  alias Pleroma.Formatter
-
-  def recognize_path(url) do
-    details = Regex.named_captures(~r/.+\/(?<route>.+)\/(?<id>\w+).*$/, url)
-
-    case details do
-      %{ "route" => "notice", "id" => id } ->
-                                    %{type: :activity, entity: Repo.get(Activity, id) }
-      %{ "route" => "users", "id" => nickname } ->
-                                    %{type: :user, entity: User.get_by_nickname(nickname) }
-      _ ->
-        { :error, "no matching route"}
-    end
-  end
-
-  def truncated_content(activity) do
-    content = activity.data['object']['content']
-    IO.puts(content)
-    Formatter.truncate(content)
-  end
-end
diff --git a/lib/pleroma/web/oembed/oembed_controller.ex b/lib/pleroma/web/oembed/oembed_controller.ex
deleted file mode 100644 (file)
index d63d3c5..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-defmodule Pleroma.Web.OEmbed.OEmbedController do
-  use Pleroma.Web, :controller
-
-  alias Pleroma.Web.OEmbed
-  alias Pleroma.Web.OEmbed.{NoteView, ActivityRepresenter}
-  alias Pleroma.Web.MediaProxy
-  alias Pleroma.Repo
-  alias Pleroma.User
-
-  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
-    conn
-    |> put_resp_content_type("application/json")
-    |> 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)
-
-  end
-end
diff --git a/lib/pleroma/web/oembed/views/note_view.ex b/lib/pleroma/web/oembed/views/note_view.ex
deleted file mode 100644 (file)
index ecdabc0..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-defmodule Pleroma.Web.OEmbed.NoteView do
-  use Pleroma.Web, :view
-  alias Pleroma.{User, Activity}
-  alias Pleroma.Web.OEmbed
-
-  def render("note.json", %{type: type, entity: activity }) do
-    oembed_data(activity)
-  end
-
-  def oembed_data(activity) do
-    with %User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]),
-         image = User.avatar_url(user) |> MediaProxy.url() do
-      %{
-        version: "1.0",
-        type: "link",
-        title: OEmbed.truncated_content(activity),
-        provider_url: "https://pleroma.site",
-        thumbnail_url: image,
-      }
-  end
-end
index 4f319b3607003da149ccddd96e82fd817890cfeb..792b4a4bd6ab3b3513eb74842e3a36a101a4bd5a 100644 (file)
@@ -1,14 +1,10 @@
 defmodule Pleroma.Web.Metadata do
   alias Phoenix.HTML
-  alias Pleroma.{Web, Formatter}
-  alias Pleroma.{User, Activity}
+  alias Pleroma.{Formatter, User}
   alias Pleroma.Web.MediaProxy
 
-  def build_tags(request_url, params) do
-    Enum.concat([
-      if(meta_enabled?(:opengraph), do: opengraph_tags(params), else: []),
-      if(meta_enabled?(:oembed), do: oembed_links(request_url), else: [])
-    ])
+  def build_tags(params) do
+    if(meta_enabled?(:opengraph), do: opengraph_tags(params), else: [])
     |> Enum.map(&to_tag/1)
     |> Enum.map(&HTML.safe_to_string/1)
     |> Enum.join("\n")
@@ -24,13 +20,12 @@ defmodule Pleroma.Web.Metadata do
     with truncated_content = Formatter.truncate(activity.data["object"]["content"]) do
       [
         {:meta,
-          [
-            property: "og:title",
-            content: "#{user.name} (@#{user.nickname}@#{pleroma_domain()}) post ##{activity.id}"
-          ], []},
+         [
+           property: "og:title",
+           content: "#{user.name} (@#{user.nickname}@#{pleroma_domain()}) post ##{activity.id}"
+         ], []},
         {:meta, [property: "og:url", content: activity.data["id"]], []},
-        {:meta, [property: "og:description", content: truncated_content],
-          []},
+        {:meta, [property: "og:description", content: truncated_content], []},
         {:meta, [property: "og:image", content: user_avatar_url(user)], []},
         {:meta, [property: "og:image:width", content: 120], []},
         {:meta, [property: "og:image:height", content: 120], []},
@@ -44,10 +39,10 @@ defmodule Pleroma.Web.Metadata do
     with truncated_bio = Formatter.truncate(user.bio) do
       [
         {:meta,
-          [
-            property: "og:title",
-            content: "#{user.name} (@#{user.nickname}@#{pleroma_domain()}) profile"
-          ], []},
+         [
+           property: "og:title",
+           content: "#{user.name} (@#{user.nickname}@#{pleroma_domain()}) profile"
+         ], []},
         {:meta, [property: "og:url", content: User.profile_url(user)], []},
         {:meta, [property: "og:description", content: truncated_bio], []},
         {:meta, [property: "og:image", content: user_avatar_url(user)], []},
@@ -58,13 +53,6 @@ defmodule Pleroma.Web.Metadata do
     end
   end
 
-  defp oembed_links(url) do
-    Enum.map(["xml", "json"], fn format ->
-      href = HTML.raw(oembed_path(url, format))
-      { :link, [ type: ["application/#{format}+oembed"], href: href, rel: 'alternate'], [] }
-    end)
-  end
-
   def to_tag(data) do
     with {name, attrs, _content = []} <- data do
       HTML.Tag.tag(name, attrs)
@@ -77,11 +65,6 @@ defmodule Pleroma.Web.Metadata do
     end
   end
 
-  defp oembed_path(url, format) do
-    query = URI.encode_query(%{url: url, format: format})
-    "#{Web.base_url()}/oembed?#{query}"
-  end
-
   defp user_avatar_url(user) do
     User.avatar_url(user) |> MediaProxy.url()
   end
@@ -89,4 +72,4 @@ defmodule Pleroma.Web.Metadata do
   def pleroma_domain do
     Pleroma.Config.get([:instance, :domain], "UNKNOWN_DOMAIN")
   end
-end
\ No newline at end of file
+end
index ba44b2e9907387895c472b6d0202286612c1be1f..c6440c20e9daa1d1248494fb201fe7aed7785b6a 100644 (file)
@@ -5,7 +5,7 @@ defmodule Pleroma.Web.OStatus do
   import Pleroma.Web.XML
   require Logger
 
-  alias Pleroma.{Repo, User, Web, Object, Activity, Formatter}
+  alias Pleroma.{Repo, User, Web, Object, Activity}
   alias Pleroma.Web.ActivityPub.ActivityPub
   alias Pleroma.Web.{WebFinger, Websub}
   alias Pleroma.Web.OStatus.{FollowHandler, UnfollowHandler, NoteHandler, DeleteHandler}
index fbd25c5f53c8d23032b7d9d61a1f7c54807355ed..55dbcab9302e56fbdc939da096be0ec1748fe913 100644 (file)
@@ -14,9 +14,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do
   action_fallback(:errors)
 
   def feed_redirect(conn, %{"nickname" => nickname}) do
-    format = get_format(conn)
-    IO.puts(format)
-    case format do
+    case get_format(conn) do
       "html" ->
         with %User{} = user <- User.get_cached_by_nickname(nickname) do
           Fallback.RedirectController.redirector_with_meta(conn, %{user: user})
index ad26093acaf24ec5f8f2a0f5fca0e3bb8933c1f1..914cd6a6d2f53e9c6bea0b471881716a2e93764b 100644 (file)
@@ -453,8 +453,8 @@ defmodule Fallback.RedirectController do
   end
 
   def redirector_with_meta(conn, params) do
-    {:ok, index_content } = File.read(Application.app_dir(:pleroma, "priv/static/index.html"))
-    tags = Metadata.build_tags(request_url(conn), params)
+    {:ok, index_content} = File.read(Application.app_dir(:pleroma, "priv/static/index.html"))
+    tags = Metadata.build_tags(params)
     response = String.replace(index_content, "<!--server-generated-meta-->", tags)
 
     conn
diff --git a/test/web/oembed/oembed_test.exs b/test/web/oembed/oembed_test.exs
deleted file mode 100644 (file)
index 16c2c35..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-defmodule Pleroma.Web.OEmbedTest do
-  use Pleroma.DataCase
-  alias Pleroma.Web.OEmbed
-  alias Pleroma.Web.XML
-  alias Pleroma.{Object, Repo, User, Activity}
-  import Pleroma.Factory
-  import ExUnit.CaptureLog
-
-  setup_all do
-    :ok
-  end
-
-  test 'recognizes notices in given url' do
-    url = "https://pleroma.site/notice/5"
-    assert { :activity, _ } = OEmbed.recognize_path(url)
-  end
-
-  test 'recognizes user card in given url' do
-    url = "https://pleroma.site/users/raeno"
-    assert { :user, _ } = OEmbed.recognize_path(url)
-  end
-
-end