Merge branch 'feature/media-description' into 'develop'
Feature/media description Closes #174 See merge request pleroma/pleroma!255
This commit is contained in:
commit
b7001ea9e7
@ -19,7 +19,7 @@ defmodule Pleroma.Upload do
|
|||||||
end
|
end
|
||||||
|
|
||||||
%{
|
%{
|
||||||
"type" => "Image",
|
"type" => "Document",
|
||||||
"url" => [
|
"url" => [
|
||||||
%{
|
%{
|
||||||
"type" => "Link",
|
"type" => "Link",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
||||||
use Pleroma.Web, :controller
|
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
|
||||||
alias Pleroma.Web.MastodonAPI.{StatusView, AccountView, MastodonView, ListView}
|
alias Pleroma.Web.MastodonAPI.{StatusView, AccountView, MastodonView, ListView}
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
@ -428,16 +428,43 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
|||||||
render(conn, AccountView, "relationships.json", %{user: user, targets: targets})
|
render(conn, AccountView, "relationships.json", %{user: user, targets: targets})
|
||||||
end
|
end
|
||||||
|
|
||||||
def upload(%{assigns: %{user: _}} = conn, %{"file" => file}) do
|
def update_media(%{assigns: %{user: _}} = conn, data) do
|
||||||
with {:ok, object} <- ActivityPub.upload(file) 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 =
|
data =
|
||||||
object.data
|
new_data
|
||||||
|> Map.put("id", object.id)
|
|> Map.put("id", object.id)
|
||||||
|
|
||||||
render(conn, StatusView, "attachment.json", %{attachment: data})
|
render(conn, StatusView, "attachment.json", %{attachment: data})
|
||||||
end
|
end
|
||||||
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
|
def favourited_by(conn, %{"id" => id}) do
|
||||||
with %Activity{data: %{"object" => %{"likes" => likes}}} <- Repo.get(Activity, id) do
|
with %Activity{data: %{"object" => %{"likes" => likes}}} <- Repo.get(Activity, id) do
|
||||||
q = from(u in User, where: u.ap_id in ^likes)
|
q = from(u in User, where: u.ap_id in ^likes)
|
||||||
|
@ -169,7 +169,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
|||||||
remote_url: href,
|
remote_url: href,
|
||||||
preview_url: MediaProxy.url(href),
|
preview_url: MediaProxy.url(href),
|
||||||
text_url: href,
|
text_url: href,
|
||||||
type: type
|
type: type,
|
||||||
|
description: attachment["name"]
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -127,6 +127,7 @@ defmodule Pleroma.Web.Router do
|
|||||||
get("/notifications/:id", MastodonAPIController, :get_notification)
|
get("/notifications/:id", MastodonAPIController, :get_notification)
|
||||||
|
|
||||||
post("/media", MastodonAPIController, :upload)
|
post("/media", MastodonAPIController, :upload)
|
||||||
|
put("/media/:id", MastodonAPIController, :update_media)
|
||||||
|
|
||||||
get("/lists", MastodonAPIController, :get_lists)
|
get("/lists", MastodonAPIController, :get_lists)
|
||||||
get("/lists/:id", MastodonAPIController, :get_list)
|
get("/lists/:id", MastodonAPIController, :get_list)
|
||||||
|
@ -736,16 +736,19 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||||||
filename: "an_image.jpg"
|
filename: "an_image.jpg"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
desc = "Description of the image"
|
||||||
|
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
conn =
|
conn =
|
||||||
conn
|
conn
|
||||||
|> assign(:user, user)
|
|> assign(:user, user)
|
||||||
|> post("/api/v1/media", %{"file" => file})
|
|> post("/api/v1/media", %{"file" => file, "description" => desc})
|
||||||
|
|
||||||
assert media = json_response(conn, 200)
|
assert media = json_response(conn, 200)
|
||||||
|
|
||||||
assert media["type"] == "image"
|
assert media["type"] == "image"
|
||||||
|
assert media["description"] == desc
|
||||||
end
|
end
|
||||||
|
|
||||||
test "hashtag timeline", %{conn: conn} do
|
test "hashtag timeline", %{conn: conn} do
|
||||||
|
@ -102,7 +102,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||||||
url: "someurl",
|
url: "someurl",
|
||||||
remote_url: "someurl",
|
remote_url: "someurl",
|
||||||
preview_url: "someurl",
|
preview_url: "someurl",
|
||||||
text_url: "someurl"
|
text_url: "someurl",
|
||||||
|
description: nil
|
||||||
}
|
}
|
||||||
|
|
||||||
assert expected == StatusView.render("attachment.json", %{attachment: object})
|
assert expected == StatusView.render("attachment.json", %{attachment: object})
|
||||||
|
Loading…
Reference in New Issue
Block a user