mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-12-03 10:14:20 +00:00
Remove oembed for now, will submit it in another MR. Fix warnings
This commit is contained in:
parent
018516d3f3
commit
b5de7c4c4d
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
||||
end
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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})
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
Loading…
Reference in a new issue