aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRoger Braun <roger@rogerbraun.net>2017-11-10 17:37:54 +0100
committerRoger Braun <roger@rogerbraun.net>2017-11-10 17:37:54 +0100
commit1d3d66a841253a244e5166726ba4f3d1f21651c3 (patch)
treeb1d0c230d9bfebd139b527392e5399fa647781d9 /lib
parent6e9c22c0afaa67f0b94f602eceef5c57b7c9192f (diff)
parent1b8ad9f731708a3231ef01a5db1fba2516d48d98 (diff)
downloadpleroma-1d3d66a841253a244e5166726ba4f3d1f21651c3.tar.gz
Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into develop
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/upload.ex10
-rw-r--r--lib/pleroma/web/mastodon_api/mastodon_api_controller.ex12
2 files changed, 19 insertions, 3 deletions
diff --git a/lib/pleroma/upload.ex b/lib/pleroma/upload.ex
index 2717377a3..d5723f5de 100644
--- a/lib/pleroma/upload.ex
+++ b/lib/pleroma/upload.ex
@@ -8,11 +8,19 @@ defmodule Pleroma.Upload 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,
diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
index feaf9a900..c28e20ed1 100644
--- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
+++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
@@ -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 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController 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),