aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRoman Chvanikov <chvanikoff@pm.me>2019-06-30 21:23:35 +0300
committerRoman Chvanikov <chvanikoff@pm.me>2019-06-30 21:23:35 +0300
commitd2cb18b2a342b990cc47dfdc42adb843c3db1b5e (patch)
tree2982108b486fe8361fba5f22c53491bb265924b4 /lib
parent657277ffc0d3d25be4376ed629057a2d2cefb2e1 (diff)
parent66380d36d540751f59445c8a65e9747ce5475ee5 (diff)
downloadpleroma-d2cb18b2a342b990cc47dfdc42adb843c3db1b5e.tar.gz
Merge branch 'develop' into feature/digest-email
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/config.ex2
-rw-r--r--lib/pleroma/upload/filter/anonymize_filename.ex17
-rw-r--r--lib/pleroma/web/activity_pub/mrf/mediaproxy_warming_policy.ex56
-rw-r--r--lib/pleroma/web/admin_api/views/account_view.ex8
-rw-r--r--lib/pleroma/web/admin_api/views/report_view.ex10
-rw-r--r--lib/pleroma/web/common_api/common_api.ex4
-rw-r--r--lib/pleroma/web/mastodon_api/mastodon_api_controller.ex4
7 files changed, 91 insertions, 10 deletions
diff --git a/lib/pleroma/config.ex b/lib/pleroma/config.ex
index 71a47b9fb..fcc039710 100644
--- a/lib/pleroma/config.ex
+++ b/lib/pleroma/config.ex
@@ -38,7 +38,7 @@ defmodule Pleroma.Config do
def put([parent_key | keys], value) do
parent =
- Application.get_env(:pleroma, parent_key)
+ Application.get_env(:pleroma, parent_key, [])
|> put_in(keys, value)
Application.put_env(:pleroma, parent_key, parent)
diff --git a/lib/pleroma/upload/filter/anonymize_filename.ex b/lib/pleroma/upload/filter/anonymize_filename.ex
index 5ca53a79b..a8516811c 100644
--- a/lib/pleroma/upload/filter/anonymize_filename.ex
+++ b/lib/pleroma/upload/filter/anonymize_filename.ex
@@ -10,10 +10,19 @@ defmodule Pleroma.Upload.Filter.AnonymizeFilename do
"""
@behaviour Pleroma.Upload.Filter
- def filter(upload) do
- extension = List.last(String.split(upload.name, "."))
- name = Pleroma.Config.get([__MODULE__, :text], random(extension))
- {:ok, %Pleroma.Upload{upload | name: name}}
+ alias Pleroma.Config
+ alias Pleroma.Upload
+
+ def filter(%Upload{name: name} = upload) do
+ extension = List.last(String.split(name, "."))
+ name = predefined_name(extension) || random(extension)
+ {:ok, %Upload{upload | name: name}}
+ end
+
+ @spec predefined_name(String.t()) :: String.t() | nil
+ defp predefined_name(extension) do
+ with name when not is_nil(name) <- Config.get([__MODULE__, :text]),
+ do: String.replace(name, "{extension}", extension)
end
defp random(extension) do
diff --git a/lib/pleroma/web/activity_pub/mrf/mediaproxy_warming_policy.ex b/lib/pleroma/web/activity_pub/mrf/mediaproxy_warming_policy.ex
new file mode 100644
index 000000000..01d21a299
--- /dev/null
+++ b/lib/pleroma/web/activity_pub/mrf/mediaproxy_warming_policy.ex
@@ -0,0 +1,56 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy do
+ @moduledoc "Preloads any attachments in the MediaProxy cache by prefetching them"
+ @behaviour Pleroma.Web.ActivityPub.MRF
+
+ alias Pleroma.HTTP
+ alias Pleroma.Web.MediaProxy
+
+ require Logger
+
+ @hackney_options [
+ pool: :media,
+ recv_timeout: 10_000
+ ]
+
+ def perform(:prefetch, url) do
+ Logger.info("Prefetching #{inspect(url)}")
+
+ url
+ |> MediaProxy.url()
+ |> HTTP.get([], adapter: @hackney_options)
+ end
+
+ def perform(:preload, %{"object" => %{"attachment" => attachments}} = _message) do
+ Enum.each(attachments, fn
+ %{"url" => url} when is_list(url) ->
+ url
+ |> Enum.each(fn
+ %{"href" => href} ->
+ PleromaJobQueue.enqueue(:background, __MODULE__, [:prefetch, href])
+
+ x ->
+ Logger.debug("Unhandled attachment URL object #{inspect(x)}")
+ end)
+
+ x ->
+ Logger.debug("Unhandled attachment #{inspect(x)}")
+ end)
+ end
+
+ @impl true
+ def filter(
+ %{"type" => "Create", "object" => %{"attachment" => attachments} = _object} = message
+ )
+ when is_list(attachments) and length(attachments) > 0 do
+ PleromaJobQueue.enqueue(:background, __MODULE__, [:preload, message])
+
+ {:ok, message}
+ end
+
+ @impl true
+ def filter(message), do: {:ok, message}
+end
diff --git a/lib/pleroma/web/admin_api/views/account_view.ex b/lib/pleroma/web/admin_api/views/account_view.ex
index 28bb667d8..7e1b9c431 100644
--- a/lib/pleroma/web/admin_api/views/account_view.ex
+++ b/lib/pleroma/web/admin_api/views/account_view.ex
@@ -5,8 +5,11 @@
defmodule Pleroma.Web.AdminAPI.AccountView do
use Pleroma.Web, :view
+ alias Pleroma.HTML
+ alias Pleroma.User
alias Pleroma.User.Info
alias Pleroma.Web.AdminAPI.AccountView
+ alias Pleroma.Web.MediaProxy
def render("index.json", %{users: users, count: count, page_size: page_size}) do
%{
@@ -17,9 +20,14 @@ defmodule Pleroma.Web.AdminAPI.AccountView do
end
def render("show.json", %{user: user}) do
+ avatar = User.avatar_url(user) |> MediaProxy.url()
+ display_name = HTML.strip_tags(user.name || user.nickname)
+
%{
"id" => user.id,
+ "avatar" => avatar,
"nickname" => user.nickname,
+ "display_name" => display_name,
"deactivated" => user.info.deactivated,
"local" => user.local,
"roles" => Info.roles(user.info),
diff --git a/lib/pleroma/web/admin_api/views/report_view.ex b/lib/pleroma/web/admin_api/views/report_view.ex
index e7db3a8ff..73ccdc582 100644
--- a/lib/pleroma/web/admin_api/views/report_view.ex
+++ b/lib/pleroma/web/admin_api/views/report_view.ex
@@ -8,7 +8,6 @@ defmodule Pleroma.Web.AdminAPI.ReportView do
alias Pleroma.HTML
alias Pleroma.User
alias Pleroma.Web.CommonAPI.Utils
- alias Pleroma.Web.MastodonAPI.AccountView
alias Pleroma.Web.MastodonAPI.StatusView
def render("index.json", %{reports: reports}) do
@@ -38,12 +37,17 @@ defmodule Pleroma.Web.AdminAPI.ReportView do
%{
id: report.id,
- account: AccountView.render("account.json", %{user: account}),
- actor: AccountView.render("account.json", %{user: user}),
+ account: merge_account_views(account),
+ actor: merge_account_views(user),
content: content,
created_at: created_at,
statuses: StatusView.render("index.json", %{activities: statuses, as: :activity}),
state: report.data["state"]
}
end
+
+ defp merge_account_views(user) do
+ Pleroma.Web.MastodonAPI.AccountView.render("account.json", %{user: user})
+ |> Map.merge(Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: user}))
+ end
end
diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex
index f8df1e2ea..f71c67a3d 100644
--- a/lib/pleroma/web/common_api/common_api.ex
+++ b/lib/pleroma/web/common_api/common_api.ex
@@ -11,6 +11,7 @@ defmodule Pleroma.Web.CommonAPI do
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Utils
+ alias Pleroma.Web.ActivityPub.Visibility
import Pleroma.Web.CommonAPI.Utils
@@ -284,12 +285,11 @@ defmodule Pleroma.Web.CommonAPI do
},
object: %Object{
data: %{
- "to" => object_to,
"type" => "Note"
}
}
} = activity <- get_by_id_or_ap_id(id_or_ap_id),
- true <- Enum.member?(object_to, "https://www.w3.org/ns/activitystreams#Public"),
+ true <- Visibility.is_public?(activity),
%{valid?: true} = info_changeset <-
User.Info.add_pinnned_activity(user.info, activity),
changeset <-
diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
index 7cdba4cc0..ceb88511b 100644
--- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
+++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
@@ -356,6 +356,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
def user_statuses(%{assigns: %{user: reading_user}} = conn, params) do
with %User{} = user <- User.get_cached_by_id(params["id"]) do
+ params =
+ params
+ |> Map.put("tag", params["tagged"])
+
activities = ActivityPub.fetch_user_activities(user, reading_user, params)
conn