mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-11-19 16:10:59 +00:00
[#210] Further refactoring.
This commit is contained in:
parent
44ab3dbe2c
commit
be187f82f7
1 changed files with 11 additions and 3 deletions
|
@ -226,13 +226,21 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc "https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-metadata-create"
|
@doc """
|
||||||
|
Updates metadata of uploaded media object.
|
||||||
|
Derived from [Twitter API endpoint](https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-metadata-create).
|
||||||
|
"""
|
||||||
def update_media(%{assigns: %{user: _}} = conn, %{"media_id" => id} = data) do
|
def update_media(%{assigns: %{user: _}} = conn, %{"media_id" => id} = data) do
|
||||||
description = get_in(data, ["alt_text", "text"]) || data["name"] || data["description"]
|
description = get_in(data, ["alt_text", "text"]) || data["name"] || data["description"]
|
||||||
|
|
||||||
with %Object{} = object <- Repo.get(Object, id), is_binary(description) do
|
with %Object{} = object <- Repo.get(Object, id),
|
||||||
|
is_binary(description) do
|
||||||
new_data = Map.put(object.data, "name", description)
|
new_data = Map.put(object.data, "name", description)
|
||||||
{:ok, _} = object |> Object.change(%{data: new_data}) |> Repo.update()
|
|
||||||
|
{:ok, _} =
|
||||||
|
object
|
||||||
|
|> Object.change(%{data: new_data})
|
||||||
|
|> Repo.update()
|
||||||
end
|
end
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|
|
Loading…
Reference in a new issue