1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.MastoFEController do
6 use Pleroma.Web, :controller
9 alias Pleroma.Web.MastodonAPI.AuthController
10 alias Pleroma.Web.OAuth.Token
11 alias Pleroma.Web.Plugs.OAuthScopesPlug
13 plug(OAuthScopesPlug, %{scopes: ["write:accounts"]} when action == :put_settings)
15 # Note: :index action handles attempt of unauthenticated access to private instance with redirect
16 plug(:skip_public_check when action == :index)
20 %{scopes: ["read"], fallback: :proceed_unauthenticated}
24 plug(:skip_auth when action == :manifest)
27 def index(conn, _params) do
28 with %{assigns: %{user: %User{} = user, token: %Token{app_id: token_app_id} = token}} <- conn,
29 {:ok, %{id: ^token_app_id}} <- AuthController.local_mastofe_app() do
31 [:frontends, :mastodon]
32 |> Pleroma.Config.get()
33 |> Map.get("name", "mastodon-fe")
36 if flavour == "fedibird-fe" do
39 "glitchsoc.index.html"
47 custom_emojis: Pleroma.Emoji.get_all()
52 |> put_session(:return_to, conn.request_path)
53 |> redirect(to: "/web/login")
57 @doc "GET /web/manifest.json"
58 def manifest(conn, _params) do
59 render(conn, "manifest.json")
62 @doc "PUT /api/web/settings: Backend-obscure settings blob for MastoFE, don't parse/reuse elsewhere"
63 def put_settings(%{assigns: %{user: user}} = conn, %{"data" => settings} = _params) do
64 with {:ok, _} <- User.mastodon_settings_update(user, settings) do
69 |> put_status(:internal_server_error)
70 |> json(%{error: inspect(e)})