keep masto routes, add placeholder index
This commit is contained in:
parent
04d3661fcf
commit
7ca534740f
7 changed files with 120 additions and 44 deletions
|
@ -709,7 +709,7 @@
|
|||
"192.168.0.0/16"
|
||||
]
|
||||
|
||||
config :pleroma, :static_fe, enabled: false
|
||||
config :pleroma, :static_fe, enabled: true
|
||||
|
||||
# Example of frontend configuration
|
||||
# This example will make us serve the primary frontend from the
|
||||
|
@ -726,6 +726,10 @@
|
|||
# available: %{...}
|
||||
|
||||
config :pleroma, :frontends,
|
||||
mastodon: %{
|
||||
"name" => "mastodon-fe",
|
||||
"ref" => "develop"
|
||||
},
|
||||
available: %{
|
||||
"pleroma-fe" => %{
|
||||
"name" => "pleroma-fe",
|
||||
|
@ -734,7 +738,7 @@
|
|||
"ref" => "develop",
|
||||
"build_dir" => "dist"
|
||||
},
|
||||
# mastodon-Fe cannot be set as a primary - it can only be enabled via the mastodon configuration above
|
||||
# mastodon-Fe cannot be set as a primary - this is only here so we can update this seperately
|
||||
"mastodon-fe" => %{
|
||||
"name" => "mastodon-fe",
|
||||
"git" => "https://akkoma.dev/AkkomaGang/masto-fe",
|
||||
|
|
|
@ -8,7 +8,6 @@ defmodule Pleroma.Web.Endpoint do
|
|||
require Pleroma.Constants
|
||||
|
||||
alias Pleroma.Config
|
||||
@mastoFEEnabled Config.get([:frontends, :mastodon, "enabled"])
|
||||
|
||||
socket("/socket", Pleroma.Web.UserSocket)
|
||||
socket("/live", Phoenix.LiveView.Socket)
|
||||
|
@ -69,6 +68,28 @@ defmodule Pleroma.Web.Endpoint do
|
|||
}
|
||||
)
|
||||
|
||||
plug(Plug.Static.IndexHtml, at: "/pleroma/fedife/")
|
||||
|
||||
plug(Pleroma.Web.Plugs.FrontendStatic,
|
||||
at: "/pleroma/fedife",
|
||||
frontend_type: :fedife,
|
||||
gzip: true,
|
||||
cache_control_for_etags: @static_cache_control,
|
||||
headers: %{
|
||||
"cache-control" => @static_cache_control
|
||||
}
|
||||
)
|
||||
|
||||
plug(Pleroma.Web.Plugs.FrontendStatic,
|
||||
at: "/",
|
||||
frontend_type: :mastodon,
|
||||
gzip: true,
|
||||
cache_control_for_etags: @static_cache_control,
|
||||
headers: %{
|
||||
"cache-control" => @static_cache_control
|
||||
}
|
||||
)
|
||||
|
||||
# Serve at "/" the static files from "priv/static" directory.
|
||||
#
|
||||
# You should set gzip to true if you are running phoenix.digest
|
||||
|
@ -91,18 +112,6 @@ defmodule Pleroma.Web.Endpoint do
|
|||
from: {:pleroma, "priv/static/adminfe/"}
|
||||
)
|
||||
|
||||
if @mastoFEEnabled do
|
||||
plug(Pleroma.Web.Plugs.FrontendStatic,
|
||||
at: "/",
|
||||
frontend_type: :mastodon,
|
||||
gzip: true,
|
||||
cache_control_for_etags: @static_cache_control,
|
||||
headers: %{
|
||||
"cache-control" => @static_cache_control
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
# Code reloading can be explicitly enabled under the
|
||||
# :code_reloader configuration of your endpoint.
|
||||
if code_reloading? do
|
||||
|
|
|
@ -8,16 +8,61 @@ defmodule Pleroma.Web.MastodonAPI.AuthController do
|
|||
import Pleroma.Web.ControllerHelper, only: [json_response: 3]
|
||||
|
||||
alias Pleroma.Helpers.AuthHelper
|
||||
alias Pleroma.Helpers.UriHelper
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.OAuth.App
|
||||
alias Pleroma.Web.OAuth.Authorization
|
||||
alias Pleroma.Web.OAuth.Token
|
||||
alias Pleroma.Web.OAuth.Token.Strategy.Revoke, as: RevokeToken
|
||||
alias Pleroma.Web.TwitterAPI.TwitterAPI
|
||||
alias Pleroma.Web.MastodonFE.Controller, as: MastodonFEController
|
||||
|
||||
action_fallback(Pleroma.Web.MastodonAPI.FallbackController)
|
||||
|
||||
plug(Pleroma.Web.Plugs.RateLimiter, [name: :password_reset] when action == :password_reset)
|
||||
|
||||
use MastodonFEController, :auth_controller_login
|
||||
@local_mastodon_name "Mastodon-Local"
|
||||
|
||||
@doc "GET /web/login"
|
||||
# Local Mastodon FE login callback action
|
||||
def login(conn, %{"code" => auth_token} = params) do
|
||||
with {:ok, app} <- local_mastofe_app(),
|
||||
{:ok, auth} <- Authorization.get_by_token(app, auth_token),
|
||||
{:ok, oauth_token} <- Token.exchange_token(app, auth) do
|
||||
redirect_to =
|
||||
conn
|
||||
|> local_mastodon_post_login_path()
|
||||
|> UriHelper.modify_uri_params(%{"access_token" => oauth_token.token})
|
||||
|
||||
conn
|
||||
|> AuthHelper.put_session_token(oauth_token.token)
|
||||
|> redirect(to: redirect_to)
|
||||
else
|
||||
_ -> redirect_to_oauth_form(conn, params)
|
||||
end
|
||||
end
|
||||
|
||||
def login(conn, params) do
|
||||
with %{assigns: %{user: %User{}, token: %Token{app_id: app_id}}} <- conn,
|
||||
{:ok, %{id: ^app_id}} <- local_mastofe_app() do
|
||||
redirect(conn, to: local_mastodon_post_login_path(conn))
|
||||
else
|
||||
_ -> redirect_to_oauth_form(conn, params)
|
||||
end
|
||||
end
|
||||
|
||||
defp redirect_to_oauth_form(conn, _params) do
|
||||
with {:ok, app} <- local_mastofe_app() do
|
||||
path =
|
||||
Routes.o_auth_path(conn, :authorize,
|
||||
response_type: "code",
|
||||
client_id: app.client_id,
|
||||
redirect_uri: ".",
|
||||
scope: Enum.join(app.scopes, " ")
|
||||
)
|
||||
|
||||
redirect(conn, to: path)
|
||||
end
|
||||
end
|
||||
|
||||
@doc "DELETE /auth/sign_out"
|
||||
def logout(conn, _) do
|
||||
|
@ -42,5 +87,22 @@ def password_reset(conn, params) do
|
|||
json_response(conn, :no_content, "")
|
||||
end
|
||||
|
||||
use MastodonFEController, :auth_controller_local_functions
|
||||
defp local_mastodon_post_login_path(conn) do
|
||||
case get_session(conn, :return_to) do
|
||||
nil ->
|
||||
Routes.masto_fe_path(conn, :index, ["getting-started"])
|
||||
|
||||
return_to ->
|
||||
delete_session(conn, :return_to)
|
||||
return_to
|
||||
end
|
||||
end
|
||||
|
||||
@spec local_mastofe_app() :: {:ok, App.t()} | {:error, Ecto.Changeset.t()}
|
||||
def local_mastofe_app do
|
||||
App.get_or_make(
|
||||
%{client_name: @local_mastodon_name, redirect_uris: "."},
|
||||
["read", "write", "follow", "push", "admin"]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,6 +14,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationView do
|
|||
alias Pleroma.Web.AdminAPI.Report
|
||||
alias Pleroma.Web.AdminAPI.ReportView
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.MediaProxy
|
||||
alias Pleroma.Web.MastodonAPI.AccountView
|
||||
alias Pleroma.Web.MastodonAPI.NotificationView
|
||||
alias Pleroma.Web.MastodonAPI.StatusView
|
||||
|
@ -140,7 +141,7 @@ defp put_report(response, activity) do
|
|||
defp put_emoji(response, activity) do
|
||||
response
|
||||
|> Map.put(:emoji, activity.data["content"])
|
||||
|> Map.put(:emoji_url, Pleroma.Emoji.emoji_url(activity.data))
|
||||
|> Map.put(:emoji_url, MediaProxy.url(Pleroma.Emoji.emoji_url(activity.data)))
|
||||
end
|
||||
|
||||
defp put_chat_message(response, activity, reading_user, opts) do
|
||||
|
|
|
@ -597,6 +597,7 @@ def login(%User{} = user, %App{} = app, requested_scopes) when is_list(requested
|
|||
end
|
||||
end
|
||||
|
||||
# Special case: Local MastodonFE
|
||||
defp redirect_uri(%Plug.Conn{} = conn, "."), do: Routes.auth_url(conn, :login)
|
||||
|
||||
defp redirect_uri(%Plug.Conn{}, redirect_uri), do: redirect_uri
|
||||
|
|
|
@ -4,11 +4,8 @@
|
|||
|
||||
defmodule Pleroma.Web.Router do
|
||||
use Pleroma.Web, :router
|
||||
alias Pleroma.Config
|
||||
import Phoenix.LiveDashboard.Router
|
||||
|
||||
@mastoFEEnabled Config.get([:frontends, :mastodon, "enabled"])
|
||||
|
||||
pipeline :accepts_html do
|
||||
plug(:accepts, ["html"])
|
||||
end
|
||||
|
@ -581,13 +578,11 @@ defmodule Pleroma.Web.Router do
|
|||
get("/timelines/list/:list_id", TimelineController, :list)
|
||||
end
|
||||
|
||||
if @mastoFEEnabled do
|
||||
scope "/api/web", Pleroma.Web do
|
||||
pipe_through(:authenticated_api)
|
||||
scope "/api/web", Pleroma.Web do
|
||||
pipe_through(:authenticated_api)
|
||||
|
||||
# Backend-obscure settings blob for MastoFE, don't parse/reuse elsewhere
|
||||
put("/settings", MastoFEController, :put_settings)
|
||||
end
|
||||
# Backend-obscure settings blob for MastoFE, don't parse/reuse elsewhere
|
||||
put("/settings", MastoFEController, :put_settings)
|
||||
end
|
||||
|
||||
scope "/api/v1", Pleroma.Web.MastodonAPI do
|
||||
|
@ -796,26 +791,24 @@ defmodule Pleroma.Web.Router do
|
|||
get("/:version", Nodeinfo.NodeinfoController, :nodeinfo)
|
||||
end
|
||||
|
||||
if @mastoFEEnabled do
|
||||
scope "/", Pleroma.Web do
|
||||
pipe_through(:api)
|
||||
scope "/", Pleroma.Web do
|
||||
pipe_through(:api)
|
||||
|
||||
get("/manifest.json", ManifestController, :show)
|
||||
get("/web/manifest.json", MastoFEController, :manifest)
|
||||
end
|
||||
|
||||
scope "/", Pleroma.Web do
|
||||
pipe_through(:mastodon_html)
|
||||
get("/web/login", MastodonAPI.AuthController, :login)
|
||||
delete("/auth/sign_out", MastodonAPI.AuthController, :logout)
|
||||
get("/web/*path", MastoFEController, :index)
|
||||
get("/embed/:id", EmbedController, :show)
|
||||
end
|
||||
get("/manifest.json", ManifestController, :show)
|
||||
get("/web/manifest.json", MastoFEController, :manifest)
|
||||
end
|
||||
|
||||
scope "/", Pleroma.Web do
|
||||
pipe_through(:pleroma_html)
|
||||
post("/auth/password", TwitterAPI.PasswordController, :request)
|
||||
pipe_through(:mastodon_html)
|
||||
|
||||
get("/web/login", MastodonAPI.AuthController, :login)
|
||||
delete("/auth/sign_out", MastodonAPI.AuthController, :logout)
|
||||
|
||||
post("/auth/password", MastodonAPI.AuthController, :password_reset)
|
||||
|
||||
get("/web/*path", MastoFEController, :index)
|
||||
|
||||
get("/embed/:id", EmbedController, :show)
|
||||
end
|
||||
|
||||
scope "/proxy/", Pleroma.Web do
|
||||
|
|
6
priv/static/index.html
Normal file
6
priv/static/index.html
Normal file
|
@ -0,0 +1,6 @@
|
|||
<html>
|
||||
<body>
|
||||
<h3>Welcome to Akkoma!</h3>
|
||||
<p>If you're seeing this page, your server works!</p>
|
||||
<p>In order to get a frontend to show here, you'll need to set up <pre>:pleroma, :frontends, :primary</pre> and install your frontend of choice</p>
|
||||
</html>
|
Loading…
Reference in a new issue