summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/formatter.ex36
-rw-r--r--lib/pleroma/upload.ex26
-rw-r--r--lib/pleroma/web/activity_pub/transmogrifier.ex27
-rw-r--r--lib/pleroma/web/activity_pub/views/user_view.ex9
-rw-r--r--lib/pleroma/web/mastodon_api/mastodon_api_controller.ex43
-rw-r--r--lib/pleroma/web/nodeinfo/nodeinfo_controller.ex9
-rw-r--r--lib/pleroma/web/router.ex2
-rw-r--r--lib/pleroma/web/templates/mastodon_api/mastodon/index.html.eex2
8 files changed, 125 insertions, 29 deletions
diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex
index d199c9243..3e71a3b5f 100644
--- a/lib/pleroma/formatter.ex
+++ b/lib/pleroma/formatter.ex
@@ -165,8 +165,29 @@ defmodule Pleroma.Formatter do
@emoji
end
- @link_regex ~r/https?:\/\/[\w\.\/?=\-#\+%&@~'\(\):]+[\w\/]/u
+ @link_regex ~r/[0-9a-z+\-\.]+:[0-9a-z$-_.+!*'(),]+/ui
+
+ # IANA got a list https://www.iana.org/assignments/uri-schemes/ but
+ # Stuff like ipfs isn’t in it
+ # There is very niche stuff
+ @uri_schemes [
+ "https://",
+ "http://",
+ "dat://",
+ "dweb://",
+ "gopher://",
+ "ipfs://",
+ "ipns://",
+ "irc:",
+ "ircs:",
+ "magnet:",
+ "mailto:",
+ "mumble:",
+ "ssb://",
+ "xmpp:"
+ ]
+ # TODO: make it use something other than @link_regex
def html_escape(text) do
Regex.split(@link_regex, text, include_captures: true)
|> Enum.map_every(2, fn chunk ->
@@ -176,11 +197,18 @@ defmodule Pleroma.Formatter do
|> Enum.join("")
end
- @doc "changes http:... links to html links"
+ @doc "changes scheme:... urls to html links"
def add_links({subs, text}) do
+ additionnal_schemes =
+ Application.get_env(:pleroma, :uri_schemes, [])
+ |> Keyword.get(:additionnal_schemes, [])
+
links =
- Regex.scan(@link_regex, text)
- |> Enum.map(fn [url] -> {Ecto.UUID.generate(), url} end)
+ text
+ |> String.split([" ", "\t", "<br>"])
+ |> Enum.filter(fn word -> String.starts_with?(word, @uri_schemes ++ additionnal_schemes) end)
+ |> Enum.filter(fn word -> Regex.match?(@link_regex, word) end)
+ |> Enum.map(fn url -> {Ecto.UUID.generate(), url} end)
|> Enum.sort_by(fn {_, url} -> -String.length(url) end)
uuid_text =
diff --git a/lib/pleroma/upload.ex b/lib/pleroma/upload.ex
index 408a3fc56..e0cb545b0 100644
--- a/lib/pleroma/upload.ex
+++ b/lib/pleroma/upload.ex
@@ -124,20 +124,20 @@ defmodule Pleroma.Upload do
if should_dedupe do
create_name(uuid, List.last(String.split(file.filename, ".")), type)
else
- unless String.contains?(file.filename, ".") do
- case type do
- "image/png" -> file.filename <> ".png"
- "image/jpeg" -> file.filename <> ".jpg"
- "image/gif" -> file.filename <> ".gif"
- "video/webm" -> file.filename <> ".webm"
- "video/mp4" -> file.filename <> ".mp4"
- "audio/mpeg" -> file.filename <> ".mp3"
- "audio/ogg" -> file.filename <> ".ogg"
- "audio/wav" -> file.filename <> ".wav"
- _ -> file.filename
+ parts = String.split(file.filename, ".")
+
+ new_filename =
+ if length(parts) > 1 do
+ Enum.drop(parts, -1) |> Enum.join(".")
+ else
+ Enum.join(parts)
end
- else
- file.filename
+
+ case type do
+ "application/octet-stream" -> file.filename
+ "audio/mpeg" -> new_filename <> ".mp3"
+ "image/jpeg" -> new_filename <> ".jpg"
+ _ -> Enum.join([new_filename, String.split(type, "/") |> List.last()], ".")
end
end
end
diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex
index 2ebc526df..e5fb6e033 100644
--- a/lib/pleroma/web/activity_pub/transmogrifier.ex
+++ b/lib/pleroma/web/activity_pub/transmogrifier.ex
@@ -21,6 +21,10 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
Enum.at(actor, 0)
end
+ def get_actor(%{"actor" => actor}) when is_map(actor) do
+ actor["id"]
+ end
+
def get_actor(%{"actor" => actor_list}) do
Enum.find(actor_list, fn %{"type" => type} -> type == "Person" end)
|> Map.get("id")
@@ -38,6 +42,24 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|> fix_emoji
|> fix_tag
|> fix_content_map
+ |> fix_addressing
+ end
+
+ def fix_addressing_list(map, field) do
+ if is_binary(map[field]) do
+ map
+ |> Map.put(field, [map[field]])
+ else
+ map
+ end
+ end
+
+ def fix_addressing(map) do
+ map
+ |> fix_addressing_list("to")
+ |> fix_addressing_list("cc")
+ |> fix_addressing_list("bto")
+ |> fix_addressing_list("bcc")
end
def fix_actor(%{"attributedTo" => actor} = object) do
@@ -143,7 +165,10 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
def handle_incoming(%{"type" => "Create", "object" => %{"type" => objtype} = object} = data)
when objtype in ["Article", "Note"] do
actor = get_actor(data)
- data = Map.put(data, "actor", actor)
+
+ data =
+ Map.put(data, "actor", actor)
+ |> fix_addressing
with nil <- Activity.get_create_activity_by_object_ap_id(object["id"]),
%User{} = user <- User.get_or_fetch_by_ap_id(data["actor"]) do
diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex
index 41bfe5048..0b1d5a9fa 100644
--- a/lib/pleroma/web/activity_pub/views/user_view.ex
+++ b/lib/pleroma/web/activity_pub/views/user_view.ex
@@ -98,9 +98,6 @@ defmodule Pleroma.Web.ActivityPub.UserView do
info = User.user_info(user)
params = %{
- "type" => ["Create", "Announce"],
- "actor_id" => user.ap_id,
- "whole_db" => true,
"limit" => "10"
}
@@ -111,10 +108,8 @@ defmodule Pleroma.Web.ActivityPub.UserView do
params
end
- activities = ActivityPub.fetch_public_activities(params)
- min_id = Enum.at(activities, 0).id
-
- activities = Enum.reverse(activities)
+ activities = ActivityPub.fetch_user_activities(user, nil, params)
+ min_id = Enum.at(Enum.reverse(activities), 0).id
max_id = Enum.at(activities, 0).id
collection =
diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
index 956787d5a..b8c605e83 100644
--- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
+++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
@@ -11,15 +11,20 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
import Ecto.Query
require Logger
+ @httpoison Application.get_env(:pleroma, :httpoison)
+
action_fallback(:errors)
def create_app(conn, params) do
with cs <- App.register_changeset(%App{}, params) |> IO.inspect(),
{:ok, app} <- Repo.insert(cs) |> IO.inspect() do
res = %{
- id: app.id,
+ id: app.id |> to_string,
+ name: app.client_name,
client_id: app.client_id,
- client_secret: app.client_secret
+ client_secret: app.client_secret,
+ redirect_uri: app.redirect_uris,
+ website: app.website
}
json(conn, res)
@@ -1097,4 +1102,38 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|> put_status(500)
|> json("Something went wrong")
end
+
+ @suggestions Application.get_env(:pleroma, :suggestions)
+
+ def suggestions(%{assigns: %{user: user}} = conn, _) do
+ if Keyword.get(@suggestions, :enabled, false) do
+ api = Keyword.get(@suggestions, :third_party_engine, "")
+ timeout = Keyword.get(@suggestions, :timeout, 5000)
+
+ host =
+ Application.get_env(:pleroma, Pleroma.Web.Endpoint)
+ |> Keyword.get(:url)
+ |> Keyword.get(:host)
+
+ user = user.nickname
+ url = String.replace(api, "{{host}}", host) |> String.replace("{{user}}", user)
+
+ with {:ok, %{status_code: 200, body: body}} <-
+ @httpoison.get(url, [], timeout: timeout, recv_timeout: timeout),
+ {:ok, data} <- Jason.decode(body) do
+ data2 =
+ Enum.slice(data, 0, 40)
+ |> Enum.map(fn x ->
+ Map.put(x, "id", User.get_or_fetch(x["acct"]).id)
+ end)
+
+ conn
+ |> json(data2)
+ else
+ e -> Logger.error("Could not retrieve suggestions at fetch #{url}, #{inspect(e)}")
+ end
+ else
+ json(conn, [])
+ end
+ end
end
diff --git a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex
index 7c67bbf1c..2fab60274 100644
--- a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex
+++ b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex
@@ -21,6 +21,7 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do
def nodeinfo(conn, %{"version" => "2.0"}) do
instance = Application.get_env(:pleroma, :instance)
media_proxy = Application.get_env(:pleroma, :media_proxy)
+ suggestions = Application.get_env(:pleroma, :suggestions)
stats = Stats.get_stats()
response = %{
@@ -45,7 +46,13 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do
nodeName: Keyword.get(instance, :name),
nodeDescription: Keyword.get(instance, :description),
mediaProxy: Keyword.get(media_proxy, :enabled),
- private: !Keyword.get(instance, :public, true)
+ private: !Keyword.get(instance, :public, true),
+ suggestions: %{
+ enabled: Keyword.get(suggestions, :enabled, false),
+ thirdPartyEngine: Keyword.get(suggestions, :third_party_engine, ""),
+ timeout: Keyword.get(suggestions, :timeout, 5000),
+ web: Keyword.get(suggestions, :web, "")
+ }
}
}
diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex
index be0c10ea4..2dadf974c 100644
--- a/lib/pleroma/web/router.ex
+++ b/lib/pleroma/web/router.ex
@@ -141,6 +141,8 @@ defmodule Pleroma.Web.Router do
get("/domain_blocks", MastodonAPIController, :domain_blocks)
post("/domain_blocks", MastodonAPIController, :block_domain)
delete("/domain_blocks", MastodonAPIController, :unblock_domain)
+
+ get("/suggestions", MastodonAPIController, :suggestions)
end
scope "/api/web", Pleroma.Web.MastodonAPI do
diff --git a/lib/pleroma/web/templates/mastodon_api/mastodon/index.html.eex b/lib/pleroma/web/templates/mastodon_api/mastodon/index.html.eex
index 6a00b9e2c..0862412ea 100644
--- a/lib/pleroma/web/templates/mastodon_api/mastodon/index.html.eex
+++ b/lib/pleroma/web/templates/mastodon_api/mastodon/index.html.eex
@@ -19,7 +19,7 @@
<script id='initial-state' type='application/json'><%= raw @initial_state %></script>
<script src="/packs/application.js"></script>
</head>
-<body class='app-body no-reduce-motion'>
+<body class='app-body no-reduce-motion system-font'>
<div class='app-holder' data-props='{&quot;locale&quot;:&quot;en&quot;}' id='mastodon'>
</div>
</body>