Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into develop

This commit is contained in:
Roger Braun 2017-11-10 17:37:54 +01:00
commit 1d3d66a841
7 changed files with 74 additions and 7 deletions

View file

@ -8,11 +8,19 @@ def store(%Plug.Upload{} = file) do
result_file = Path.join(upload_folder, file.filename)
File.cp!(file.path, result_file)
# fix content type on some image uploads
matches = Regex.named_captures(~r/\.(?<ext>(jpg|jpeg|png|gif))$/i, file.filename)
content_type = if file.content_type == "application/octet-stream" and matches do
if matches["ext"] == "jpg", do: "image/jpeg", else: "image/#{matches["ext"]}"
else
file.content_type
end
%{
"type" => "Image",
"url" => [%{
"type" => "Link",
"mediaType" => file.content_type,
"mediaType" => content_type,
"href" => url_for(Path.join(uuid, :cow_uri.urlencode(file.filename)))
}],
"name" => file.filename,

View file

@ -6,7 +6,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
alias Pleroma.Web.MastodonAPI.{StatusView, AccountView}
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.TwitterAPI.TwitterAPI
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.{CommonAPI, OStatus}
import Ecto.Query
import Logger
@ -361,11 +361,19 @@ def blocks(%{assigns: %{user: user}} = conn, _) do
def search(%{assigns: %{user: user}} = conn, %{"q" => query} = params) do
accounts = User.search(query, params["resolve"] == "true")
fetched = if Regex.match?(~r/https?:/, query) do
with {:ok, activities} <- OStatus.fetch_activity_from_url(query) do
activities
else
_e -> []
end
end || []
q = from a in Activity,
where: fragment("?->>'type' = 'Create'", a.data),
where: fragment("to_tsvector('english', ?->'object'->>'content') @@ plainto_tsquery('english', ?)", a.data, ^query),
limit: 20
statuses = Repo.all(q)
statuses = Repo.all(q) ++ fetched
res = %{
"accounts" => AccountView.render("accounts.json", users: accounts, for: user, as: :user),

View file

@ -8,10 +8,6 @@ def up do
add :actor, :string
end
execute """
update activities set actor = data->>'actor';
"""
create index(:activities, [:actor, "id DESC NULLS LAST"], concurrently: true)
end

View file

@ -0,0 +1,26 @@
defmodule Pleroma.Repo.Migrations.FillActorField do
use Ecto.Migration
alias Pleroma.{Repo, Activity}
def up do
max = Repo.aggregate(Activity, :max, :id)
if max do
IO.puts("#{max} activities")
chunks = 0..(round(max / 10_000))
Enum.each(chunks, fn (i) ->
min = i * 10_000
max = min + 10_000
execute("""
update activities set actor = data->>'actor' where id > #{min} and id <= #{max};
""")
|> IO.inspect
end)
end
end
def down do
end
end

View file

@ -0,0 +1,8 @@
defmodule Pleroma.Repo.Migrations.AddSortIndexToActivities do
use Ecto.Migration
@disable_ddl_transaction true
def change do
create index(:activities, ["id desc nulls last"], concurrently: true)
end
end

View file

@ -9,5 +9,17 @@ test "copies the file to the configured folder" do
assert data["name"] == "an [image.jpg"
assert List.first(data["url"])["href"] == "http://localhost:4001/media/#{data["uuid"]}/an%20%5Bimage.jpg"
end
test "fixes an incorrect content type" do
file = %Plug.Upload{content_type: "application/octet-stream", path: Path.absname("test/fixtures/image.jpg"), filename: "an [image.jpg"}
data = Upload.store(file)
assert hd(data["url"])["mediaType"] == "image/jpeg"
end
test "does not modify a valid content type" do
file = %Plug.Upload{content_type: "image/png", path: Path.absname("test/fixtures/image.jpg"), filename: "an [image.jpg"}
data = Upload.store(file)
assert hd(data["url"])["mediaType"] == "image/png"
end
end
end

View file

@ -386,6 +386,15 @@ test "search", %{conn: conn} do
assert status["id"] == to_string(activity.id)
end
test "search fetches remote statuses", %{conn: conn} do
conn = conn
|> get("/api/v1/search", %{"q" => "https://shitposter.club/notice/2827873"})
assert results = json_response(conn, 200)
[status] = results["statuses"]
assert status["uri"] == "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
end
test "search fetches remote accounts", %{conn: conn} do
conn = conn
|> get("/api/v1/search", %{"q" => "shp@social.heldscal.la", "resolve" => "true"})