forked from AkkomaGang/akkoma
Merge branch 'develop' into 'fix/mix-task-uploads-moduledoc'
# Conflicts: # lib/mix/tasks/pleroma/uploads.ex
This commit is contained in:
commit
bda25b999b
58 changed files with 241 additions and 286 deletions
|
@ -1,5 +1,5 @@
|
||||||
defmodule Mix.Tasks.Pleroma.Common do
|
defmodule Mix.Tasks.Pleroma.Common do
|
||||||
@shortdoc "Common functions to be reused in mix tasks"
|
@doc "Common functions to be reused in mix tasks"
|
||||||
def start_pleroma do
|
def start_pleroma do
|
||||||
Mix.Task.run("app.start")
|
Mix.Task.run("app.start")
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
defmodule Mix.Tasks.Pleroma.Instance do
|
defmodule Mix.Tasks.Pleroma.Instance do
|
||||||
use Mix.Task
|
use Mix.Task
|
||||||
alias Pleroma.{Repo, User}
|
|
||||||
alias Mix.Tasks.Pleroma.Common
|
alias Mix.Tasks.Pleroma.Common
|
||||||
|
|
||||||
@shortdoc "Manages Pleroma instance"
|
@shortdoc "Manages Pleroma instance"
|
||||||
|
|
|
@ -22,7 +22,7 @@ defmodule Mix.Tasks.Pleroma.Relay do
|
||||||
def run(["follow", target]) do
|
def run(["follow", target]) do
|
||||||
Common.start_pleroma()
|
Common.start_pleroma()
|
||||||
|
|
||||||
with {:ok, activity} <- Relay.follow(target) do
|
with {:ok, _activity} <- Relay.follow(target) do
|
||||||
# put this task to sleep to allow the genserver to push out the messages
|
# put this task to sleep to allow the genserver to push out the messages
|
||||||
:timer.sleep(500)
|
:timer.sleep(500)
|
||||||
else
|
else
|
||||||
|
@ -33,7 +33,7 @@ def run(["follow", target]) do
|
||||||
def run(["unfollow", target]) do
|
def run(["unfollow", target]) do
|
||||||
Common.start_pleroma()
|
Common.start_pleroma()
|
||||||
|
|
||||||
with {:ok, activity} <- Relay.unfollow(target) do
|
with {:ok, _activity} <- Relay.unfollow(target) do
|
||||||
# put this task to sleep to allow the genserver to push out the messages
|
# put this task to sleep to allow the genserver to push out the messages
|
||||||
:timer.sleep(500)
|
:timer.sleep(500)
|
||||||
else
|
else
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
defmodule Mix.Tasks.Pleroma.Uploads do
|
defmodule Mix.Tasks.Pleroma.Uploads do
|
||||||
use Mix.Task
|
use Mix.Task
|
||||||
import Mix.Ecto
|
alias Pleroma.{Upload, Uploaders.Local}
|
||||||
alias Pleroma.{Upload, Uploaders.Local, Uploaders.S3}
|
|
||||||
alias Mix.Tasks.Pleroma.Common
|
alias Mix.Tasks.Pleroma.Common
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
@log_every 50
|
@log_every 50
|
||||||
|
|
||||||
@shortdoc "Migrates uploads from local to remote storage"
|
@shortdoc "Migrates uploads from local to remote storage"
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
|
Manages uploads
|
||||||
|
|
||||||
## Migrate uploads from local to remote storage
|
## Migrate uploads from local to remote storage
|
||||||
mix pleroma.uploads migrate_local TARGET_UPLOADER [OPTIONS...]
|
mix pleroma.uploads migrate_local TARGET_UPLOADER [OPTIONS...]
|
||||||
Options:
|
Options:
|
||||||
|
@ -16,7 +18,6 @@ defmodule Mix.Tasks.Pleroma.Uploads do
|
||||||
|
|
||||||
A list of avalible uploaders can be seen in config.exs
|
A list of avalible uploaders can be seen in config.exs
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def run(["migrate_local", target_uploader | args]) do
|
def run(["migrate_local", target_uploader | args]) do
|
||||||
delete? = Enum.member?(args, "--delete")
|
delete? = Enum.member?(args, "--delete")
|
||||||
Common.start_pleroma()
|
Common.start_pleroma()
|
||||||
|
@ -63,7 +64,7 @@ def run(["migrate_local", target_uploader | args]) do
|
||||||
|
|
||||||
File.exists?(root_path) ->
|
File.exists?(root_path) ->
|
||||||
file = Path.basename(id)
|
file = Path.basename(id)
|
||||||
[hash, ext] = String.split(id, ".")
|
hash = Path.rootname(id)
|
||||||
{%Pleroma.Upload{id: hash, name: file, path: file, tempfile: root_path}, root_path}
|
{%Pleroma.Upload{id: hash, name: file, path: file, tempfile: root_path}, root_path}
|
||||||
|
|
||||||
true ->
|
true ->
|
||||||
|
|
|
@ -235,6 +235,26 @@ def run(["set", nickname | rest]) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def run(["invite"]) do
|
||||||
|
Common.start_pleroma()
|
||||||
|
|
||||||
|
with {:ok, token} <- Pleroma.UserInviteToken.create_token() do
|
||||||
|
Mix.shell().info("Generated user invite token")
|
||||||
|
|
||||||
|
url =
|
||||||
|
Pleroma.Web.Router.Helpers.redirect_url(
|
||||||
|
Pleroma.Web.Endpoint,
|
||||||
|
:registration_page,
|
||||||
|
token.token
|
||||||
|
)
|
||||||
|
|
||||||
|
IO.puts(url)
|
||||||
|
else
|
||||||
|
_ ->
|
||||||
|
Mix.shell().error("Could not create invite token.")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
defp set_moderator(user, value) do
|
defp set_moderator(user, value) do
|
||||||
info_cng = User.Info.admin_api_update(user.info, %{is_moderator: value})
|
info_cng = User.Info.admin_api_update(user.info, %{is_moderator: value})
|
||||||
|
|
||||||
|
@ -270,24 +290,4 @@ defp set_locked(user, value) do
|
||||||
|
|
||||||
Mix.shell().info("Locked status of #{user.nickname}: #{user.info.locked}")
|
Mix.shell().info("Locked status of #{user.nickname}: #{user.info.locked}")
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(["invite"]) do
|
|
||||||
Common.start_pleroma()
|
|
||||||
|
|
||||||
with {:ok, token} <- Pleroma.UserInviteToken.create_token() do
|
|
||||||
Mix.shell().info("Generated user invite token")
|
|
||||||
|
|
||||||
url =
|
|
||||||
Pleroma.Web.Router.Helpers.redirect_url(
|
|
||||||
Pleroma.Web.Endpoint,
|
|
||||||
:registration_page,
|
|
||||||
token.token
|
|
||||||
)
|
|
||||||
|
|
||||||
IO.puts(url)
|
|
||||||
else
|
|
||||||
_ ->
|
|
||||||
Mix.shell().error("Could not create invite token.")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,7 +15,6 @@ def user_agent() do
|
||||||
|
|
||||||
# See http://elixir-lang.org/docs/stable/elixir/Application.html
|
# See http://elixir-lang.org/docs/stable/elixir/Application.html
|
||||||
# for more information on OTP Applications
|
# for more information on OTP Applications
|
||||||
@env Mix.env()
|
|
||||||
def start(_type, _args) do
|
def start(_type, _args) do
|
||||||
import Cachex.Spec
|
import Cachex.Spec
|
||||||
|
|
||||||
|
|
|
@ -165,7 +165,7 @@ defp load_from_file(file) do
|
||||||
|
|
||||||
defp load_from_file_stream(stream) do
|
defp load_from_file_stream(stream) do
|
||||||
stream
|
stream
|
||||||
|> Stream.map(&String.strip/1)
|
|> Stream.map(&String.trim/1)
|
||||||
|> Stream.map(fn line ->
|
|> Stream.map(fn line ->
|
||||||
case String.split(line, ~r/,\s*/) do
|
case String.split(line, ~r/,\s*/) do
|
||||||
[name, file] -> {name, file}
|
[name, file] -> {name, file}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
defmodule Pleroma.Filter do
|
defmodule Pleroma.Filter do
|
||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
import Ecto.{Changeset, Query}
|
import Ecto.{Changeset, Query}
|
||||||
alias Pleroma.{User, Repo, Activity}
|
alias Pleroma.{User, Repo}
|
||||||
|
|
||||||
schema "filters" do
|
schema "filters" do
|
||||||
belongs_to(:user, Pleroma.User)
|
belongs_to(:user, User)
|
||||||
field(:filter_id, :integer)
|
field(:filter_id, :integer)
|
||||||
field(:hide, :boolean, default: false)
|
field(:hide, :boolean, default: false)
|
||||||
field(:whole_word, :boolean, default: true)
|
field(:whole_word, :boolean, default: true)
|
||||||
|
@ -26,7 +26,7 @@ def get(id, %{id: user_id} = _user) do
|
||||||
Repo.one(query)
|
Repo.one(query)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_filters(%Pleroma.User{id: user_id} = user) do
|
def get_filters(%User{id: user_id} = _user) do
|
||||||
query =
|
query =
|
||||||
from(
|
from(
|
||||||
f in Pleroma.Filter,
|
f in Pleroma.Filter,
|
||||||
|
|
|
@ -166,7 +166,7 @@ def scrub_attribute("img", {"src", "http" <> target}) do
|
||||||
{"src", media_url}
|
{"src", media_url}
|
||||||
end
|
end
|
||||||
|
|
||||||
def scrub_attribute(tag, attribute), do: attribute
|
def scrub_attribute(_tag, attribute), do: attribute
|
||||||
|
|
||||||
def scrub({"img", attributes, children}) do
|
def scrub({"img", attributes, children}) do
|
||||||
attributes =
|
attributes =
|
||||||
|
@ -177,9 +177,9 @@ def scrub({"img", attributes, children}) do
|
||||||
{"img", attributes, children}
|
{"img", attributes, children}
|
||||||
end
|
end
|
||||||
|
|
||||||
def scrub({:comment, children}), do: ""
|
def scrub({:comment, _children}), do: ""
|
||||||
|
|
||||||
def scrub({tag, attributes, children}), do: {tag, attributes, children}
|
def scrub({tag, attributes, children}), do: {tag, attributes, children}
|
||||||
def scrub({tag, children}), do: children
|
def scrub({_tag, children}), do: children
|
||||||
def scrub(text), do: text
|
def scrub(text), do: text
|
||||||
end
|
end
|
||||||
|
|
|
@ -25,7 +25,7 @@ def new(opts \\ []) do
|
||||||
|
|
||||||
# fetch Hackney options
|
# fetch Hackney options
|
||||||
#
|
#
|
||||||
defp hackney_options(opts \\ []) do
|
defp hackney_options(opts) do
|
||||||
options = Keyword.get(opts, :adapter, [])
|
options = Keyword.get(opts, :adapter, [])
|
||||||
@hackney_options ++ options
|
@hackney_options ++ options
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,7 +23,7 @@ def follow_changeset(list, attrs \\ %{}) do
|
||||||
|> validate_required([:following])
|
|> validate_required([:following])
|
||||||
end
|
end
|
||||||
|
|
||||||
def for_user(user, opts) do
|
def for_user(user, _opts) do
|
||||||
query =
|
query =
|
||||||
from(
|
from(
|
||||||
l in Pleroma.List,
|
l in Pleroma.List,
|
||||||
|
@ -46,7 +46,7 @@ def get(id, %{id: user_id} = _user) do
|
||||||
Repo.one(query)
|
Repo.one(query)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_following(%Pleroma.List{following: following} = list) do
|
def get_following(%Pleroma.List{following: following} = _list) do
|
||||||
q =
|
q =
|
||||||
from(
|
from(
|
||||||
u in User,
|
u in User,
|
||||||
|
|
|
@ -33,10 +33,10 @@ def bin_mime_type(<<head::binary-size(@read_bytes), _::binary>>) do
|
||||||
{:ok, check_mime_type(head)}
|
{:ok, check_mime_type(head)}
|
||||||
end
|
end
|
||||||
|
|
||||||
def mime_type(<<_::binary>>), do: {:ok, @default}
|
|
||||||
|
|
||||||
def bin_mime_type(_), do: :error
|
def bin_mime_type(_), do: :error
|
||||||
|
|
||||||
|
def mime_type(<<_::binary>>), do: {:ok, @default}
|
||||||
|
|
||||||
defp fix_extension(filename, content_type) do
|
defp fix_extension(filename, content_type) do
|
||||||
parts = String.split(filename, ".")
|
parts = String.split(filename, ".")
|
||||||
|
|
||||||
|
|
|
@ -118,7 +118,7 @@ def create_notification(%Activity{} = activity, %User{} = user) do
|
||||||
def get_notified_from_activity(activity, local_only \\ true)
|
def get_notified_from_activity(activity, local_only \\ true)
|
||||||
|
|
||||||
def get_notified_from_activity(
|
def get_notified_from_activity(
|
||||||
%Activity{data: %{"to" => _, "type" => type} = data} = activity,
|
%Activity{data: %{"to" => _, "type" => type} = _data} = activity,
|
||||||
local_only
|
local_only
|
||||||
)
|
)
|
||||||
when type in ["Create", "Like", "Announce", "Follow"] do
|
when type in ["Create", "Like", "Announce", "Follow"] do
|
||||||
|
@ -131,18 +131,18 @@ def get_notified_from_activity(
|
||||||
User.get_users_from_set(recipients, local_only)
|
User.get_users_from_set(recipients, local_only)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_notified_from_activity(_, local_only), do: []
|
def get_notified_from_activity(_, _local_only), do: []
|
||||||
|
|
||||||
defp maybe_notify_to_recipients(
|
defp maybe_notify_to_recipients(
|
||||||
recipients,
|
recipients,
|
||||||
%Activity{data: %{"to" => to, "type" => type}} = activity
|
%Activity{data: %{"to" => to, "type" => _type}} = _activity
|
||||||
) do
|
) do
|
||||||
recipients ++ to
|
recipients ++ to
|
||||||
end
|
end
|
||||||
|
|
||||||
defp maybe_notify_mentioned_recipients(
|
defp maybe_notify_mentioned_recipients(
|
||||||
recipients,
|
recipients,
|
||||||
%Activity{data: %{"to" => to, "type" => type} = data} = activity
|
%Activity{data: %{"to" => _to, "type" => type} = data} = _activity
|
||||||
)
|
)
|
||||||
when type == "Create" do
|
when type == "Create" do
|
||||||
object = Object.normalize(data["object"])
|
object = Object.normalize(data["object"])
|
||||||
|
|
|
@ -26,14 +26,7 @@ def call(
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(
|
def call(%{assigns: %{auth_credentials: %{password: _}}} = conn, _) do
|
||||||
%{
|
|
||||||
assigns: %{
|
|
||||||
auth_credentials: %{password: password}
|
|
||||||
}
|
|
||||||
} = conn,
|
|
||||||
_
|
|
||||||
) do
|
|
||||||
Pbkdf2.dummy_checkpw()
|
Pbkdf2.dummy_checkpw()
|
||||||
conn
|
conn
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,7 +5,7 @@ def init(options) do
|
||||||
options
|
options
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(conn, opts) do
|
def call(conn, _opts) do
|
||||||
with ["Basic " <> header] <- get_req_header(conn, "authorization"),
|
with ["Basic " <> header] <- get_req_header(conn, "authorization"),
|
||||||
{:ok, userinfo} <- Base.decode64(header),
|
{:ok, userinfo} <- Base.decode64(header),
|
||||||
[username, password] <- String.split(userinfo, ":", parts: 2) do
|
[username, password] <- String.split(userinfo, ":", parts: 2) do
|
||||||
|
|
|
@ -5,7 +5,7 @@ def init(options) do
|
||||||
options
|
options
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(conn, opts) do
|
def call(conn, _opts) do
|
||||||
if Keyword.get(Application.get_env(:pleroma, :instance), :federating) do
|
if Keyword.get(Application.get_env(:pleroma, :instance), :federating) do
|
||||||
conn
|
conn
|
||||||
else
|
else
|
||||||
|
|
|
@ -4,10 +4,10 @@ defmodule Pleroma.Plugs.HTTPSecurityPlug do
|
||||||
|
|
||||||
def init(opts), do: opts
|
def init(opts), do: opts
|
||||||
|
|
||||||
def call(conn, options) do
|
def call(conn, _options) do
|
||||||
if Config.get([:http_security, :enabled]) do
|
if Config.get([:http_security, :enabled]) do
|
||||||
conn =
|
conn
|
||||||
merge_resp_headers(conn, headers())
|
|> merge_resp_headers(headers())
|
||||||
|> maybe_send_sts_header(Config.get([:http_security, :sts]))
|
|> maybe_send_sts_header(Config.get([:http_security, :sts]))
|
||||||
else
|
else
|
||||||
conn
|
conn
|
||||||
|
@ -42,7 +42,7 @@ defp csp_string do
|
||||||
"script-src 'self'",
|
"script-src 'self'",
|
||||||
"connect-src 'self' " <> String.replace(Pleroma.Web.Endpoint.static_url(), "http", "ws"),
|
"connect-src 'self' " <> String.replace(Pleroma.Web.Endpoint.static_url(), "http", "ws"),
|
||||||
"manifest-src 'self'",
|
"manifest-src 'self'",
|
||||||
if @protocol == "https" do
|
if protocol == "https" do
|
||||||
"upgrade-insecure-requests"
|
"upgrade-insecure-requests"
|
||||||
end
|
end
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
defmodule Pleroma.Plugs.SessionAuthenticationPlug do
|
defmodule Pleroma.Plugs.SessionAuthenticationPlug do
|
||||||
import Plug.Conn
|
import Plug.Conn
|
||||||
alias Pleroma.User
|
|
||||||
|
|
||||||
def init(options) do
|
def init(options) do
|
||||||
options
|
options
|
||||||
|
|
|
@ -8,10 +8,6 @@ defmodule Pleroma.Plugs.UploadedMedia do
|
||||||
@behaviour Plug
|
@behaviour Plug
|
||||||
# no slashes
|
# no slashes
|
||||||
@path "media"
|
@path "media"
|
||||||
@cache_control %{
|
|
||||||
default: "public, max-age=1209600",
|
|
||||||
error: "public, must-revalidate, max-age=160"
|
|
||||||
}
|
|
||||||
|
|
||||||
def init(_opts) do
|
def init(_opts) do
|
||||||
static_plug_opts =
|
static_plug_opts =
|
||||||
|
|
|
@ -7,7 +7,7 @@ def init(options) do
|
||||||
options
|
options
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(conn, options) do
|
def call(conn, _options) do
|
||||||
with %{auth_credentials: %{username: username}} <- conn.assigns,
|
with %{auth_credentials: %{username: username}} <- conn.assigns,
|
||||||
{:ok, %User{} = user} <- user_fetcher(username) do
|
{:ok, %User{} = user} <- user_fetcher(username) do
|
||||||
conn
|
conn
|
||||||
|
|
|
@ -85,7 +85,9 @@ defmodule Pleroma.ReverseProxy do
|
||||||
| {:redirect_on_failure, boolean()}
|
| {:redirect_on_failure, boolean()}
|
||||||
|
|
||||||
@spec call(Plug.Conn.t(), url :: String.t(), [option()]) :: Plug.Conn.t()
|
@spec call(Plug.Conn.t(), url :: String.t(), [option()]) :: Plug.Conn.t()
|
||||||
def call(conn = %{method: method}, url, opts \\ []) when method in @methods do
|
def call(_conn, _url, _opts \\ [])
|
||||||
|
|
||||||
|
def call(conn = %{method: method}, url, opts) when method in @methods do
|
||||||
hackney_opts =
|
hackney_opts =
|
||||||
@default_hackney_options
|
@default_hackney_options
|
||||||
|> Keyword.merge(Keyword.get(opts, :http, []))
|
|> Keyword.merge(Keyword.get(opts, :http, []))
|
||||||
|
@ -240,7 +242,6 @@ defp put_resp_headers(conn, headers) do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp build_req_headers(headers, opts) do
|
defp build_req_headers(headers, opts) do
|
||||||
headers =
|
|
||||||
headers
|
headers
|
||||||
|> downcase_headers()
|
|> downcase_headers()
|
||||||
|> Enum.filter(fn {k, _} -> k in @keep_req_headers end)
|
|> Enum.filter(fn {k, _} -> k in @keep_req_headers end)
|
||||||
|
@ -268,7 +269,7 @@ defp build_resp_headers(headers, opts) do
|
||||||
|> (fn headers -> headers ++ Keyword.get(opts, :resp_headers, []) end).()
|
|> (fn headers -> headers ++ Keyword.get(opts, :resp_headers, []) end).()
|
||||||
end
|
end
|
||||||
|
|
||||||
defp build_resp_cache_headers(headers, opts) do
|
defp build_resp_cache_headers(headers, _opts) do
|
||||||
has_cache? = Enum.any?(headers, fn {k, _} -> k in @resp_cache_headers end)
|
has_cache? = Enum.any?(headers, fn {k, _} -> k in @resp_cache_headers end)
|
||||||
|
|
||||||
if has_cache? do
|
if has_cache? do
|
||||||
|
|
|
@ -128,7 +128,6 @@ defp get_opts(opts) do
|
||||||
opts
|
opts
|
||||||
end
|
end
|
||||||
|
|
||||||
opts =
|
|
||||||
if Pleroma.Config.get([:instance, :dedupe_media]) == true &&
|
if Pleroma.Config.get([:instance, :dedupe_media]) == true &&
|
||||||
!Enum.member?(opts.filters, Pleroma.Upload.Filter.Dedupe) do
|
!Enum.member?(opts.filters, Pleroma.Upload.Filter.Dedupe) do
|
||||||
Logger.warn("""
|
Logger.warn("""
|
||||||
|
@ -216,7 +215,5 @@ defp url_from_spec(base_url, {:file, path}) do
|
||||||
|> Path.join()
|
|> Path.join()
|
||||||
end
|
end
|
||||||
|
|
||||||
defp url_from_spec({:url, url}) do
|
defp url_from_spec(_base_url, {:url, url}), do: url
|
||||||
url
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
defmodule Pleroma.Upload.Filter.Dedupe do
|
defmodule Pleroma.Upload.Filter.Dedupe do
|
||||||
@behaviour Pleroma.Upload.Filter
|
@behaviour Pleroma.Upload.Filter
|
||||||
|
alias Pleroma.Upload
|
||||||
|
|
||||||
def filter(upload = %Pleroma.Upload{name: name, tempfile: path}) do
|
def filter(upload = %Upload{name: name}) do
|
||||||
extension = String.split(name, ".") |> List.last()
|
extension = String.split(name, ".") |> List.last()
|
||||||
shasum = :crypto.hash(:sha256, File.read!(upload.tempfile)) |> Base.encode16(case: :lower)
|
shasum = :crypto.hash(:sha256, File.read!(upload.tempfile)) |> Base.encode16(case: :lower)
|
||||||
filename = shasum <> "." <> extension
|
filename = shasum <> "." <> extension
|
||||||
{:ok, %Pleroma.Upload{upload | id: shasum, path: filename}}
|
{:ok, %Upload{upload | id: shasum, path: filename}}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
defmodule Pleroma.Upload.Filter.Mogrify do
|
defmodule Pleroma.Upload.Filter.Mogrify do
|
||||||
@behaviour Pleroma.Uploader.Filter
|
@behaviour Pleroma.Upload.Filter
|
||||||
|
|
||||||
@type conversion :: action :: String.t() | {action :: String.t(), opts :: String.t()}
|
@type conversion :: action :: String.t() | {action :: String.t(), opts :: String.t()}
|
||||||
@type conversions :: conversion() | [conversion()]
|
@type conversions :: conversion() | [conversion()]
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
defmodule Pleroma.Uploaders.Local do
|
defmodule Pleroma.Uploaders.Local do
|
||||||
@behaviour Pleroma.Uploaders.Uploader
|
@behaviour Pleroma.Uploaders.Uploader
|
||||||
|
|
||||||
alias Pleroma.Web
|
|
||||||
|
|
||||||
def get_file(_) do
|
def get_file(_) do
|
||||||
{:ok, {:static_dir, upload_path()}}
|
{:ok, {:static_dir, upload_path()}}
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,8 +12,8 @@ def get_file(file) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def put_file(upload) do
|
def put_file(upload) do
|
||||||
cgi = Pleroma.Config.get([Pleroma.Uploaders.MDII, :cgi])
|
cgi = Config.get([Pleroma.Uploaders.MDII, :cgi])
|
||||||
files = Pleroma.Config.get([Pleroma.Uploaders.MDII, :files])
|
files = Config.get([Pleroma.Uploaders.MDII, :files])
|
||||||
|
|
||||||
{:ok, file_data} = File.read(upload.tempfile)
|
{:ok, file_data} = File.read(upload.tempfile)
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@ def process_url(url) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def upload_file(filename, body, content_type) do
|
def upload_file(filename, body, content_type) do
|
||||||
object_url = Pleroma.Config.get!([Pleroma.Uploaders.Swift, :object_url])
|
|
||||||
token = Pleroma.Uploaders.Swift.Keystone.get_token()
|
token = Pleroma.Uploaders.Swift.Keystone.get_token()
|
||||||
|
|
||||||
case put("#{filename}", body, "X-Auth-Token": token, "Content-Type": content_type) do
|
case put("#{filename}", body, "X-Auth-Token": token, "Content-Type": content_type) do
|
||||||
|
|
|
@ -2,7 +2,6 @@ defmodule Pleroma.User do
|
||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
|
|
||||||
import Ecto.{Changeset, Query}
|
import Ecto.{Changeset, Query}
|
||||||
alias Ecto.Multi
|
|
||||||
alias Pleroma.{Repo, User, Object, Web, Activity, Notification}
|
alias Pleroma.{Repo, User, Object, Web, Activity, Notification}
|
||||||
alias Comeonin.Pbkdf2
|
alias Comeonin.Pbkdf2
|
||||||
alias Pleroma.Formatter
|
alias Pleroma.Formatter
|
||||||
|
@ -10,6 +9,8 @@ defmodule Pleroma.User do
|
||||||
alias Pleroma.Web.{OStatus, Websub, OAuth}
|
alias Pleroma.Web.{OStatus, Websub, OAuth}
|
||||||
alias Pleroma.Web.ActivityPub.{Utils, ActivityPub}
|
alias Pleroma.Web.ActivityPub.{Utils, ActivityPub}
|
||||||
|
|
||||||
|
@type t :: %__MODULE__{}
|
||||||
|
|
||||||
schema "users" do
|
schema "users" do
|
||||||
field(:bio, :string)
|
field(:bio, :string)
|
||||||
field(:email, :string)
|
field(:email, :string)
|
||||||
|
@ -218,7 +219,7 @@ def maybe_direct_follow(%User{} = follower, %User{} = followed) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def maybe_follow(%User{} = follower, %User{info: info} = followed) do
|
def maybe_follow(%User{} = follower, %User{info: _info} = followed) do
|
||||||
if not following?(follower, followed) do
|
if not following?(follower, followed) do
|
||||||
follow(follower, followed)
|
follow(follower, followed)
|
||||||
else
|
else
|
||||||
|
@ -280,6 +281,7 @@ def unfollow(%User{} = follower, %User{} = followed) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@spec following?(User.t(), User.t()) :: boolean
|
||||||
def following?(%User{} = follower, %User{} = followed) do
|
def following?(%User{} = follower, %User{} = followed) do
|
||||||
Enum.member?(follower.following, followed.follower_address)
|
Enum.member?(follower.following, followed.follower_address)
|
||||||
end
|
end
|
||||||
|
@ -824,20 +826,21 @@ def tag(user_identifiers, tags) when is_list(user_identifiers) do
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def tag(nickname, tags) when is_binary(nickname),
|
||||||
|
do: tag(User.get_by_nickname(nickname), tags)
|
||||||
|
|
||||||
|
def tag(%User{} = user, tags),
|
||||||
|
do: update_tags(user, Enum.uniq(user.tags ++ normalize_tags(tags)))
|
||||||
|
|
||||||
def untag(user_identifiers, tags) when is_list(user_identifiers) do
|
def untag(user_identifiers, tags) when is_list(user_identifiers) do
|
||||||
Repo.transaction(fn ->
|
Repo.transaction(fn ->
|
||||||
for user_identifier <- user_identifiers, do: untag(user_identifier, tags)
|
for user_identifier <- user_identifiers, do: untag(user_identifier, tags)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
def tag(nickname, tags) when is_binary(nickname), do: tag(User.get_by_nickname(nickname), tags)
|
|
||||||
|
|
||||||
def untag(nickname, tags) when is_binary(nickname),
|
def untag(nickname, tags) when is_binary(nickname),
|
||||||
do: untag(User.get_by_nickname(nickname), tags)
|
do: untag(User.get_by_nickname(nickname), tags)
|
||||||
|
|
||||||
def tag(%User{} = user, tags),
|
|
||||||
do: update_tags(user, Enum.uniq(user.tags ++ normalize_tags(tags)))
|
|
||||||
|
|
||||||
def untag(%User{} = user, tags), do: update_tags(user, user.tags -- normalize_tags(tags))
|
def untag(%User{} = user, tags), do: update_tags(user, user.tags -- normalize_tags(tags))
|
||||||
|
|
||||||
defp update_tags(%User{} = user, new_tags) do
|
defp update_tags(%User{} = user, new_tags) do
|
||||||
|
|
|
@ -3,7 +3,8 @@ defmodule Pleroma.UserInviteToken do
|
||||||
|
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
|
|
||||||
alias Pleroma.{User, UserInviteToken, Repo}
|
alias Pleroma.UserInviteToken
|
||||||
|
alias Pleroma.Repo
|
||||||
|
|
||||||
schema "user_invite_tokens" do
|
schema "user_invite_tokens" do
|
||||||
field(:token, :string)
|
field(:token, :string)
|
||||||
|
|
|
@ -799,7 +799,7 @@ def visible_for_user?(activity, user) do
|
||||||
end
|
end
|
||||||
|
|
||||||
# guard
|
# guard
|
||||||
def entire_thread_visible_for_user?(nil, user), do: false
|
def entire_thread_visible_for_user?(nil, _user), do: false
|
||||||
|
|
||||||
# child
|
# child
|
||||||
def entire_thread_visible_for_user?(
|
def entire_thread_visible_for_user?(
|
||||||
|
|
|
@ -141,7 +141,7 @@ def inbox(conn, params) do
|
||||||
json(conn, "error")
|
json(conn, "error")
|
||||||
end
|
end
|
||||||
|
|
||||||
def relay(conn, params) do
|
def relay(conn, _params) do
|
||||||
with %User{} = user <- Relay.get_actor(),
|
with %User{} = user <- Relay.get_actor(),
|
||||||
{:ok, user} <- Pleroma.Web.WebFinger.ensure_keys_present(user) do
|
{:ok, user} <- Pleroma.Web.WebFinger.ensure_keys_present(user) do
|
||||||
conn
|
conn
|
||||||
|
|
|
@ -5,7 +5,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.EnsureRePrepended do
|
||||||
|
|
||||||
@reply_prefix Regex.compile!("^re:[[:space:]]*", [:caseless])
|
@reply_prefix Regex.compile!("^re:[[:space:]]*", [:caseless])
|
||||||
def filter_by_summary(
|
def filter_by_summary(
|
||||||
%{"summary" => parent_summary} = parent,
|
%{"summary" => parent_summary} = _parent,
|
||||||
%{"summary" => child_summary} = child
|
%{"summary" => child_summary} = child
|
||||||
)
|
)
|
||||||
when not is_nil(child_summary) and byte_size(child_summary) > 0 and
|
when not is_nil(child_summary) and byte_size(child_summary) > 0 and
|
||||||
|
@ -19,7 +19,7 @@ def filter_by_summary(
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def filter_by_summary(parent, child), do: child
|
def filter_by_summary(_parent, child), do: child
|
||||||
|
|
||||||
def filter(%{"type" => activity_type} = object) when activity_type == "Create" do
|
def filter(%{"type" => activity_type} = object) when activity_type == "Create" do
|
||||||
child = object["object"]
|
child = object["object"]
|
||||||
|
|
|
@ -37,9 +37,9 @@ def get_actor(%{"actor" => nil, "attributedTo" => actor}) when not is_nil(actor)
|
||||||
@doc """
|
@doc """
|
||||||
Checks that an imported AP object's actor matches the domain it came from.
|
Checks that an imported AP object's actor matches the domain it came from.
|
||||||
"""
|
"""
|
||||||
def contain_origin(id, %{"actor" => nil}), do: :error
|
def contain_origin(_id, %{"actor" => nil}), do: :error
|
||||||
|
|
||||||
def contain_origin(id, %{"actor" => actor} = params) do
|
def contain_origin(id, %{"actor" => _actor} = params) do
|
||||||
id_uri = URI.parse(id)
|
id_uri = URI.parse(id)
|
||||||
actor_uri = URI.parse(get_actor(params))
|
actor_uri = URI.parse(get_actor(params))
|
||||||
|
|
||||||
|
@ -50,9 +50,9 @@ def contain_origin(id, %{"actor" => actor} = params) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def contain_origin_from_id(id, %{"id" => nil}), do: :error
|
def contain_origin_from_id(_id, %{"id" => nil}), do: :error
|
||||||
|
|
||||||
def contain_origin_from_id(id, %{"id" => other_id} = params) do
|
def contain_origin_from_id(id, %{"id" => other_id} = _params) do
|
||||||
id_uri = URI.parse(id)
|
id_uri = URI.parse(id)
|
||||||
other_uri = URI.parse(other_id)
|
other_uri = URI.parse(other_id)
|
||||||
|
|
||||||
|
@ -266,6 +266,32 @@ def fix_content_map(%{"contentMap" => content_map} = object) do
|
||||||
|
|
||||||
def fix_content_map(object), do: object
|
def fix_content_map(object), do: object
|
||||||
|
|
||||||
|
defp mastodon_follow_hack(%{"id" => id, "actor" => follower_id}, followed) do
|
||||||
|
with true <- id =~ "follows",
|
||||||
|
%User{local: true} = follower <- User.get_cached_by_ap_id(follower_id),
|
||||||
|
%Activity{} = activity <- Utils.fetch_latest_follow(follower, followed) do
|
||||||
|
{:ok, activity}
|
||||||
|
else
|
||||||
|
_ -> {:error, nil}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp mastodon_follow_hack(_, _), do: {:error, nil}
|
||||||
|
|
||||||
|
defp get_follow_activity(follow_object, followed) do
|
||||||
|
with object_id when not is_nil(object_id) <- Utils.get_ap_id(follow_object),
|
||||||
|
{_, %Activity{} = activity} <- {:activity, Activity.get_by_ap_id(object_id)} do
|
||||||
|
{:ok, activity}
|
||||||
|
else
|
||||||
|
# Can't find the activity. This might a Mastodon 2.3 "Accept"
|
||||||
|
{:activity, nil} ->
|
||||||
|
mastodon_follow_hack(follow_object, followed)
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
{:error, nil}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# disallow objects with bogus IDs
|
# disallow objects with bogus IDs
|
||||||
def handle_incoming(%{"id" => nil}), do: :error
|
def handle_incoming(%{"id" => nil}), do: :error
|
||||||
def handle_incoming(%{"id" => ""}), do: :error
|
def handle_incoming(%{"id" => ""}), do: :error
|
||||||
|
@ -331,34 +357,8 @@ def handle_incoming(
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp mastodon_follow_hack(%{"id" => id, "actor" => follower_id}, followed) do
|
|
||||||
with true <- id =~ "follows",
|
|
||||||
%User{local: true} = follower <- User.get_cached_by_ap_id(follower_id),
|
|
||||||
%Activity{} = activity <- Utils.fetch_latest_follow(follower, followed) do
|
|
||||||
{:ok, activity}
|
|
||||||
else
|
|
||||||
_ -> {:error, nil}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
defp mastodon_follow_hack(_), do: {:error, nil}
|
|
||||||
|
|
||||||
defp get_follow_activity(follow_object, followed) do
|
|
||||||
with object_id when not is_nil(object_id) <- Utils.get_ap_id(follow_object),
|
|
||||||
{_, %Activity{} = activity} <- {:activity, Activity.get_by_ap_id(object_id)} do
|
|
||||||
{:ok, activity}
|
|
||||||
else
|
|
||||||
# Can't find the activity. This might a Mastodon 2.3 "Accept"
|
|
||||||
{:activity, nil} ->
|
|
||||||
mastodon_follow_hack(follow_object, followed)
|
|
||||||
|
|
||||||
_ ->
|
|
||||||
{:error, nil}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def handle_incoming(
|
def handle_incoming(
|
||||||
%{"type" => "Accept", "object" => follow_object, "actor" => actor, "id" => id} = data
|
%{"type" => "Accept", "object" => follow_object, "actor" => _actor, "id" => _id} = data
|
||||||
) do
|
) do
|
||||||
with actor <- get_actor(data),
|
with actor <- get_actor(data),
|
||||||
%User{} = followed <- User.get_or_fetch_by_ap_id(actor),
|
%User{} = followed <- User.get_or_fetch_by_ap_id(actor),
|
||||||
|
@ -374,7 +374,7 @@ def handle_incoming(
|
||||||
local: false
|
local: false
|
||||||
}) do
|
}) do
|
||||||
if not User.following?(follower, followed) do
|
if not User.following?(follower, followed) do
|
||||||
{:ok, follower} = User.follow(follower, followed)
|
{:ok, _follower} = User.follow(follower, followed)
|
||||||
end
|
end
|
||||||
|
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
|
@ -384,7 +384,7 @@ def handle_incoming(
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_incoming(
|
def handle_incoming(
|
||||||
%{"type" => "Reject", "object" => follow_object, "actor" => actor, "id" => id} = data
|
%{"type" => "Reject", "object" => follow_object, "actor" => _actor, "id" => _id} = data
|
||||||
) do
|
) do
|
||||||
with actor <- get_actor(data),
|
with actor <- get_actor(data),
|
||||||
%User{} = followed <- User.get_or_fetch_by_ap_id(actor),
|
%User{} = followed <- User.get_or_fetch_by_ap_id(actor),
|
||||||
|
@ -408,7 +408,7 @@ def handle_incoming(
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_incoming(
|
def handle_incoming(
|
||||||
%{"type" => "Like", "object" => object_id, "actor" => actor, "id" => id} = data
|
%{"type" => "Like", "object" => object_id, "actor" => _actor, "id" => id} = data
|
||||||
) do
|
) do
|
||||||
with actor <- get_actor(data),
|
with actor <- get_actor(data),
|
||||||
%User{} = actor <- User.get_or_fetch_by_ap_id(actor),
|
%User{} = actor <- User.get_or_fetch_by_ap_id(actor),
|
||||||
|
@ -421,7 +421,7 @@ def handle_incoming(
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_incoming(
|
def handle_incoming(
|
||||||
%{"type" => "Announce", "object" => object_id, "actor" => actor, "id" => id} = data
|
%{"type" => "Announce", "object" => object_id, "actor" => _actor, "id" => id} = data
|
||||||
) do
|
) do
|
||||||
with actor <- get_actor(data),
|
with actor <- get_actor(data),
|
||||||
%User{} = actor <- User.get_or_fetch_by_ap_id(actor),
|
%User{} = actor <- User.get_or_fetch_by_ap_id(actor),
|
||||||
|
@ -492,7 +492,7 @@ def handle_incoming(
|
||||||
%{
|
%{
|
||||||
"type" => "Undo",
|
"type" => "Undo",
|
||||||
"object" => %{"type" => "Announce", "object" => object_id},
|
"object" => %{"type" => "Announce", "object" => object_id},
|
||||||
"actor" => actor,
|
"actor" => _actor,
|
||||||
"id" => id
|
"id" => id
|
||||||
} = data
|
} = data
|
||||||
) do
|
) do
|
||||||
|
@ -520,7 +520,7 @@ def handle_incoming(
|
||||||
User.unfollow(follower, followed)
|
User.unfollow(follower, followed)
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
else
|
else
|
||||||
e -> :error
|
_e -> :error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -539,12 +539,12 @@ def handle_incoming(
|
||||||
User.unblock(blocker, blocked)
|
User.unblock(blocker, blocked)
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
else
|
else
|
||||||
e -> :error
|
_e -> :error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_incoming(
|
def handle_incoming(
|
||||||
%{"type" => "Block", "object" => blocked, "actor" => blocker, "id" => id} = data
|
%{"type" => "Block", "object" => blocked, "actor" => blocker, "id" => id} = _data
|
||||||
) do
|
) do
|
||||||
with true <- Pleroma.Config.get([:activitypub, :accept_blocks]),
|
with true <- Pleroma.Config.get([:activitypub, :accept_blocks]),
|
||||||
%User{local: true} = blocked = User.get_cached_by_ap_id(blocked),
|
%User{local: true} = blocked = User.get_cached_by_ap_id(blocked),
|
||||||
|
@ -554,7 +554,7 @@ def handle_incoming(
|
||||||
User.block(blocker, blocked)
|
User.block(blocker, blocked)
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
else
|
else
|
||||||
e -> :error
|
_e -> :error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -562,7 +562,7 @@ def handle_incoming(
|
||||||
%{
|
%{
|
||||||
"type" => "Undo",
|
"type" => "Undo",
|
||||||
"object" => %{"type" => "Like", "object" => object_id},
|
"object" => %{"type" => "Like", "object" => object_id},
|
||||||
"actor" => actor,
|
"actor" => _actor,
|
||||||
"id" => id
|
"id" => id
|
||||||
} = data
|
} = data
|
||||||
) do
|
) do
|
||||||
|
|
|
@ -292,7 +292,7 @@ def update_follow_state(%Activity{} = activity, state) do
|
||||||
"""
|
"""
|
||||||
def make_follow_data(
|
def make_follow_data(
|
||||||
%User{ap_id: follower_id},
|
%User{ap_id: follower_id},
|
||||||
%User{ap_id: followed_id} = followed,
|
%User{ap_id: followed_id} = _followed,
|
||||||
activity_id
|
activity_id
|
||||||
) do
|
) do
|
||||||
data = %{
|
data = %{
|
||||||
|
|
|
@ -63,13 +63,19 @@ def right_add(conn, %{"permission_group" => permission_group, "nickname" => nick
|
||||||
info_cng = User.Info.admin_api_update(user.info, info)
|
info_cng = User.Info.admin_api_update(user.info, info)
|
||||||
|
|
||||||
cng =
|
cng =
|
||||||
Ecto.Changeset.change(user)
|
user
|
||||||
|
|> Ecto.Changeset.change()
|
||||||
|> Ecto.Changeset.put_embed(:info, info_cng)
|
|> Ecto.Changeset.put_embed(:info, info_cng)
|
||||||
|
|
||||||
{:ok, user} = User.update_and_set_cache(cng)
|
{:ok, _user} = User.update_and_set_cache(cng)
|
||||||
|
|
||||||
|
json(conn, info)
|
||||||
|
end
|
||||||
|
|
||||||
|
def right_add(conn, _) do
|
||||||
conn
|
conn
|
||||||
|> json(info)
|
|> put_status(404)
|
||||||
|
|> json(%{error: "No such permission_group"})
|
||||||
end
|
end
|
||||||
|
|
||||||
def right_get(conn, %{"nickname" => nickname}) do
|
def right_get(conn, %{"nickname" => nickname}) do
|
||||||
|
@ -82,12 +88,6 @@ def right_get(conn, %{"nickname" => nickname}) do
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
def right_add(conn, _) do
|
|
||||||
conn
|
|
||||||
|> put_status(404)
|
|
||||||
|> json(%{error: "No such permission_group"})
|
|
||||||
end
|
|
||||||
|
|
||||||
def right_delete(
|
def right_delete(
|
||||||
%{assigns: %{user: %User{:nickname => admin_nickname}}} = conn,
|
%{assigns: %{user: %User{:nickname => admin_nickname}}} = conn,
|
||||||
%{
|
%{
|
||||||
|
@ -113,10 +113,9 @@ def right_delete(
|
||||||
Ecto.Changeset.change(user)
|
Ecto.Changeset.change(user)
|
||||||
|> Ecto.Changeset.put_embed(:info, info_cng)
|
|> Ecto.Changeset.put_embed(:info, info_cng)
|
||||||
|
|
||||||
{:ok, user} = User.update_and_set_cache(cng)
|
{:ok, _user} = User.update_and_set_cache(cng)
|
||||||
|
|
||||||
conn
|
json(conn, info)
|
||||||
|> json(info)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -127,12 +126,10 @@ def right_delete(conn, _) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def relay_follow(conn, %{"relay_url" => target}) do
|
def relay_follow(conn, %{"relay_url" => target}) do
|
||||||
{status, message} = Relay.follow(target)
|
with {:ok, _message} <- Relay.follow(target) do
|
||||||
|
json(conn, target)
|
||||||
if status == :ok do
|
|
||||||
conn
|
|
||||||
|> json(target)
|
|
||||||
else
|
else
|
||||||
|
_ ->
|
||||||
conn
|
conn
|
||||||
|> put_status(500)
|
|> put_status(500)
|
||||||
|> json(target)
|
|> json(target)
|
||||||
|
@ -140,19 +137,17 @@ def relay_follow(conn, %{"relay_url" => target}) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def relay_unfollow(conn, %{"relay_url" => target}) do
|
def relay_unfollow(conn, %{"relay_url" => target}) do
|
||||||
{status, message} = Relay.unfollow(target)
|
with {:ok, _message} <- Relay.unfollow(target) do
|
||||||
|
json(conn, target)
|
||||||
if status == :ok do
|
|
||||||
conn
|
|
||||||
|> json(target)
|
|
||||||
else
|
else
|
||||||
|
_ ->
|
||||||
conn
|
conn
|
||||||
|> put_status(500)
|
|> put_status(500)
|
||||||
|> json(target)
|
|> json(target)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@shortdoc "Get a account registeration invite token (base64 string)"
|
@doc "Get a account registeration invite token (base64 string)"
|
||||||
def get_invite_token(conn, _params) do
|
def get_invite_token(conn, _params) do
|
||||||
{:ok, token} = Pleroma.UserInviteToken.create_token()
|
{:ok, token} = Pleroma.UserInviteToken.create_token()
|
||||||
|
|
||||||
|
@ -160,7 +155,7 @@ def get_invite_token(conn, _params) do
|
||||||
|> json(token.token)
|
|> json(token.token)
|
||||||
end
|
end
|
||||||
|
|
||||||
@shortdoc "Get a password reset token (base64 string) for given nickname"
|
@doc "Get a password reset token (base64 string) for given nickname"
|
||||||
def get_password_reset(conn, %{"nickname" => nickname}) do
|
def get_password_reset(conn, %{"nickname" => nickname}) do
|
||||||
(%User{local: true} = user) = User.get_by_nickname(nickname)
|
(%User{local: true} = user) = User.get_by_nickname(nickname)
|
||||||
{:ok, token} = Pleroma.PasswordResetToken.create_token(user)
|
{:ok, token} = Pleroma.PasswordResetToken.create_token(user)
|
||||||
|
|
|
@ -122,7 +122,7 @@ def format_input(text, mentions, tags, "text/plain") do
|
||||||
|> Formatter.finalize()
|
|> Formatter.finalize()
|
||||||
end
|
end
|
||||||
|
|
||||||
def format_input(text, mentions, tags, "text/html") do
|
def format_input(text, mentions, _tags, "text/html") do
|
||||||
text
|
text
|
||||||
|> Formatter.html_escape("text/html")
|
|> Formatter.html_escape("text/html")
|
||||||
|> String.replace(~r/\r?\n/, "<br>")
|
|> String.replace(~r/\r?\n/, "<br>")
|
||||||
|
@ -236,7 +236,7 @@ def confirm_current_password(user, password) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def emoji_from_profile(%{info: info} = user) do
|
def emoji_from_profile(%{info: _info} = user) do
|
||||||
(Formatter.get_emoji(user.bio) ++ Formatter.get_emoji(user.name))
|
(Formatter.get_emoji(user.bio) ++ Formatter.get_emoji(user.name))
|
||||||
|> Enum.map(fn {shortcode, url} ->
|
|> Enum.map(fn {shortcode, url} ->
|
||||||
%{
|
%{
|
||||||
|
|
|
@ -13,7 +13,6 @@ defmodule Pleroma.Web.Federator do
|
||||||
|
|
||||||
@websub Application.get_env(:pleroma, :websub)
|
@websub Application.get_env(:pleroma, :websub)
|
||||||
@ostatus Application.get_env(:pleroma, :ostatus)
|
@ostatus Application.get_env(:pleroma, :ostatus)
|
||||||
@httpoison Application.get_env(:pleroma, :httpoison)
|
|
||||||
@max_jobs 20
|
@max_jobs 20
|
||||||
|
|
||||||
def init(args) do
|
def init(args) do
|
||||||
|
@ -134,7 +133,7 @@ def handle(:publish_single_ap, params) do
|
||||||
|
|
||||||
def handle(
|
def handle(
|
||||||
:publish_single_websub,
|
:publish_single_websub,
|
||||||
%{xml: xml, topic: topic, callback: callback, secret: secret} = params
|
%{xml: _xml, topic: _topic, callback: _callback, secret: _secret} = params
|
||||||
) do
|
) do
|
||||||
case Websub.publish_one(params) do
|
case Websub.publish_one(params) do
|
||||||
{:ok, _} ->
|
{:ok, _} ->
|
||||||
|
@ -151,7 +150,7 @@ def handle(type, _) do
|
||||||
end
|
end
|
||||||
|
|
||||||
if Mix.env() == :test do
|
if Mix.env() == :test do
|
||||||
def enqueue(type, payload, priority \\ 1) do
|
def enqueue(type, payload, _priority \\ 1) do
|
||||||
if Pleroma.Config.get([:instance, :federating]) do
|
if Pleroma.Config.get([:instance, :federating]) do
|
||||||
handle(type, payload)
|
handle(type, payload)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,13 +1,8 @@
|
||||||
defmodule Pleroma.Web.Federator.RetryQueue do
|
defmodule Pleroma.Web.Federator.RetryQueue do
|
||||||
use GenServer
|
use GenServer
|
||||||
alias Pleroma.Web.{WebFinger, Websub}
|
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
@websub Application.get_env(:pleroma, :websub)
|
|
||||||
@ostatus Application.get_env(:pleroma, :websub)
|
|
||||||
@httpoison Application.get_env(:pleroma, :websub)
|
|
||||||
@instance Application.get_env(:pleroma, :websub)
|
|
||||||
# initial timeout, 5 min
|
# initial timeout, 5 min
|
||||||
@initial_timeout 30_000
|
@initial_timeout 30_000
|
||||||
@max_retries 5
|
@max_retries 5
|
||||||
|
@ -46,7 +41,7 @@ def handle_cast({:maybe_enqueue, data, transport, retries}, %{dropped: drop_coun
|
||||||
Process.send_after(
|
Process.send_after(
|
||||||
__MODULE__,
|
__MODULE__,
|
||||||
{:send, data, transport, retries},
|
{:send, data, transport, retries},
|
||||||
growth_function(retries)
|
timeout
|
||||||
)
|
)
|
||||||
|
|
||||||
{:noreply, state}
|
{:noreply, state}
|
||||||
|
@ -62,7 +57,7 @@ def handle_info({:send, data, transport, retries}, %{delivered: delivery_count}
|
||||||
{:ok, _} ->
|
{:ok, _} ->
|
||||||
{:noreply, %{state | delivered: delivery_count + 1}}
|
{:noreply, %{state | delivered: delivery_count + 1}}
|
||||||
|
|
||||||
{:error, reason} ->
|
{:error, _reason} ->
|
||||||
enqueue(data, transport, retries)
|
enqueue(data, transport, retries)
|
||||||
{:noreply, state}
|
{:noreply, state}
|
||||||
end
|
end
|
||||||
|
|
|
@ -437,10 +437,7 @@ def relationships(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
||||||
end
|
end
|
||||||
|
|
||||||
# Instead of returning a 400 when no "id" params is present, Mastodon returns an empty array.
|
# Instead of returning a 400 when no "id" params is present, Mastodon returns an empty array.
|
||||||
def relationships(%{assigns: %{user: user}} = conn, _) do
|
def relationships(%{assigns: %{user: _user}} = conn, _), do: json(conn, [])
|
||||||
conn
|
|
||||||
|> json([])
|
|
||||||
end
|
|
||||||
|
|
||||||
def update_media(%{assigns: %{user: user}} = conn, data) do
|
def update_media(%{assigns: %{user: user}} = conn, data) do
|
||||||
with %Object{} = object <- Repo.get(Object, data["id"]),
|
with %Object{} = object <- Repo.get(Object, data["id"]),
|
||||||
|
@ -850,7 +847,7 @@ def rename_list(%{assigns: %{user: user}} = conn, %{"id" => id, "title" => title
|
||||||
end
|
end
|
||||||
|
|
||||||
def list_timeline(%{assigns: %{user: user}} = conn, %{"list_id" => id} = params) do
|
def list_timeline(%{assigns: %{user: user}} = conn, %{"list_id" => id} = params) do
|
||||||
with %Pleroma.List{title: title, following: following} <- Pleroma.List.get(id, user) do
|
with %Pleroma.List{title: _title, following: following} <- Pleroma.List.get(id, user) do
|
||||||
params =
|
params =
|
||||||
params
|
params
|
||||||
|> Map.put("type", "Create")
|
|> Map.put("type", "Create")
|
||||||
|
@ -983,13 +980,11 @@ def put_settings(%{assigns: %{user: user}} = conn, %{"data" => settings} = _para
|
||||||
|
|
||||||
with changeset <- User.update_changeset(user),
|
with changeset <- User.update_changeset(user),
|
||||||
changeset <- Ecto.Changeset.put_embed(changeset, :info, info_cng),
|
changeset <- Ecto.Changeset.put_embed(changeset, :info, info_cng),
|
||||||
{:ok, user} <- User.update_and_set_cache(changeset) do
|
{:ok, _user} <- User.update_and_set_cache(changeset) do
|
||||||
conn
|
json(conn, %{})
|
||||||
|> json(%{})
|
|
||||||
else
|
else
|
||||||
e ->
|
e ->
|
||||||
conn
|
json(conn, %{error: inspect(e)})
|
||||||
|> json(%{error: inspect(e)})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -5,12 +5,13 @@ defmodule Pleroma.Web.MastodonAPI.MastodonSocket do
|
||||||
alias Pleroma.{User, Repo}
|
alias Pleroma.{User, Repo}
|
||||||
|
|
||||||
transport(
|
transport(
|
||||||
:streaming,
|
:websocket,
|
||||||
Phoenix.Transports.WebSocket.Raw,
|
Phoenix.Transports.WebSocket.Raw,
|
||||||
# We never receive data.
|
# We never receive data.
|
||||||
timeout: :infinity
|
timeout: :infinity
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@spec connect(params :: map(), Phoenix.Socket.t()) :: {:ok, Phoenix.Socket.t()} | :error
|
||||||
def connect(%{"access_token" => token} = params, socket) do
|
def connect(%{"access_token" => token} = params, socket) do
|
||||||
with %Token{user_id: user_id} <- Repo.get_by(Token, token: token),
|
with %Token{user_id: user_id} <- Repo.get_by(Token, token: token),
|
||||||
%User{} = user <- Repo.get(User, user_id),
|
%User{} = user <- Repo.get(User, user_id),
|
||||||
|
@ -52,16 +53,16 @@ def connect(%{"stream" => stream} = params, socket)
|
||||||
_ -> stream
|
_ -> stream
|
||||||
end
|
end
|
||||||
|
|
||||||
with socket =
|
socket =
|
||||||
socket
|
socket
|
||||||
|> assign(:topic, topic) do
|
|> assign(:topic, topic)
|
||||||
|
|
||||||
Pleroma.Web.Streamer.add_socket(topic, socket)
|
Pleroma.Web.Streamer.add_socket(topic, socket)
|
||||||
{:ok, socket}
|
{:ok, socket}
|
||||||
else
|
|
||||||
_e -> :error
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def connect(_params, _socket), do: :error
|
||||||
|
|
||||||
def id(_), do: nil
|
def id(_), do: nil
|
||||||
|
|
||||||
def handle(:text, message, _state) do
|
def handle(:text, message, _state) do
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
defmodule Pleroma.Web.MastodonAPI.MastodonView do
|
defmodule Pleroma.Web.MastodonAPI.MastodonView do
|
||||||
use Pleroma.Web, :view
|
use Pleroma.Web, :view
|
||||||
import Phoenix.HTML
|
import Phoenix.HTML
|
||||||
import Phoenix.HTML.Form
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
defmodule Pleroma.Web.MastodonAPI.PushSubscriptionView do
|
defmodule Pleroma.Web.MastodonAPI.PushSubscriptionView do
|
||||||
use Pleroma.Web, :view
|
use Pleroma.Web, :view
|
||||||
alias Pleroma.Web.MastodonAPI.PushSubscriptionView
|
|
||||||
|
|
||||||
def render("push_subscription.json", %{subscription: subscription}) do
|
def render("push_subscription.json", %{subscription: subscription}) do
|
||||||
%{
|
%{
|
||||||
|
|
|
@ -8,7 +8,6 @@ def remote(conn, params = %{"sig" => sig64, "url" => url64}) do
|
||||||
with config <- Pleroma.Config.get([:media_proxy], []),
|
with config <- Pleroma.Config.get([:media_proxy], []),
|
||||||
true <- Keyword.get(config, :enabled, false),
|
true <- Keyword.get(config, :enabled, false),
|
||||||
{:ok, url} <- MediaProxy.decode_url(sig64, url64),
|
{:ok, url} <- MediaProxy.decode_url(sig64, url64),
|
||||||
filename <- Path.basename(URI.parse(url).path),
|
|
||||||
:ok <- filename_matches(Map.has_key?(params, "filename"), conn.request_path, url) do
|
:ok <- filename_matches(Map.has_key?(params, "filename"), conn.request_path, url) do
|
||||||
ReverseProxy.call(conn, url, Keyword.get(config, :proxy_opts, @default_proxy_opts))
|
ReverseProxy.call(conn, url, Keyword.get(config, :proxy_opts, @default_proxy_opts))
|
||||||
else
|
else
|
||||||
|
@ -31,9 +30,10 @@ def filename_matches(has_filename, path, url) do
|
||||||
|
|
||||||
path = URI.decode(path)
|
path = URI.decode(path)
|
||||||
|
|
||||||
cond do
|
if has_filename && filename && Path.basename(path) != filename do
|
||||||
has_filename && filename && Path.basename(path) != filename -> {:wrong_filename, filename}
|
{:wrong_filename, filename}
|
||||||
true -> :ok
|
else
|
||||||
|
:ok
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -121,7 +121,7 @@ def token_exchange(
|
||||||
|
|
||||||
def token_exchange(
|
def token_exchange(
|
||||||
conn,
|
conn,
|
||||||
%{"grant_type" => "password", "name" => name, "password" => password} = params
|
%{"grant_type" => "password", "name" => name, "password" => _password} = params
|
||||||
) do
|
) do
|
||||||
params =
|
params =
|
||||||
params
|
params
|
||||||
|
|
|
@ -375,14 +375,10 @@ def fetch_activity_from_html_url(url) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_activity_from_url(url) do
|
def fetch_activity_from_url(url) do
|
||||||
try do
|
with {:ok, [_ | _] = activities} <- fetch_activity_from_atom_url(url) do
|
||||||
with {:ok, activities} when length(activities) > 0 <- fetch_activity_from_atom_url(url) do
|
|
||||||
{:ok, activities}
|
{:ok, activities}
|
||||||
else
|
else
|
||||||
_e ->
|
_e -> fetch_activity_from_html_url(url)
|
||||||
with {:ok, activities} <- fetch_activity_from_html_url(url) do
|
|
||||||
{:ok, activities}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
rescue
|
rescue
|
||||||
e ->
|
e ->
|
||||||
|
@ -390,4 +386,3 @@ def fetch_activity_from_url(url) do
|
||||||
{:error, "Couldn't get #{url}: #{inspect(e)}"}
|
{:error, "Couldn't get #{url}: #{inspect(e)}"}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
|
@ -157,7 +157,7 @@ defp represent_activity(
|
||||||
conn,
|
conn,
|
||||||
"activity+json",
|
"activity+json",
|
||||||
%Activity{data: %{"type" => "Create"}} = activity,
|
%Activity{data: %{"type" => "Create"}} = activity,
|
||||||
user
|
_user
|
||||||
) do
|
) do
|
||||||
object = Object.normalize(activity.data["object"])
|
object = Object.normalize(activity.data["object"])
|
||||||
|
|
||||||
|
@ -166,7 +166,7 @@ defp represent_activity(
|
||||||
|> json(ObjectView.render("object.json", %{object: object}))
|
|> json(ObjectView.render("object.json", %{object: object}))
|
||||||
end
|
end
|
||||||
|
|
||||||
defp represent_activity(conn, "activity+json", _, _) do
|
defp represent_activity(_conn, "activity+json", _, _) do
|
||||||
{:error, :not_found}
|
{:error, :not_found}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
defmodule Pleroma.Web.Router do
|
defmodule Pleroma.Web.Router do
|
||||||
use Pleroma.Web, :router
|
use Pleroma.Web, :router
|
||||||
|
|
||||||
alias Pleroma.{Repo, User, Web.Router}
|
|
||||||
|
|
||||||
pipeline :api do
|
pipeline :api do
|
||||||
plug(:accepts, ["json"])
|
plug(:accepts, ["json"])
|
||||||
plug(:fetch_session)
|
plug(:fetch_session)
|
||||||
|
|
|
@ -61,8 +61,6 @@ def handle_cast(%{action: :stream, topic: "direct", item: item}, topics) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_cast(%{action: :stream, topic: "list", item: item}, topics) do
|
def handle_cast(%{action: :stream, topic: "list", item: item}, topics) do
|
||||||
author = User.get_cached_by_ap_id(item.data["actor"])
|
|
||||||
|
|
||||||
# filter the recipient list if the activity is not public, see #270.
|
# filter the recipient list if the activity is not public, see #270.
|
||||||
recipient_lists =
|
recipient_lists =
|
||||||
case ActivityPub.is_public?(item) do
|
case ActivityPub.is_public?(item) do
|
||||||
|
|
|
@ -6,9 +6,8 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
|
||||||
alias Pleroma.Web.WebFinger
|
alias Pleroma.Web.WebFinger
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
alias Comeonin.Pbkdf2
|
alias Comeonin.Pbkdf2
|
||||||
alias Pleroma.{Formatter, Emoji}
|
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
alias Pleroma.{Repo, PasswordResetToken, User}
|
alias Pleroma.{Repo, PasswordResetToken, User, Emoji}
|
||||||
|
|
||||||
def show_password_reset(conn, %{"token" => token}) do
|
def show_password_reset(conn, %{"token" => token}) do
|
||||||
with %{used: false} = token <- Repo.get_by(PasswordResetToken, %{token: token}),
|
with %{used: false} = token <- Repo.get_by(PasswordResetToken, %{token: token}),
|
||||||
|
|
|
@ -141,7 +141,7 @@ def to_map(
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_map(
|
def to_map(
|
||||||
%Activity{data: %{"object" => %{"content" => content} = object}} = activity,
|
%Activity{data: %{"object" => %{"content" => _content} = object}} = activity,
|
||||||
%{user: user} = opts
|
%{user: user} = opts
|
||||||
) do
|
) do
|
||||||
created_at = object["published"] |> Utils.date_to_asctime()
|
created_at = object["published"] |> Utils.date_to_asctime()
|
||||||
|
@ -165,7 +165,7 @@ def to_map(
|
||||||
|
|
||||||
tags = if possibly_sensitive, do: Enum.uniq(["nsfw" | tags]), else: tags
|
tags = if possibly_sensitive, do: Enum.uniq(["nsfw" | tags]), else: tags
|
||||||
|
|
||||||
{summary, content} = ActivityView.render_content(object)
|
{_summary, content} = ActivityView.render_content(object)
|
||||||
|
|
||||||
html =
|
html =
|
||||||
HTML.filter_tags(content, User.html_filter_policy(opts[:for]))
|
HTML.filter_tags(content, User.html_filter_policy(opts[:for]))
|
||||||
|
@ -173,7 +173,7 @@ def to_map(
|
||||||
|
|
||||||
video =
|
video =
|
||||||
if object["type"] == "Video" do
|
if object["type"] == "Video" do
|
||||||
vid = [object]
|
[object]
|
||||||
else
|
else
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,18 +2,15 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
|
||||||
alias Pleroma.{UserInviteToken, User, Activity, Repo, Object}
|
alias Pleroma.{UserInviteToken, User, Activity, Repo, Object}
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
alias Pleroma.Web.TwitterAPI.UserView
|
alias Pleroma.Web.TwitterAPI.UserView
|
||||||
alias Pleroma.Web.{OStatus, CommonAPI}
|
alias Pleroma.Web.CommonAPI
|
||||||
alias Pleroma.Web.MediaProxy
|
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
@httpoison Application.get_env(:pleroma, :httpoison)
|
|
||||||
|
|
||||||
def create_status(%User{} = user, %{"status" => _} = data) do
|
def create_status(%User{} = user, %{"status" => _} = data) do
|
||||||
CommonAPI.post(user, data)
|
CommonAPI.post(user, data)
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete(%User{} = user, id) do
|
def delete(%User{} = user, id) do
|
||||||
with %Activity{data: %{"type" => type}} <- Repo.get(Activity, id),
|
with %Activity{data: %{"type" => _type}} <- Repo.get(Activity, id),
|
||||||
{:ok, activity} <- CommonAPI.delete(id, user) do
|
{:ok, activity} <- CommonAPI.delete(id, user) do
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
end
|
end
|
||||||
|
@ -37,7 +34,7 @@ def follow(%User{} = follower, params) do
|
||||||
|
|
||||||
def unfollow(%User{} = follower, params) do
|
def unfollow(%User{} = follower, params) do
|
||||||
with {:ok, %User{} = unfollowed} <- get_user(params),
|
with {:ok, %User{} = unfollowed} <- get_user(params),
|
||||||
{:ok, follower, follow_activity} <- User.unfollow(follower, unfollowed),
|
{:ok, follower, _follow_activity} <- User.unfollow(follower, unfollowed),
|
||||||
{:ok, _activity} <- ActivityPub.unfollow(follower, unfollowed) do
|
{:ok, _activity} <- ActivityPub.unfollow(follower, unfollowed) do
|
||||||
{:ok, follower, unfollowed}
|
{:ok, follower, unfollowed}
|
||||||
else
|
else
|
||||||
|
@ -244,10 +241,6 @@ def search(_user, %{"q" => query} = params) do
|
||||||
_activities = Repo.all(q)
|
_activities = Repo.all(q)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp make_date do
|
|
||||||
DateTime.utc_now() |> DateTime.to_iso8601()
|
|
||||||
end
|
|
||||||
|
|
||||||
# DEPRECATED mostly, context objects are now created at insertion time.
|
# DEPRECATED mostly, context objects are now created at insertion time.
|
||||||
def context_to_conversation_id(context) do
|
def context_to_conversation_id(context) do
|
||||||
with %Object{id: id} <- Object.get_cached_by_ap_id(context) do
|
with %Object{id: id} <- Object.get_cached_by_ap_id(context) do
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
defmodule Pleroma.Web.TwitterAPI.Controller do
|
defmodule Pleroma.Web.TwitterAPI.Controller do
|
||||||
use Pleroma.Web, :controller
|
use Pleroma.Web, :controller
|
||||||
alias Pleroma.Formatter
|
|
||||||
alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView, ActivityView, NotificationView}
|
alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView, ActivityView, NotificationView}
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
alias Pleroma.Web.CommonAPI.Utils, as: CommonUtils
|
|
||||||
alias Pleroma.{Repo, Activity, Object, User, Notification}
|
alias Pleroma.{Repo, Activity, Object, User, Notification}
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
alias Pleroma.Web.ActivityPub.Utils
|
alias Pleroma.Web.ActivityPub.Utils
|
||||||
|
@ -155,7 +153,7 @@ def notifications_read(%{assigns: %{user: user}} = conn, %{"latest_id" => latest
|
||||||
|> render(NotificationView, "notification.json", %{notifications: notifications, for: user})
|
|> render(NotificationView, "notification.json", %{notifications: notifications, for: user})
|
||||||
end
|
end
|
||||||
|
|
||||||
def notifications_read(%{assigns: %{user: user}} = conn, _) do
|
def notifications_read(%{assigns: %{user: _user}} = conn, _) do
|
||||||
bad_request_reply(conn, "You need to specify latest_id")
|
bad_request_reply(conn, "You need to specify latest_id")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -416,7 +414,7 @@ def friend_requests(conn, params) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def approve_friend_request(conn, %{"user_id" => uid} = params) do
|
def approve_friend_request(conn, %{"user_id" => uid} = _params) do
|
||||||
with followed <- conn.assigns[:user],
|
with followed <- conn.assigns[:user],
|
||||||
uid when is_number(uid) <- String.to_integer(uid),
|
uid when is_number(uid) <- String.to_integer(uid),
|
||||||
%User{} = follower <- Repo.get(User, uid),
|
%User{} = follower <- Repo.get(User, uid),
|
||||||
|
@ -436,7 +434,7 @@ def approve_friend_request(conn, %{"user_id" => uid} = params) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def deny_friend_request(conn, %{"user_id" => uid} = params) do
|
def deny_friend_request(conn, %{"user_id" => uid} = _params) do
|
||||||
with followed <- conn.assigns[:user],
|
with followed <- conn.assigns[:user],
|
||||||
uid when is_number(uid) <- String.to_integer(uid),
|
uid when is_number(uid) <- String.to_integer(uid),
|
||||||
%User{} = follower <- Repo.get(User, uid),
|
%User{} = follower <- Repo.get(User, uid),
|
||||||
|
|
|
@ -28,14 +28,14 @@ def parse_document(text) do
|
||||||
|> :xmerl_scan.string()
|
|> :xmerl_scan.string()
|
||||||
|
|
||||||
doc
|
doc
|
||||||
|
rescue
|
||||||
|
_e ->
|
||||||
|
Logger.debug("Couldn't parse XML: #{inspect(text)}")
|
||||||
|
:error
|
||||||
catch
|
catch
|
||||||
:exit, _error ->
|
:exit, _error ->
|
||||||
Logger.debug("Couldn't parse XML: #{inspect(text)}")
|
Logger.debug("Couldn't parse XML: #{inspect(text)}")
|
||||||
:error
|
:error
|
||||||
rescue
|
|
||||||
e ->
|
|
||||||
Logger.debug("Couldn't parse XML: #{inspect(text)}")
|
|
||||||
:error
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
6
mix.exs
6
mix.exs
|
@ -8,6 +8,12 @@ def project do
|
||||||
elixir: "~> 1.4",
|
elixir: "~> 1.4",
|
||||||
elixirc_paths: elixirc_paths(Mix.env()),
|
elixirc_paths: elixirc_paths(Mix.env()),
|
||||||
compilers: [:phoenix, :gettext] ++ Mix.compilers(),
|
compilers: [:phoenix, :gettext] ++ Mix.compilers(),
|
||||||
|
elixirc_options:
|
||||||
|
if Mix.env() == :test do
|
||||||
|
[]
|
||||||
|
else
|
||||||
|
[warnings_as_errors: true]
|
||||||
|
end,
|
||||||
start_permanent: Mix.env() == :prod,
|
start_permanent: Mix.env() == :prod,
|
||||||
aliases: aliases(),
|
aliases: aliases(),
|
||||||
deps: deps(),
|
deps: deps(),
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
defmodule Pleroma.Builders.ActivityBuilder do
|
defmodule Pleroma.Builders.ActivityBuilder do
|
||||||
alias Pleroma.Builders.UserBuilder
|
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
|
|
||||||
def build(data \\ %{}, opts \\ %{}) do
|
def build(data \\ %{}, opts \\ %{}) do
|
||||||
|
|
|
@ -13,7 +13,7 @@ def request(
|
||||||
with {:ok, res} <- apply(__MODULE__, method, [url, query, body, headers]) do
|
with {:ok, res} <- apply(__MODULE__, method, [url, query, body, headers]) do
|
||||||
res
|
res
|
||||||
else
|
else
|
||||||
{_, r} = error ->
|
{_, _r} = error ->
|
||||||
# Logger.warn(r)
|
# Logger.warn(r)
|
||||||
error
|
error
|
||||||
end
|
end
|
||||||
|
|
5
test/support/websub_mock.ex
Normal file
5
test/support/websub_mock.ex
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
defmodule Pleroma.Web.WebsubMock do
|
||||||
|
def verify(sub) do
|
||||||
|
{:ok, sub}
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,9 +1,3 @@
|
||||||
defmodule Pleroma.Web.WebsubMock do
|
|
||||||
def verify(sub) do
|
|
||||||
{:ok, sub}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
defmodule Pleroma.Web.WebsubTest do
|
defmodule Pleroma.Web.WebsubTest do
|
||||||
use Pleroma.DataCase
|
use Pleroma.DataCase
|
||||||
alias Pleroma.Web.Websub
|
alias Pleroma.Web.Websub
|
||||||
|
|
Loading…
Reference in a new issue