Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F85804508
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
35 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/config/config.exs b/config/config.exs
index 891ef054a..2225d38b9 100644
--- a/config/config.exs
+++ b/config/config.exs
@@ -1,657 +1,662 @@
# .i;;;;i.
# iYcviii;vXY:
# .YXi .i1c.
# .YC. . in7.
# .vc. ...... ;1c.
# i7, .. .;1;
# i7, .. ... .Y1i
# ,7v .6MMM@; .YX,
# .7;. ..IMMMMMM1 :t7.
# .;Y. ;$MMMMMM9. :tc.
# vY. .. .nMMM@MMU. ;1v.
# i7i ... .#MM@M@C. .....:71i
# it: .... $MMM@9;.,i;;;i,;tti
# :t7. ..... 0MMMWv.,iii:::,,;St.
# .nC. ..... IMMMQ..,::::::,.,czX.
# .ct: ....... .ZMMMI..,:::::::,,:76Y.
# c2: ......,i..Y$M@t..:::::::,,..inZY
# vov ......:ii..c$MBc..,,,,,,,,,,..iI9i
# i9Y ......iii:..7@MA,..,,,,,,,,,....;AA:
# iIS. ......:ii::..;@MI....,............;Ez.
# .I9. ......:i::::...8M1..................C0z.
# .z9; ......:i::::,.. .i:...................zWX.
# vbv ......,i::::,,. ................. :AQY
# c6Y. .,...,::::,,..:t0@@QY. ................ :8bi
# :6S. ..,,...,:::,,,..EMMMMMMI. ............... .;bZ,
# :6o, .,,,,..:::,,,..i#MMMMMM#v................. YW2.
# .n8i ..,,,,,,,::,,,,.. tMMMMM@C:.................. .1Wn
# 7Uc. .:::,,,,,::,,,,.. i1t;,..................... .UEi
# 7C...::::::::::::,,,,.. .................... vSi.
# ;1;...,,::::::,......... .................. Yz:
# v97,......... .voC.
# izAotX7777777777777777777777777777777777777777Y7n92:
# .;CoIIIIIUAA666666699999ZZZZZZZZZZZZZZZZZZZZ6ov.
#
# !!! ATTENTION !!!
# DO NOT EDIT THIS FILE! THIS FILE CONTAINS THE DEFAULT VALUES FOR THE CON-
# FIGURATION! EDIT YOUR SECRET FILE (either prod.secret.exs, dev.secret.exs).
#
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
#
# This configuration file is loaded before any dependency and
# is restricted to this project.
use Mix.Config
# General application configuration
config :pleroma, ecto_repos: [Pleroma.Repo]
config :pleroma, Pleroma.Repo,
types: Pleroma.PostgresTypes,
telemetry_event: [Pleroma.Repo.Instrumenter],
migration_lock: nil
config :pleroma, Pleroma.Captcha,
enabled: true,
seconds_valid: 300,
method: Pleroma.Captcha.Native
config :pleroma, Pleroma.Captcha.Kocaptcha, endpoint: "https://captcha.kotobank.ch"
# Upload configuration
config :pleroma, Pleroma.Upload,
uploader: Pleroma.Uploaders.Local,
filters: [Pleroma.Upload.Filter.Dedupe],
link_name: false,
proxy_remote: false,
proxy_opts: [
redirect_on_failure: false,
max_body_length: 25 * 1_048_576,
http: [
follow_redirect: true,
pool: :upload
]
]
config :pleroma, Pleroma.Uploaders.Local, uploads: "uploads"
config :pleroma, Pleroma.Uploaders.S3,
bucket: nil,
streaming_enabled: true,
public_endpoint: "https://s3.amazonaws.com"
config :pleroma, :emoji,
shortcode_globs: ["/emoji/custom/**/*.png"],
pack_extensions: [".png", ".gif"],
groups: [
Custom: ["/emoji/*.png", "/emoji/**/*.png"]
],
default_manifest: "https://git.pleroma.social/pleroma/emoji-index/raw/master/index.json",
shared_pack_cache_seconds_per_file: 60
config :pleroma, :uri_schemes,
valid_schemes: [
"https",
"http",
"dat",
"dweb",
"gopher",
"ipfs",
"ipns",
"irc",
"ircs",
"magnet",
"mailto",
"mumble",
"ssb",
"xmpp"
]
websocket_config = [
path: "/websocket",
serializer: [
{Phoenix.Socket.V1.JSONSerializer, "~> 1.0.0"},
{Phoenix.Socket.V2.JSONSerializer, "~> 2.0.0"}
],
timeout: 60_000,
transport_log: false,
compress: false
]
# Configures the endpoint
config :pleroma, Pleroma.Web.Endpoint,
instrumenters: [Pleroma.Web.Endpoint.Instrumenter],
url: [host: "localhost"],
http: [
ip: {127, 0, 0, 1},
dispatch: [
{:_,
[
{"/api/v1/streaming", Pleroma.Web.MastodonAPI.WebsocketHandler, []},
{"/websocket", Phoenix.Endpoint.CowboyWebSocket,
{Phoenix.Transports.WebSocket,
{Pleroma.Web.Endpoint, Pleroma.Web.UserSocket, websocket_config}}},
{:_, Phoenix.Endpoint.Cowboy2Handler, {Pleroma.Web.Endpoint, []}}
]}
]
],
protocol: "https",
secret_key_base: "aK4Abxf29xU9TTDKre9coZPUgevcVCFQJe/5xP/7Lt4BEif6idBIbjupVbOrbKxl",
signing_salt: "CqaoopA2",
render_errors: [view: Pleroma.Web.ErrorView, accepts: ~w(json)],
pubsub: [name: Pleroma.PubSub, adapter: Phoenix.PubSub.PG2],
secure_cookie_flag: true,
extra_cookie_attrs: [
"SameSite=Lax"
]
# Configures Elixir's Logger
config :logger, :console,
level: :debug,
format: "\n$time $metadata[$level] $message\n",
metadata: [:request_id]
config :logger, :ex_syslogger,
level: :debug,
ident: "pleroma",
format: "$metadata[$level] $message",
metadata: [:request_id]
config :quack,
level: :warn,
meta: [:all],
webhook_url: "https://hooks.slack.com/services/YOUR-KEY-HERE"
config :mime, :types, %{
"application/xml" => ["xml"],
"application/xrd+xml" => ["xrd+xml"],
"application/jrd+json" => ["jrd+json"],
"application/activity+json" => ["activity+json"],
"application/ld+json" => ["activity+json"]
}
config :tesla, adapter: Tesla.Adapter.Gun
# Configures http settings, upstream proxy etc.
config :pleroma, :http,
proxy_url: nil,
send_user_agent: true,
user_agent: :default,
adapter: []
config :pleroma, :instance,
name: "Pleroma",
email: "example@example.com",
notify_email: "noreply@example.com",
description: "A Pleroma instance, an alternative fediverse server",
limit: 5_000,
chat_limit: 5_000,
remote_limit: 100_000,
upload_limit: 16_000_000,
avatar_upload_limit: 2_000_000,
background_upload_limit: 4_000_000,
banner_upload_limit: 4_000_000,
poll_limits: %{
max_options: 20,
max_option_chars: 200,
min_expiration: 0,
max_expiration: 365 * 24 * 60 * 60
},
registrations_open: true,
invites_enabled: false,
account_activation_required: false,
federating: true,
federation_incoming_replies_max_depth: 100,
federation_reachability_timeout_days: 7,
federation_publisher_modules: [
Pleroma.Web.ActivityPub.Publisher
],
allow_relay: true,
rewrite_policy: Pleroma.Web.ActivityPub.MRF.NoOpPolicy,
public: true,
quarantined_instances: [],
managed_config: true,
static_dir: "instance/static/",
allowed_post_formats: [
"text/plain",
"text/html",
"text/markdown",
"text/bbcode"
],
mrf_transparency: true,
mrf_transparency_exclusions: [],
autofollowed_nicknames: [],
max_pinned_statuses: 1,
attachment_links: false,
welcome_user_nickname: nil,
welcome_message: nil,
max_report_comment_size: 1000,
safe_dm_mentions: false,
healthcheck: false,
remote_post_retention_days: 90,
skip_thread_containment: true,
limit_to_local_content: :unauthenticated,
user_bio_length: 5000,
user_name_length: 100,
max_account_fields: 10,
max_remote_account_fields: 20,
account_field_name_length: 512,
account_field_value_length: 2048,
external_user_synchronization: true,
extended_nickname_format: true,
cleanup_attachments: false
config :pleroma, :feed,
post_title: %{
max_length: 100,
omission: "..."
}
config :pleroma, :markup,
# XXX - unfortunately, inline images must be enabled by default right now, because
# of custom emoji. Issue #275 discusses defanging that somehow.
allow_inline_images: true,
allow_headings: false,
allow_tables: false,
allow_fonts: false,
scrub_policy: [
Pleroma.HTML.Scrubber.Default,
Pleroma.HTML.Transform.MediaProxy
]
config :pleroma, :frontend_configurations,
pleroma_fe: %{
theme: "pleroma-dark",
logo: "/static/logo.png",
background: "/images/city.jpg",
redirectRootNoLogin: "/main/all",
redirectRootLogin: "/main/friends",
showInstanceSpecificPanel: true,
scopeOptionsEnabled: false,
formattingOptionsEnabled: false,
collapseMessageWithSubject: false,
hidePostStats: false,
hideUserStats: false,
scopeCopy: true,
subjectLineBehavior: "email",
alwaysShowSubjectInput: true
},
masto_fe: %{
showInstanceSpecificPanel: true
}
config :pleroma, :assets,
mascots: [
pleroma_fox_tan: %{
url: "/images/pleroma-fox-tan-smol.png",
mime_type: "image/png"
},
pleroma_fox_tan_shy: %{
url: "/images/pleroma-fox-tan-shy.png",
mime_type: "image/png"
}
],
default_mascot: :pleroma_fox_tan
config :pleroma, :manifest,
icons: [
%{
src: "/static/logo.png",
type: "image/png"
}
],
theme_color: "#282c37",
background_color: "#191b22"
config :pleroma, :activitypub,
unfollow_blocked: true,
outgoing_blocks: true,
follow_handshake_timeout: 500,
note_replies_output_limit: 5,
sign_object_fetches: true,
authorized_fetch_mode: false
config :pleroma, :streamer,
workers: 3,
overflow_workers: 2
config :pleroma, :user, deny_follow_blocked: true
config :pleroma, :mrf_normalize_markup, scrub_policy: Pleroma.HTML.Scrubber.Default
config :pleroma, :mrf_rejectnonpublic,
allow_followersonly: false,
allow_direct: false
config :pleroma, :mrf_hellthread,
delist_threshold: 10,
reject_threshold: 20
config :pleroma, :mrf_simple,
media_removal: [],
media_nsfw: [],
federated_timeline_removal: [],
report_removal: [],
reject: [],
accept: [],
avatar_removal: [],
banner_removal: []
config :pleroma, :mrf_keyword,
reject: [],
federated_timeline_removal: [],
replace: []
config :pleroma, :mrf_subchain, match_actor: %{}
config :pleroma, :mrf_vocabulary,
accept: [],
reject: []
config :pleroma, :mrf_object_age,
threshold: 172_800,
actions: [:delist, :strip_followers]
config :pleroma, :rich_media,
enabled: true,
ignore_hosts: [],
ignore_tld: ["local", "localdomain", "lan"],
parsers: [
Pleroma.Web.RichMedia.Parsers.TwitterCard,
Pleroma.Web.RichMedia.Parsers.OGP,
Pleroma.Web.RichMedia.Parsers.OEmbed
],
ttl_setters: [Pleroma.Web.RichMedia.Parser.TTL.AwsSignedUrl]
config :pleroma, :media_proxy,
enabled: false,
proxy_opts: [
redirect_on_failure: false,
max_body_length: 25 * 1_048_576,
http: [
follow_redirect: true,
pool: :media
]
],
whitelist: []
config :pleroma, :chat, enabled: true
config :phoenix, :format_encoders, json: Jason
config :phoenix, :json_library, Jason
config :phoenix, :filter_parameters, ["password", "confirm"]
config :pleroma, :gopher,
enabled: false,
ip: {0, 0, 0, 0},
port: 9999
config :pleroma, Pleroma.Web.Metadata,
providers: [
Pleroma.Web.Metadata.Providers.OpenGraph,
Pleroma.Web.Metadata.Providers.TwitterCard,
Pleroma.Web.Metadata.Providers.RelMe,
- Pleroma.Web.Metadata.Providers.Feed,
- Pleroma.Web.Metadata.Providers.Instance,
- Pleroma.Web.Metadata.Providers.User
+ Pleroma.Web.Metadata.Providers.Feed
+ ],
+ unfurl_nsfw: false
+
+config :pleroma, Pleroma.Web.Preload,
+ providers: [
+ Pleroma.Web.Preload.Providers.Instance,
+ Pleroma.Web.Preload.Providers.User
],
unfurl_nsfw: false
config :pleroma, :http_security,
enabled: true,
sts: false,
sts_max_age: 31_536_000,
ct_max_age: 2_592_000,
referrer_policy: "same-origin"
config :cors_plug,
max_age: 86_400,
methods: ["POST", "PUT", "DELETE", "GET", "PATCH", "OPTIONS"],
expose: [
"Link",
"X-RateLimit-Reset",
"X-RateLimit-Limit",
"X-RateLimit-Remaining",
"X-Request-Id",
"Idempotency-Key"
],
credentials: true,
headers: ["Authorization", "Content-Type", "Idempotency-Key"]
config :pleroma, Pleroma.User,
restricted_nicknames: [
".well-known",
"~",
"about",
"activities",
"api",
"auth",
"check_password",
"dev",
"friend-requests",
"inbox",
"internal",
"main",
"media",
"nodeinfo",
"notice",
"oauth",
"objects",
"ostatus_subscribe",
"pleroma",
"proxy",
"push",
"registration",
"relay",
"settings",
"status",
"tag",
"user-search",
"user_exists",
"users",
"web"
]
config :pleroma, Oban,
repo: Pleroma.Repo,
verbose: false,
prune: {:maxlen, 1500},
queues: [
activity_expiration: 10,
federator_incoming: 50,
federator_outgoing: 50,
web_push: 50,
mailer: 10,
transmogrifier: 20,
scheduled_activities: 10,
background: 5,
remote_fetcher: 2,
attachments_cleanup: 5,
new_users_digest: 1
],
crontab: [
{"0 0 * * *", Pleroma.Workers.Cron.ClearOauthTokenWorker},
{"0 * * * *", Pleroma.Workers.Cron.StatsWorker},
{"* * * * *", Pleroma.Workers.Cron.PurgeExpiredActivitiesWorker},
{"0 0 * * 0", Pleroma.Workers.Cron.DigestEmailsWorker},
{"0 0 * * *", Pleroma.Workers.Cron.NewUsersDigestWorker}
]
config :pleroma, :workers,
retries: [
federator_incoming: 5,
federator_outgoing: 5
]
config :auto_linker,
opts: [
extra: true,
# TODO: Set to :no_scheme when it works properly
validate_tld: true,
class: false,
strip_prefix: false,
new_window: false,
rel: "ugc"
]
config :pleroma, :ldap,
enabled: System.get_env("LDAP_ENABLED") == "true",
host: System.get_env("LDAP_HOST") || "localhost",
port: String.to_integer(System.get_env("LDAP_PORT") || "389"),
ssl: System.get_env("LDAP_SSL") == "true",
sslopts: [],
tls: System.get_env("LDAP_TLS") == "true",
tlsopts: [],
base: System.get_env("LDAP_BASE") || "dc=example,dc=com",
uid: System.get_env("LDAP_UID") || "cn"
config :esshd,
enabled: false
oauth_consumer_strategies =
System.get_env("OAUTH_CONSUMER_STRATEGIES")
|> to_string()
|> String.split()
|> Enum.map(&hd(String.split(&1, ":")))
ueberauth_providers =
for strategy <- oauth_consumer_strategies do
strategy_module_name = "Elixir.Ueberauth.Strategy.#{String.capitalize(strategy)}"
strategy_module = String.to_atom(strategy_module_name)
{String.to_atom(strategy), {strategy_module, [callback_params: ["state"]]}}
end
config :ueberauth,
Ueberauth,
base_path: "/oauth",
providers: ueberauth_providers
config :pleroma,
:auth,
enforce_oauth_admin_scope_usage: true,
oauth_consumer_strategies: oauth_consumer_strategies
config :pleroma, Pleroma.Emails.Mailer, adapter: Swoosh.Adapters.Sendmail, enabled: false
config :pleroma, Pleroma.Emails.UserEmail,
logo: nil,
styling: %{
link_color: "#d8a070",
background_color: "#2C3645",
content_background_color: "#1B2635",
header_color: "#d8a070",
text_color: "#b9b9ba",
text_muted_color: "#b9b9ba"
}
config :pleroma, Pleroma.Emails.NewUsersDigestEmail, enabled: false
config :prometheus, Pleroma.Web.Endpoint.MetricsExporter, path: "/api/pleroma/app_metrics"
config :pleroma, Pleroma.ScheduledActivity,
daily_user_limit: 25,
total_user_limit: 300,
enabled: true
config :pleroma, :email_notifications,
digest: %{
active: false,
interval: 7,
inactivity_threshold: 7
}
config :pleroma, :oauth2,
token_expires_in: 600,
issue_new_refresh_token: true,
clean_expired_tokens: false
config :pleroma, :database, rum_enabled: false
config :pleroma, :env, Mix.env()
config :http_signatures,
adapter: Pleroma.Signature
config :pleroma, :rate_limit,
authentication: {60_000, 15},
timeline: {500, 3},
search: [{1000, 10}, {1000, 30}],
app_account_creation: {1_800_000, 25},
relations_actions: {10_000, 10},
relation_id_action: {60_000, 2},
statuses_actions: {10_000, 15},
status_id_action: {60_000, 3},
password_reset: {1_800_000, 5},
account_confirmation_resend: {8_640_000, 5},
ap_routes: {60_000, 15}
config :pleroma, Pleroma.ActivityExpiration, enabled: true
config :pleroma, Pleroma.Plugs.RemoteIp, enabled: true
config :pleroma, :static_fe, enabled: false
config :pleroma, :web_cache_ttl,
activity_pub: nil,
activity_pub_question: 30_000
config :pleroma, :modules, runtime_dir: "instance/modules"
config :pleroma, configurable_from_database: false
config :pleroma, Pleroma.Repo,
parameters: [gin_fuzzy_search_limit: "500"],
prepare: :unnamed
config :pleroma, :connections_pool,
checkin_timeout: 250,
max_connections: 250,
retry: 1,
retry_timeout: 1000,
await_up_timeout: 5_000
config :pleroma, :pools,
federation: [
size: 50,
max_overflow: 10,
timeout: 150_000
],
media: [
size: 50,
max_overflow: 10,
timeout: 150_000
],
upload: [
size: 25,
max_overflow: 5,
timeout: 300_000
],
default: [
size: 10,
max_overflow: 2,
timeout: 10_000
]
config :pleroma, :hackney_pools,
federation: [
max_connections: 50,
timeout: 150_000
],
media: [
max_connections: 50,
timeout: 150_000
],
upload: [
max_connections: 25,
timeout: 300_000
]
config :pleroma, :restrict_unauthenticated,
timelines: %{local: false, federated: false},
profiles: %{local: false, remote: false},
activities: %{local: false, remote: false}
# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{Mix.env()}.exs"
diff --git a/lib/pleroma/web/fallback_redirect_controller.ex b/lib/pleroma/web/fallback_redirect_controller.ex
index c13518030..e4fc0b1f1 100644
--- a/lib/pleroma/web/fallback_redirect_controller.ex
+++ b/lib/pleroma/web/fallback_redirect_controller.ex
@@ -1,77 +1,102 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Fallback.RedirectController do
use Pleroma.Web, :controller
require Logger
alias Pleroma.User
alias Pleroma.Web.Metadata
+ alias Pleroma.Web.Preload
def api_not_implemented(conn, _params) do
conn
|> put_status(404)
|> json(%{error: "Not implemented"})
end
def redirector(conn, _params, code \\ 200)
# redirect to admin section
# /pleroma/admin -> /pleroma/admin/
#
def redirector(conn, %{"path" => ["pleroma", "admin"]} = _, _code) do
redirect(conn, to: "/pleroma/admin/")
end
def redirector(conn, _params, code) do
conn
|> put_resp_content_type("text/html")
|> send_file(code, index_file_path())
end
def redirector_with_meta(conn, %{"maybe_nickname_or_id" => maybe_nickname_or_id} = params) do
+ IO.inspect(conn, label: "inspect the conn")
+
with %User{} = user <- User.get_cached_by_nickname_or_id(maybe_nickname_or_id) do
redirector_with_meta(conn, %{user: user})
else
nil ->
redirector(conn, params)
end
end
def redirector_with_meta(conn, params) do
{:ok, index_content} = File.read(index_file_path())
+ IO.inspect(conn, label: "inspect the conn")
- tags =
- try do
- Metadata.build_tags(params)
- rescue
- e ->
- Logger.error(
- "Metadata rendering for #{conn.request_path} failed.\n" <>
- Exception.format(:error, e, __STACKTRACE__)
- )
-
- ""
- end
+ tags = build_tags(conn, params)
+ preloads = preload_data(conn, params)
- response = String.replace(index_content, "<!--server-generated-meta-->", tags)
+ response =
+ index_content
+ |> String.replace("<!--server-generated-meta-->", tags)
+ |> String.replace("<!--server-generated-initial-data-->", preloads)
conn
|> put_resp_content_type("text/html")
|> send_resp(200, response)
end
- def index_file_path do
- Pleroma.Plugs.InstanceStatic.file_path("index.html")
- end
-
def registration_page(conn, params) do
redirector(conn, params)
end
def empty(conn, _params) do
conn
|> put_status(204)
|> text("")
end
+
+ defp index_file_path do
+ Pleroma.Plugs.InstanceStatic.file_path("index.html")
+ end
+
+ defp build_tags(conn, params) do
+ try do
+ Metadata.build_tags(params)
+ rescue
+ e ->
+ Logger.error(
+ "Metadata rendering for #{conn.request_path} failed.\n" <>
+ Exception.format(:error, e, __STACKTRACE__)
+ )
+
+ ""
+ end
+ end
+
+ defp preload_data(conn, params) do
+ try do
+ Preload.build_tags(params)
+ rescue
+ e ->
+ Logger.error(
+ "Preloading for #{conn.request_path} failed.\n" <>
+ Exception.format(:error, e, __STACKTRACE__)
+ )
+
+ ""
+ end
+ end
end
diff --git a/lib/pleroma/web/metadata/instance.ex b/lib/pleroma/web/metadata/instance.ex
deleted file mode 100644
index 5b75c3cbd..000000000
--- a/lib/pleroma/web/metadata/instance.ex
+++ /dev/null
@@ -1,73 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.Metadata.Providers.Instance do
- alias Pleroma.Web.Metadata.Providers.Provider
- alias Pleroma.Web.MastodonAPI.InstanceView
- alias Pleroma.Web.Nodeinfo.Nodeinfo
-
- @behaviour Provider
-
- @impl Provider
- def build_tags(_params) do
- []
- |> build_info_tag()
- |> build_panel_tag()
- |> build_nodeinfo_tag()
- end
-
- def build_info_tag(acc \\ []) do
- "show.json"
- |> InstanceView.render(%{})
- |> Jason.encode!()
- |> check_for_empty()
- |> case do
- "" ->
- acc
-
- safe_data ->
- [make_tag("instance:info", safe_data) | acc]
- end
- end
-
- def build_panel_tag(acc \\ []) do
- instance_path = Path.join(:code.priv_dir(:pleroma), "static/instance/panel.html")
-
- if File.exists?(instance_path) do
- instance_path
- |> File.read!()
- |> case do
- "" ->
- acc
-
- safe_data ->
- [make_tag("instance:panel", safe_data) | acc]
- end
- else
- acc
- end
- end
-
- def build_nodeinfo_tag(acc \\ []) do
- case Nodeinfo.get_nodeinfo("2.0") do
- {:error, _} ->
- acc
-
- nodeinfo_data ->
- [make_tag("instance:nodeinfo", Jason.encode!(nodeinfo_data)) | acc]
- end
- end
-
- defp check_for_empty(data) do
- if data != "" and data != "\u200B" do
- data
- else
- ""
- end
- end
-
- defp make_tag(key, data) do
- {:meta, [property: key, content: data], []}
- end
-end
diff --git a/lib/pleroma/web/metadata/user.ex b/lib/pleroma/web/metadata/user.ex
deleted file mode 100644
index 0bfc405dc..000000000
--- a/lib/pleroma/web/metadata/user.ex
+++ /dev/null
@@ -1,60 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.Metadata.Providers.User do
- alias Pleroma.User
- alias Pleroma.Web.MastodonAPI.AccountView
- alias Pleroma.Web.Metadata.Providers.Provider
-
- @behaviour Provider
-
- @impl Provider
- def build_tags(params) do
- []
- |> build_accounts_tag(params)
- |> build_relationships_tag(params)
- end
-
- def build_accounts_tag(acc \\ [], %{user: user}) do
- "show.json"
- |> AccountView.render(%{user: user, for: user})
- |> Jason.encode!()
- |> check_for_empty()
- |> case do
- "" ->
- acc
-
- safe_data ->
- [make_tag("user:account", safe_data) | acc]
- end
- end
-
- def build_relationships_tag(acc \\ [], %{user: %{id: user_id} = user}) do
- targets = User.get_all_by_ids(List.wrap(user_id))
-
- "relationships.json"
- |> AccountView.render(%{user: user, targets: targets})
- |> Jason.encode!()
- |> check_for_empty()
- |> case do
- "" ->
- acc
-
- safe_data ->
- [make_tag("user:relationships", safe_data) | acc]
- end
- end
-
- defp check_for_empty(data) do
- if data != "" and data != "\u200B" do
- data
- else
- ""
- end
- end
-
- defp make_tag(key, data) do
- {:meta, [property: key, content: data], []}
- end
-end
diff --git a/lib/pleroma/web/preload.ex b/lib/pleroma/web/preload.ex
new file mode 100644
index 000000000..845122941
--- /dev/null
+++ b/lib/pleroma/web/preload.ex
@@ -0,0 +1,27 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.Preload do
+ alias Phoenix.HTML
+
+ def build_tags(params) do
+ preload_data =
+ Enum.reduce(Pleroma.Config.get([__MODULE__, :providers], []), %{}, fn parser, acc ->
+ Map.merge(acc, parser.generate_terms(params))
+ end)
+
+ rendered_html =
+ preload_data
+ |> IO.inspect(label: "data for preload", pretty: true)
+ |> Jason.encode!()
+ |> build_script_tag()
+ |> HTML.safe_to_string()
+
+ rendered_html
+ end
+
+ def build_script_tag(content) do
+ HTML.Tag.content_tag(:script, content, id: "initial-results", type: "application/json")
+ end
+end
diff --git a/lib/pleroma/web/preload/instance.ex b/lib/pleroma/web/preload/instance.ex
new file mode 100644
index 000000000..87729d2c4
--- /dev/null
+++ b/lib/pleroma/web/preload/instance.ex
@@ -0,0 +1,46 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.Preload.Providers.Instance do
+ alias Pleroma.Web.Preload.Providers.Provider
+ alias Pleroma.Web.MastodonAPI.InstanceView
+ alias Pleroma.Web.Nodeinfo.Nodeinfo
+
+ @behaviour Provider
+
+ @impl Provider
+ def generate_terms(_params \\ %{}) do
+ %{}
+ |> build_info_tag()
+ |> build_panel_tag()
+ |> build_nodeinfo_tag()
+ end
+
+ def build_info_tag(acc \\ %{}) do
+ info_data = InstanceView.render("show.json", %{})
+
+ Map.put(acc, :"/api/v1/instance", info_data)
+ end
+
+ def build_panel_tag(acc \\ %{}) do
+ instance_path = Path.join(:code.priv_dir(:pleroma), "static/instance/panel.html")
+
+ if File.exists?(instance_path) do
+ panel_data = File.read!(instance_path)
+ Map.put(acc, :"/instance/panel.html", panel_data)
+ else
+ acc
+ end
+ end
+
+ def build_nodeinfo_tag(acc \\ %{}) do
+ case Nodeinfo.get_nodeinfo("2.0") do
+ {:error, _} ->
+ acc
+
+ nodeinfo_data ->
+ Map.put(acc, :"/nodeinfo/2.0", nodeinfo_data)
+ end
+ end
+end
diff --git a/lib/pleroma/web/preload/provider.ex b/lib/pleroma/web/preload/provider.ex
new file mode 100644
index 000000000..7ef595a34
--- /dev/null
+++ b/lib/pleroma/web/preload/provider.ex
@@ -0,0 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.Preload.Providers.Provider do
+ @callback generate_terms(map()) :: map()
+end
diff --git a/lib/pleroma/web/preload/user.ex b/lib/pleroma/web/preload/user.ex
new file mode 100644
index 000000000..5028a8ea9
--- /dev/null
+++ b/lib/pleroma/web/preload/user.ex
@@ -0,0 +1,33 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.Preload.Providers.User do
+ alias Pleroma.Web.MastodonAPI.AccountView
+ alias Pleroma.Web.Preload.Providers.Provider
+
+ @behaviour Provider
+
+ @impl Provider
+ def generate_terms(params \\ %{})
+
+ def generate_terms(%{user: nil}), do: %{}
+
+ def generate_terms(%{user: user}) do
+ %{}
+ |> build_accounts_tag(user)
+ |> build_relationships_tag(user)
+ end
+
+ def generate_terms(_), do: %{}
+
+ def build_accounts_tag(acc, user) do
+ account_data = AccountView.render("show.json", %{user: user, for: user})
+ Map.put(acc, :"api/v1/accounts", account_data)
+ end
+
+ def build_relationships_tag(acc, user) do
+ relationship_data = AccountView.render("relationships.json", %{user: user, targets: [user]})
+ Map.put(acc, :"api/v1/accounts/relationships", relationship_data)
+ end
+end
diff --git a/priv/static/index.html b/priv/static/index.html
index 4304bdcbb..8d805fba9 100644
--- a/priv/static/index.html
+++ b/priv/static/index.html
@@ -1 +1,22 @@
-<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1,user-scalable=no"><title>Pleroma</title><!--server-generated-meta--><link rel=icon type=image/png href=/favicon.png><link href=/static/css/vendors~app.b2603a50868c68a1c192.css rel=stylesheet><link href=/static/css/app.1055039ce3f2fe4dd110.css rel=stylesheet><link href=/static/fontello.1583594169021.css rel=stylesheet></head><body class=hidden><noscript>To use Pleroma, please enable JavaScript.</noscript><div id=app></div><script type=text/javascript src=/static/js/vendors~app.c5bbd3734647f0cc7eef.js></script><script type=text/javascript src=/static/js/app.5c94bdec79a7d0f3cfcb.js></script></body></html>
\ No newline at end of file
+<!DOCTYPE html>
+<html lang=en>
+
+<head>
+ <meta charset=utf-8>
+ <meta name=viewport content="width=device-width,initial-scale=1,user-scalable=no">
+ <title>Pleroma</title>
+ <!--server-generated-meta-->
+ <!--server-generated-initial-data-->
+ <link rel=icon type=image/png href=/favicon.png>
+ <link href=/static/css/vendors~app.b2603a50868c68a1c192.css rel=stylesheet>
+ <link href=/static/css/app.1055039ce3f2fe4dd110.css rel=stylesheet>
+ <link href=/static/fontello.1583594169021.css rel=stylesheet>
+</head>
+
+<body class=hidden><noscript>To use Pleroma, please enable JavaScript.</noscript>
+ <div id=app></div>
+ <script type=text/javascript src=/static/js/vendors~app.c5bbd3734647f0cc7eef.js></script>
+ <script type=text/javascript src=/static/js/app.5c94bdec79a7d0f3cfcb.js></script>
+</body>
+
+</html>
\ No newline at end of file
diff --git a/test/web/metadata/instance_test.exs b/test/web/metadata/instance_test.exs
index a12c92fae..ea3696021 100644
--- a/test/web/metadata/instance_test.exs
+++ b/test/web/metadata/instance_test.exs
@@ -1,81 +1,37 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
-defmodule Pleroma.Web.Metadata.Providers.InstanceTest do
+defmodule Pleroma.Web.Preload.Providers.InstanceTest do
use Pleroma.DataCase
- alias Pleroma.Web.Metadata.Providers.Instance
+ alias Pleroma.Web.Preload.Providers.Instance
- setup do: clear_config([Pleroma.Web.Metadata, :unfurl_nsfw])
+ setup do: {:ok, Instance.generate_terms()}
- test "it renders the info" do
- result = Instance.build_tags(%{})
-
- %{
- "description" => description,
- "email" => "admin@example.com",
- "registrations" => true
- } =
- case Enum.find(result, nil, &find_tag(&1, "instance:info")) do
- nil ->
- %{}
-
- {:meta, properties, []} ->
- properties
- |> Keyword.get(:content, "")
- |> Jason.decode!()
- end
+ test "it renders the info", %{"/api/v1/instance": info} do
+ assert %{
+ description: description,
+ email: "admin@example.com",
+ registrations: true
+ } = info
assert String.equivalent?(description, "A Pleroma instance, an alternative fediverse server")
end
- test "it renders the panel" do
- result = Instance.build_tags(%{})
-
- html_panel =
- case Enum.find(result, nil, &find_tag(&1, "instance:panel")) do
- nil ->
- %{}
-
- {:meta, properties, []} ->
- properties
- |> Keyword.get(:content, "")
- end
-
+ test "it renders the panel", %{"/instance/panel.html": panel} do
assert String.contains?(
- html_panel,
+ panel,
"<p>Welcome to <a href=\"https://pleroma.social\" target=\"_blank\">Pleroma!</a></p>"
)
end
- test "it renders the node_info" do
- result = Instance.build_tags(%{})
-
+ test "it renders the node_info", %{"/nodeinfo/2.0": nodeinfo} do
%{
- "metadata" => metadata,
- "version" => "2.0"
- } =
- case Enum.find(result, nil, &find_tag(&1, "instance:nodeinfo")) do
- nil ->
- %{}
-
- {:meta, properties, []} ->
- properties
- |> Keyword.get(:content, "")
- |> Jason.decode!()
- end
-
- assert metadata["private"] == false
- assert metadata["suggestions"] == %{"enabled" => false}
- end
+ metadata: metadata,
+ version: "2.0"
+ } = nodeinfo
- def find_tag(tag, property) do
- with {:meta, properties, []} <- tag,
- prop_name <- Keyword.get(properties, :property, false) do
- String.equivalent?(prop_name, property)
- else
- _ ->
- false
- end
+ assert metadata.private == false
+ assert metadata.suggestions == %{enabled: false}
end
end
diff --git a/test/web/metadata/user_test.exs b/test/web/metadata/user_test.exs
index fde066b1b..a7d49d29c 100644
--- a/test/web/metadata/user_test.exs
+++ b/test/web/metadata/user_test.exs
@@ -1,64 +1,30 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
-defmodule Pleroma.Web.Metadata.Providers.UserTest do
+defmodule Pleroma.Web.Preload.Providers.UserTest do
use Pleroma.DataCase
import Pleroma.Factory
- alias Pleroma.Web.Metadata.Providers.User
+ alias Pleroma.Web.Preload.Providers.User
- setup do: clear_config([Pleroma.Web.Metadata, :unfurl_nsfw])
-
- test "it renders the accounts" do
+ setup do
user = insert(:user)
- result = User.build_tags(%{user: user})
-
- %{"acct" => username, "username" => username} =
- case Enum.find(result, nil, &find_tag(&1, "user:account")) do
- {:meta, properties, []} ->
- get_decoded_content(properties)
-
- _ ->
- %{}
- end
+ {:ok, User.generate_terms(%{user: user})}
end
- test "it renders the relationships" do
- user = insert(:user)
-
- result = User.build_tags(%{user: user})
+ test "it renders the accounts", %{"api/v1/accounts": accounts} do
+ assert %{"acct" => username, "username" => username} = accounts
+ end
+ test "it renders the relationships", %{"api/v1/accounts/relationships": relationships} do
[
%{
"blocked_by" => false,
"blocking" => false,
"showing_reblogs" => true,
"subscribing" => false
}
- ] =
- case Enum.find(result, nil, &find_tag(&1, "user:relationships")) do
- {:meta, properties, []} ->
- get_decoded_content(properties)
-
- _ ->
- %{}
- end
- end
-
- defp get_decoded_content(props) do
- props
- |> Keyword.get(:content, "")
- |> Jason.decode!()
- end
-
- defp find_tag(tag, property) do
- with {:meta, properties, []} <- tag,
- prop_name <- Keyword.get(properties, :property, false) do
- String.equivalent?(prop_name, property)
- else
- _ ->
- false
- end
+ ] = relationships
end
end
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Oct 10, 8:11 AM (1 d, 8 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1783792
Default Alt Text
(35 KB)
Attached To
Mode
rPUBE pleroma-upstream
Attached
Detach File
Event Timeline
Log In to Comment