From: raeno Date: Thu, 13 Dec 2018 21:16:54 +0000 (+0100) Subject: Remove oembed for now, will submit it in another MR. Fix warnings X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=b5de7c4c4d90d1049b59381953cbd76e79b77e66;p=akkoma Remove oembed for now, will submit it in another MR. Fix warnings --- diff --git a/config/config.exs b/config/config.exs index ad4b79f54..5477c0c0e 100644 --- a/config/config.exs +++ b/config/config.exs @@ -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, diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index b63f592fb..1d5dc0c99 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -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 index 0e65090ee..000000000 --- a/lib/pleroma/web/oembed/activity_representer.ex +++ /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 index a52aa6004..000000000 --- a/lib/pleroma/web/oembed/oembed.ex +++ /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/.+\/(?.+)\/(?\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 index d63d3c58c..000000000 --- a/lib/pleroma/web/oembed/oembed_controller.ex +++ /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 index ecdabc04b..000000000 --- a/lib/pleroma/web/oembed/views/note_view.ex +++ /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 diff --git a/lib/pleroma/web/ostatus/metadata.ex b/lib/pleroma/web/ostatus/metadata.ex index 4f319b360..792b4a4bd 100644 --- a/lib/pleroma/web/ostatus/metadata.ex +++ b/lib/pleroma/web/ostatus/metadata.ex @@ -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 diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex index ba44b2e99..c6440c20e 100644 --- a/lib/pleroma/web/ostatus/ostatus.ex +++ b/lib/pleroma/web/ostatus/ostatus.ex @@ -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} diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex index fbd25c5f5..55dbcab93 100644 --- a/lib/pleroma/web/ostatus/ostatus_controller.ex +++ b/lib/pleroma/web/ostatus/ostatus_controller.ex @@ -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}) diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index ad26093ac..914cd6a6d 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -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, "", tags) conn diff --git a/test/web/oembed/oembed_test.exs b/test/web/oembed/oembed_test.exs deleted file mode 100644 index 16c2c3598..000000000 --- a/test/web/oembed/oembed_test.exs +++ /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