TwitterAPI: Fix banner and background update.

This commit is contained in:
lain 2018-12-01 12:00:53 +01:00
parent 4996fb07d8
commit 93f2dc19d9
3 changed files with 52 additions and 8 deletions

View File

@ -23,7 +23,18 @@ defmodule Pleroma.User.Info do
field(:uri, :string, default: nil) field(:uri, :string, default: nil)
field(:topic, :string, default: nil) field(:topic, :string, default: nil)
field(:hub, :string, default: nil) field(:hub, :string, default: nil)
# topic, subject, salmon, subscribe_address, uri
# Found in the wild
# ap_id -> Where is this used?
# bio -> Where is this used?
# avatar -> Where is this used?
# fqn -> Where is this used?
# host -> Where is this used?
# name -> Where is this used?
# nickname -> Where is this used?
# salmon -> Where is this used?
# subject _> Where is this used?
# subscribe_address -> Where is this used?
end end
def set_activation_status(info, deactivated) do def set_activation_status(info, deactivated) do
@ -124,7 +135,8 @@ def profile_update(info, params) do
|> cast(params, [ |> cast(params, [
:locked, :locked,
:no_rich_text, :no_rich_text,
:default_scope :default_scope,
:banner
]) ])
end end

View File

@ -300,9 +300,10 @@ def update_avatar(%{assigns: %{user: user}} = conn, params) do
def update_banner(%{assigns: %{user: user}} = conn, params) do def update_banner(%{assigns: %{user: user}} = conn, params) do
with {:ok, object} <- ActivityPub.upload(%{"img" => params["banner"]}, type: :banner), with {:ok, object} <- ActivityPub.upload(%{"img" => params["banner"]}, type: :banner),
new_info <- Map.put(user.info, "banner", object.data), new_info <- %{"banner" => object.data},
change <- User.info_changeset(user, %{info: new_info}), info_cng <- User.Info.profile_update(user.info, new_info),
{:ok, user} <- User.update_and_set_cache(change) do changeset <- Ecto.Changeset.change(user) |> Ecto.Changeset.put_embed(:info, info_cng),
{:ok, user} <- User.update_and_set_cache(changeset) do
CommonAPI.update(user) CommonAPI.update(user)
%{"url" => [%{"href" => href} | _]} = object.data %{"url" => [%{"href" => href} | _]} = object.data
response = %{url: href} |> Jason.encode!() response = %{url: href} |> Jason.encode!()
@ -314,9 +315,10 @@ def update_banner(%{assigns: %{user: user}} = conn, params) do
def update_background(%{assigns: %{user: user}} = conn, params) do def update_background(%{assigns: %{user: user}} = conn, params) do
with {:ok, object} <- ActivityPub.upload(params, type: :background), with {:ok, object} <- ActivityPub.upload(params, type: :background),
new_info <- Map.put(user.info, "background", object.data), new_info <- %{"background" => object.data},
change <- User.info_changeset(user, %{info: new_info}), info_cng <- User.Info.profile_update(user.info, new_info),
{:ok, _user} <- User.update_and_set_cache(change) do changeset <- Ecto.Changeset.change(user) |> Ecto.Changeset.put_embed(:info, info_cng),
{:ok, _user} <- User.update_and_set_cache(changeset) do
%{"url" => [%{"href" => href} | _]} = object.data %{"url" => [%{"href" => href} | _]} = object.data
response = %{url: href} |> Jason.encode!() response = %{url: href} |> Jason.encode!()

View File

@ -12,6 +12,36 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
import Pleroma.Factory import Pleroma.Factory
describe "POST /api/account/update_profile_banner" do
test "it updates the banner", %{conn: conn} do
user = insert(:user)
new_banner =
"data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7"
response =
conn
|> assign(:user, user)
|> post(authenticated_twitter_api__path(conn, :update_banner), %{"banner" => new_banner})
|> json_response(200)
end
end
describe "POST /api/qvitter/update_background_image" do
test "it updates the background", %{conn: conn} do
user = insert(:user)
new_bg =
"data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7"
response =
conn
|> assign(:user, user)
|> post(authenticated_twitter_api__path(conn, :update_background), %{"img" => new_bg})
|> json_response(200)
end
end
describe "POST /api/account/verify_credentials" do describe "POST /api/account/verify_credentials" do
setup [:valid_user] setup [:valid_user]