Merge branch 'develop' of https://git.pleroma.social/pleroma/pleroma into develop
[akkoma] / lib / pleroma / web / mastodon_api / views / app_view.ex
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
5 defmodule Pleroma.Web.MastodonAPI.AppView do
6 use Pleroma.Web, :view
7
8 alias Pleroma.Web.OAuth.App
9
10 def render("show.json", %{app: %App{} = app}) do
11 %{
12 id: app.id |> to_string,
13 name: app.client_name,
14 client_id: app.client_id,
15 client_secret: app.client_secret,
16 redirect_uri: app.redirect_uris,
17 website: app.website
18 }
19 |> with_vapid_key()
20 end
21
22 def render("short.json", %{app: %App{website: webiste, client_name: name}}) do
23 %{
24 name: name,
25 website: webiste
26 }
27 |> with_vapid_key()
28 end
29
30 defp with_vapid_key(data) do
31 vapid_key = Application.get_env(:web_push_encryption, :vapid_details, [])[:public_key]
32
33 if vapid_key do
34 Map.put(data, "vapid_key", vapid_key)
35 else
36 data
37 end
38 end
39 end