forked from YokaiRick/akkoma
encode data properly
This commit is contained in:
parent
d67b302810
commit
f73b2063f4
6 changed files with 55 additions and 45 deletions
|
@ -4,7 +4,9 @@
|
|||
|
||||
defmodule Fallback.RedirectController do
|
||||
use Pleroma.Web, :controller
|
||||
|
||||
require Logger
|
||||
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.Metadata
|
||||
alias Pleroma.Web.Preload
|
||||
|
@ -38,8 +40,7 @@ def redirector_with_meta(conn, params) do
|
|||
|
||||
response =
|
||||
index_content
|
||||
|> String.replace("<!--server-generated-meta-->", tags)
|
||||
|> String.replace("<!--server-generated-initial-data-->", preloads)
|
||||
|> String.replace("<!--server-generated-meta-->", tags <> preloads)
|
||||
|
||||
conn
|
||||
|> put_resp_content_type("text/html")
|
||||
|
@ -56,7 +57,7 @@ def redirector_with_preload(conn, params) do
|
|||
|
||||
response =
|
||||
index_content
|
||||
|> String.replace("<!--server-generated-initial-data-->", preloads)
|
||||
|> String.replace("<!--server-generated-meta-->", preloads)
|
||||
|
||||
conn
|
||||
|> put_resp_content_type("text/html")
|
||||
|
|
|
@ -22,6 +22,8 @@ def build_tags(_conn, params) do
|
|||
end
|
||||
|
||||
def build_script_tag(content) do
|
||||
content = Base.encode64(content)
|
||||
|
||||
HTML.Tag.content_tag(:script, HTML.raw(content),
|
||||
id: "initial-results",
|
||||
type: "application/json"
|
||||
|
|
|
@ -11,32 +11,29 @@ defmodule Pleroma.Web.Preload.Providers.Timelines do
|
|||
@public_url :"/api/v1/timelines/public"
|
||||
|
||||
@impl Provider
|
||||
def generate_terms(_params) do
|
||||
build_public_tag(%{})
|
||||
def generate_terms(params) do
|
||||
build_public_tag(%{}, params)
|
||||
end
|
||||
|
||||
def build_public_tag(acc) do
|
||||
def build_public_tag(acc, params) do
|
||||
if Pleroma.Config.get([:restrict_unauthenticated, :timelines, :federated], true) do
|
||||
acc
|
||||
else
|
||||
Map.put(acc, @public_url, public_timeline(nil))
|
||||
Map.put(acc, @public_url, public_timeline(params))
|
||||
end
|
||||
end
|
||||
|
||||
defp public_timeline(user) do
|
||||
defp public_timeline(%{"path" => ["main", "all"]}), do: get_public_timeline(false)
|
||||
|
||||
defp public_timeline(_params), do: get_public_timeline(true)
|
||||
|
||||
defp get_public_timeline(local_only) do
|
||||
activities =
|
||||
create_timeline_params(user)
|
||||
|> Map.put("local_only", false)
|
||||
|> ActivityPub.fetch_public_activities()
|
||||
ActivityPub.fetch_public_activities(%{
|
||||
"type" => ["Create"],
|
||||
"local_only" => local_only
|
||||
})
|
||||
|
||||
StatusView.render("index.json", activities: activities, for: user, as: :activity)
|
||||
end
|
||||
|
||||
defp create_timeline_params(user) do
|
||||
%{}
|
||||
|> Map.put("type", ["Create", "Announce"])
|
||||
|> Map.put("blocking_user", user)
|
||||
|> Map.put("muting_user", user)
|
||||
|> Map.put("user", user)
|
||||
StatusView.render("index.json", activities: activities, for: nil, as: :activity)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,7 +11,12 @@ test "GET /registration/:token", %{conn: conn} do
|
|||
response = get(conn, "/registration/foo")
|
||||
|
||||
assert html_response(response, 200) =~ "<!--server-generated-meta-->"
|
||||
assert html_response(response, 200) =~ "<!--server-generated-initial-data-->"
|
||||
end
|
||||
|
||||
test "GET /*path", %{conn: conn} do
|
||||
assert conn
|
||||
|> get("/foo")
|
||||
|> html_response(200) =~ "<!--server-generated-meta-->"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -21,20 +26,35 @@ test "GET /:maybe_nickname_or_id", %{conn: conn} do
|
|||
user_missing = get(conn, "/foo")
|
||||
user_present = get(conn, "/#{user.nickname}")
|
||||
|
||||
assert html_response(user_missing, 200) =~ "<!--server-generated-meta-->"
|
||||
assert(html_response(user_missing, 200) =~ "<!--server-generated-meta-->")
|
||||
refute html_response(user_present, 200) =~ "<!--server-generated-meta-->"
|
||||
assert html_response(user_present, 200) =~ "initial-results"
|
||||
end
|
||||
|
||||
assert html_response(user_missing, 200) =~ "<!--server-generated-initial-data-->"
|
||||
refute html_response(user_present, 200) =~ "<!--server-generated-initial-data-->"
|
||||
test "GET /*path", %{conn: conn} do
|
||||
assert conn
|
||||
|> get("/foo")
|
||||
|> html_response(200) =~ "<!--server-generated-meta-->"
|
||||
|
||||
refute conn
|
||||
|> get("/foo/bar")
|
||||
|> html_response(200) =~ "<!--server-generated-meta-->"
|
||||
end
|
||||
end
|
||||
|
||||
describe "preloaded data only attached to" do
|
||||
test "GET /*path", %{conn: conn} do
|
||||
describe "preloaded data is attached to" do
|
||||
test "GET /main/public", %{conn: conn} do
|
||||
public_page = get(conn, "/main/public")
|
||||
|
||||
assert html_response(public_page, 200) =~ "<!--server-generated-meta-->"
|
||||
refute html_response(public_page, 200) =~ "<!--server-generated-initial-data-->"
|
||||
refute html_response(public_page, 200) =~ "<!--server-generated-meta-->"
|
||||
assert html_response(public_page, 200) =~ "initial-results"
|
||||
end
|
||||
|
||||
test "GET /main/all", %{conn: conn} do
|
||||
public_page = get(conn, "/main/all")
|
||||
|
||||
refute html_response(public_page, 200) =~ "<!--server-generated-meta-->"
|
||||
assert html_response(public_page, 200) =~ "initial-results"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -48,16 +68,6 @@ test "GET /pleroma/admin -> /pleroma/admin/", %{conn: conn} do
|
|||
assert redirected_to(get(conn, "/pleroma/admin")) =~ "/pleroma/admin/"
|
||||
end
|
||||
|
||||
test "GET /*path", %{conn: conn} do
|
||||
assert conn
|
||||
|> get("/foo")
|
||||
|> html_response(200) =~ "<!--server-generated-meta-->"
|
||||
|
||||
assert conn
|
||||
|> get("/foo/bar")
|
||||
|> html_response(200) =~ "<!--server-generated-meta-->"
|
||||
end
|
||||
|
||||
test "OPTIONS /*path", %{conn: conn} do
|
||||
assert conn
|
||||
|> options("/foo")
|
||||
|
|
|
@ -52,9 +52,9 @@ test "returns the timeline when not restricted" do
|
|||
end
|
||||
|
||||
test "returns public items", %{user: user} do
|
||||
{:ok, _} = CommonAPI.post(user, %{"status" => "it's post 1!"})
|
||||
{:ok, _} = CommonAPI.post(user, %{"status" => "it's post 2!"})
|
||||
{:ok, _} = CommonAPI.post(user, %{"status" => "it's post 3!"})
|
||||
{:ok, _} = CommonAPI.post(user, %{status: "it's post 1!"})
|
||||
{:ok, _} = CommonAPI.post(user, %{status: "it's post 2!"})
|
||||
{:ok, _} = CommonAPI.post(user, %{status: "it's post 3!"})
|
||||
|
||||
assert Timelines.generate_terms(%{})
|
||||
|> Map.fetch!(@public_url)
|
||||
|
@ -62,9 +62,9 @@ test "returns public items", %{user: user} do
|
|||
end
|
||||
|
||||
test "does not return non-public items", %{user: user} do
|
||||
{:ok, _} = CommonAPI.post(user, %{"status" => "it's post 1!", "visibility" => "unlisted"})
|
||||
{:ok, _} = CommonAPI.post(user, %{"status" => "it's post 2!", "visibility" => "direct"})
|
||||
{:ok, _} = CommonAPI.post(user, %{"status" => "it's post 3!"})
|
||||
{:ok, _} = CommonAPI.post(user, %{status: "it's post 1!", visibility: "unlisted"})
|
||||
{:ok, _} = CommonAPI.post(user, %{status: "it's post 2!", visibility: "direct"})
|
||||
{:ok, _} = CommonAPI.post(user, %{status: "it's post 3!"})
|
||||
|
||||
assert Timelines.generate_terms(%{})
|
||||
|> Map.fetch!(@public_url)
|
||||
|
|
|
@ -124,7 +124,7 @@ test "it streams boosts of mastodon user in the 'user' stream", %{user: user} do
|
|||
|> Map.put("object", activity.data["object"])
|
||||
|> Map.put("actor", user.ap_id)
|
||||
|
||||
{:ok, %Pleroma.Activity{data: data, local: false} = announce} =
|
||||
{:ok, %Pleroma.Activity{data: _data, local: false} = announce} =
|
||||
Pleroma.Web.ActivityPub.Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert_receive {:render_with_user, Pleroma.Web.StreamerView, "update.json", ^announce}
|
||||
|
|
Loading…
Reference in a new issue