diff options
author | eugenijm <eugenijm@protonmail.com> | 2019-03-26 23:21:31 +0300 |
---|---|---|
committer | eugenijm <eugenijm@protonmail.com> | 2019-03-26 23:27:37 +0300 |
commit | a4ab60ac54d7ef0e2983483868c0e6fd59213aa4 (patch) | |
tree | 7425cec96e7195ec51f1fb7e1eac50df10df8cc6 /lib | |
parent | 691d1208b5abd5bfb6ff0c1c75a8f315ee0e4500 (diff) | |
download | pleroma-a4ab60ac54d7ef0e2983483868c0e6fd59213aa4.tar.gz |
Add vapid_key to the `POST /api/v1/apps` response
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 15 | ||||
-rw-r--r-- | lib/pleroma/web/mastodon_api/views/app_view.ex | 38 |
2 files changed, 30 insertions, 23 deletions
diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 295c8bebe..eee4e7678 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -52,16 +52,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do with cs <- App.register_changeset(%App{}, app_attrs), false <- cs.changes[:client_name] == @local_mastodon_name, {:ok, app} <- Repo.insert(cs) do - res = %{ - id: app.id |> to_string, - name: app.client_name, - client_id: app.client_id, - client_secret: app.client_secret, - redirect_uri: app.redirect_uris, - website: app.website - } - - json(conn, res) + conn + |> put_view(AppView) + |> render("show.json", %{app: app}) end end @@ -137,7 +130,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do with %Token{app: %App{} = app} <- Repo.preload(token, :app) do conn |> put_view(AppView) - |> render("show.json", %{app: app}) + |> render("short.json", %{app: app}) end end diff --git a/lib/pleroma/web/mastodon_api/views/app_view.ex b/lib/pleroma/web/mastodon_api/views/app_view.ex index 1976d4dcb..f52b693a6 100644 --- a/lib/pleroma/web/mastodon_api/views/app_view.ex +++ b/lib/pleroma/web/mastodon_api/views/app_view.ex @@ -7,21 +7,35 @@ defmodule Pleroma.Web.MastodonAPI.AppView do alias Pleroma.Web.OAuth.App - def render("show.json", %{app: %App{website: webiste, client_name: name}}) do - result = %{ + @vapid_key :web_push_encryption + |> Application.get_env(:vapid_details, []) + |> Keyword.get(:public_key) + + def render("show.json", %{app: %App{} = app}) do + %{ + id: app.id |> to_string, + name: app.client_name, + client_id: app.client_id, + client_secret: app.client_secret, + redirect_uri: app.redirect_uris, + website: app.website + } + |> with_vapid_key() + end + + def render("short.json", %{app: %App{website: webiste, client_name: name}}) do + %{ name: name, website: webiste } + |> with_vapid_key() + end - vapid_key = Pleroma.Web.Push.vapid_config() |> Keyword.get(:public_key) - - result = - if vapid_key do - Map.put(result, "vapid_key", vapid_key) - else - result - end - - result + defp with_vapid_key(data) do + if @vapid_key do + Map.put(data, "vapid_key", @vapid_key) + else + data + end end end |