logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

app_view.ex (1388B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.MastodonAPI.AppView do
  5. use Pleroma.Web, :view
  6. alias Pleroma.Web.OAuth.App
  7. def render("index.json", %{apps: apps, count: count, page_size: page_size, admin: true}) do
  8. %{
  9. apps: render_many(apps, Pleroma.Web.MastodonAPI.AppView, "show.json", %{admin: true}),
  10. count: count,
  11. page_size: page_size
  12. }
  13. end
  14. def render("show.json", %{admin: true, app: %App{} = app} = assigns) do
  15. "show.json"
  16. |> render(Map.delete(assigns, :admin))
  17. |> Map.put(:trusted, app.trusted)
  18. |> Map.put(:id, app.id)
  19. end
  20. def render("show.json", %{app: %App{} = app}) do
  21. %{
  22. id: app.id |> to_string,
  23. name: app.client_name,
  24. client_id: app.client_id,
  25. client_secret: app.client_secret,
  26. redirect_uri: app.redirect_uris,
  27. website: app.website
  28. }
  29. |> with_vapid_key()
  30. end
  31. def render("compact_non_secret.json", %{app: %App{website: website, client_name: name}}) do
  32. %{
  33. name: name,
  34. website: website
  35. }
  36. |> with_vapid_key()
  37. end
  38. defp with_vapid_key(data) do
  39. vapid_key = Application.get_env(:web_push_encryption, :vapid_details, [])[:public_key]
  40. Pleroma.Maps.put_if_present(data, "vapid_key", vapid_key)
  41. end
  42. end