diff options
author | lambda <pleromagit@rogerbraun.net> | 2018-07-18 08:52:11 +0000 |
---|---|---|
committer | lambda <pleromagit@rogerbraun.net> | 2018-07-18 08:52:11 +0000 |
commit | b7001ea9e72947596b60e080768be10b4cbae82b (patch) | |
tree | eda8c988ce1a6a81f9d8275a07caed33aac78e1e /lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | |
parent | d93789dfde3c44c76a56732088a897ddddfe9716 (diff) | |
parent | 18cac1e36bd91e1554de1f495a7f178b27b2fbc3 (diff) | |
download | pleroma-b7001ea9e72947596b60e080768be10b4cbae82b.tar.gz |
Merge branch 'feature/media-description' into 'develop'
Feature/media description
Closes #174
See merge request pleroma/pleroma!255
Diffstat (limited to 'lib/pleroma/web/mastodon_api/mastodon_api_controller.ex')
-rw-r--r-- | lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 09e6b0b59..f270e1146 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -1,6 +1,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do use Pleroma.Web, :controller - alias Pleroma.{Repo, Activity, User, Notification, Stats} + alias Pleroma.{Repo, Object, Activity, User, Notification, Stats} alias Pleroma.Web alias Pleroma.Web.MastodonAPI.{StatusView, AccountView, MastodonView, ListView} alias Pleroma.Web.ActivityPub.ActivityPub @@ -428,16 +428,43 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do render(conn, AccountView, "relationships.json", %{user: user, targets: targets}) end - def upload(%{assigns: %{user: _}} = conn, %{"file" => file}) do - with {:ok, object} <- ActivityPub.upload(file) do + def update_media(%{assigns: %{user: _}} = conn, data) do + with %Object{} = object <- Repo.get(Object, data["id"]), + true <- is_binary(data["description"]), + description <- data["description"] do + new_data = %{object.data | "name" => description} + + change = Object.change(object, %{data: new_data}) + {:ok, media_obj} = Repo.update(change) + data = - object.data + new_data |> Map.put("id", object.id) render(conn, StatusView, "attachment.json", %{attachment: data}) end end + def upload(%{assigns: %{user: _}} = conn, %{"file" => file} = data) do + with {:ok, object} <- ActivityPub.upload(file) do + objdata = + if Map.has_key?(data, "description") do + Map.put(object.data, "name", data["description"]) + else + object.data + end + + change = Object.change(object, %{data: objdata}) + {:ok, object} = Repo.update(change) + + objdata = + objdata + |> Map.put("id", object.id) + + render(conn, StatusView, "attachment.json", %{attachment: objdata}) + end + end + def favourited_by(conn, %{"id" => id}) do with %Activity{data: %{"object" => %{"likes" => likes}}} <- Repo.get(Activity, id) do q = from(u in User, where: u.ap_id in ^likes) |