Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

41 wiersze
1.4KB

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.PleromaAPI.MascotController do
  5. use Pleroma.Web, :controller
  6. alias Pleroma.User
  7. alias Pleroma.Web.ActivityPub.ActivityPub
  8. alias Pleroma.Web.Plugs.OAuthScopesPlug
  9. plug(Pleroma.Web.ApiSpec.CastAndValidate)
  10. plug(OAuthScopesPlug, %{scopes: ["read:accounts"]} when action == :show)
  11. plug(OAuthScopesPlug, %{scopes: ["write:accounts"]} when action != :show)
  12. defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.PleromaMascotOperation
  13. @doc "GET /api/v1/pleroma/mascot"
  14. def show(%{assigns: %{user: user}} = conn, _params) do
  15. json(conn, User.get_mascot(user))
  16. end
  17. @doc "PUT /api/v1/pleroma/mascot"
  18. def update(%{assigns: %{user: user}, body_params: %{file: file}} = conn, _) do
  19. with {:ok, object} <- ActivityPub.upload(file, actor: User.ap_id(user)),
  20. # Reject if not an image
  21. %{type: "image"} = attachment <- render_attachment(object) do
  22. {:ok, _user} = User.mascot_update(user, attachment)
  23. json(conn, attachment)
  24. else
  25. %{type: _} -> render_error(conn, :unsupported_media_type, "mascots can only be images")
  26. end
  27. end
  28. defp render_attachment(object) do
  29. attachment_data = Map.put(object.data, "id", object.id)
  30. Pleroma.Web.MastodonAPI.StatusView.render("attachment.json", %{attachment: attachment_data})
  31. end
  32. end