Add Mastodon frontend.
This commit is contained in:
parent
414c52509b
commit
d293ceb1b5
|
@ -10,8 +10,12 @@ def init(options) do
|
|||
|
||||
def call(%{assigns: %{user: %User{}}} = conn, _), do: conn
|
||||
def call(conn, opts) do
|
||||
with ["Bearer " <> header] <- get_req_header(conn, "authorization"),
|
||||
%Token{user_id: user_id} <- Repo.get_by(Token, token: header),
|
||||
token = case get_req_header(conn, "authorization") do
|
||||
["Bearer " <> header] -> header
|
||||
_ -> get_session(conn, :oauth_token)
|
||||
end
|
||||
with token when not is_nil(token) <- token,
|
||||
%Token{user_id: user_id} <- Repo.get_by(Token, token: token),
|
||||
%User{} = user <- Repo.get(User, user_id) do
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|
|
|
@ -12,7 +12,7 @@ defmodule Pleroma.Web.Endpoint do
|
|||
at: "/media", from: "uploads", gzip: false
|
||||
plug Plug.Static,
|
||||
at: "/", from: :pleroma,
|
||||
only: ~w(index.html static finmoji emoji)
|
||||
only: ~w(index.html static finmoji emoji packs sounds sw.js)
|
||||
|
||||
# Code reloading can be explicitly enabled under the
|
||||
# :code_reloader configuration of your endpoint.
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
||||
use Pleroma.Web, :controller
|
||||
alias Pleroma.{Repo, Activity, User, Notification}
|
||||
alias Pleroma.Web.OAuth.App
|
||||
alias Pleroma.Web
|
||||
alias Pleroma.Web.MastodonAPI.{StatusView, AccountView}
|
||||
alias Pleroma.Web.MastodonAPI.{StatusView, AccountView, MastodonView}
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.TwitterAPI.TwitterAPI
|
||||
alias Pleroma.Web.{CommonAPI, OStatus}
|
||||
alias Pleroma.Web.OAuth.{Authorization, Token, App}
|
||||
alias Comeonin.Pbkdf2
|
||||
import Ecto.Query
|
||||
import Logger
|
||||
|
||||
|
@ -405,6 +406,116 @@ def favourites(%{assigns: %{user: user}} = conn, params) do
|
|||
|> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity})
|
||||
end
|
||||
|
||||
def index(%{assigns: %{user: user}} = conn, _params) do
|
||||
token = conn
|
||||
|> get_session(:oauth_token)
|
||||
|
||||
if user && token do
|
||||
accounts = Map.put(%{}, user.id, AccountView.render("account.json", %{user: user}))
|
||||
initial_state = %{
|
||||
meta: %{
|
||||
streaming_api_base_url: String.replace(Pleroma.Web.Endpoint.static_url(), "http", "ws"),
|
||||
access_token: token,
|
||||
locale: "en",
|
||||
domain: Pleroma.Web.Endpoint.host(),
|
||||
admin: "1",
|
||||
me: "#{user.id}",
|
||||
unfollow_modal: false,
|
||||
boost_modal: false,
|
||||
delete_modal: true,
|
||||
auto_play_gif: false,
|
||||
reduce_motion: false
|
||||
},
|
||||
compose: %{
|
||||
me: "#{user.id}",
|
||||
default_privacy: "public",
|
||||
default_sensitive: false
|
||||
},
|
||||
media_attachments: %{
|
||||
accept_content_types: [
|
||||
".jpg",
|
||||
".jpeg",
|
||||
".png",
|
||||
".gif",
|
||||
".webm",
|
||||
".mp4",
|
||||
".m4v",
|
||||
"image\/jpeg",
|
||||
"image\/png",
|
||||
"image\/gif",
|
||||
"video\/webm",
|
||||
"video\/mp4"
|
||||
]
|
||||
},
|
||||
settings: %{
|
||||
onboarded: true,
|
||||
home: %{
|
||||
shows: %{
|
||||
reblog: true,
|
||||
reply: true
|
||||
}
|
||||
},
|
||||
notifications: %{
|
||||
alerts: %{
|
||||
follow: true,
|
||||
favourite: true,
|
||||
reblog: true,
|
||||
mention: true
|
||||
},
|
||||
shows: %{
|
||||
follow: true,
|
||||
favourite: true,
|
||||
reblog: true,
|
||||
mention: true
|
||||
},
|
||||
sounds: %{
|
||||
follow: true,
|
||||
favourite: true,
|
||||
reblog: true,
|
||||
mention: true
|
||||
}
|
||||
}
|
||||
},
|
||||
push_subscription: nil,
|
||||
accounts: accounts,
|
||||
custom_emojis: %{}
|
||||
} |> Poison.encode!
|
||||
conn
|
||||
|> put_layout(false)
|
||||
|> render(MastodonView, "index.html", %{initial_state: initial_state})
|
||||
else
|
||||
conn
|
||||
|> redirect(to: "/web/login")
|
||||
end
|
||||
end
|
||||
|
||||
def login(conn, params) do
|
||||
conn
|
||||
|> render(MastodonView, "login.html")
|
||||
end
|
||||
|
||||
defp get_or_make_app() do
|
||||
with %App{} = app <- Repo.get_by(App, client_name: "Mastodon-Local") do
|
||||
{:ok, app}
|
||||
else
|
||||
_e ->
|
||||
cs = App.register_changeset(%App{}, %{client_name: "Mastodon-Local", redirect_uris: ".", scopes: "read,write,follow"})
|
||||
Repo.insert(cs)
|
||||
end
|
||||
end
|
||||
|
||||
def login_post(conn, %{"authorization" => %{ "name" => name, "password" => password}}) do
|
||||
with %User{} = user <- User.get_cached_by_nickname(name),
|
||||
true <- Pbkdf2.checkpw(password, user.password_hash),
|
||||
{:ok, app} <- get_or_make_app(),
|
||||
{:ok, auth} <- Authorization.create_authorization(app, user),
|
||||
{:ok, token} <- Token.exchange_token(app, auth) do
|
||||
conn
|
||||
|> put_session(:oauth_token, token.token)
|
||||
|> redirect(to: "/web/timelines/public")
|
||||
end
|
||||
end
|
||||
|
||||
def relationship_noop(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
||||
Logger.debug("Unimplemented, returning unmodified relationship")
|
||||
with %User{} = target <- Repo.get(User, id) do
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
defmodule Pleroma.Web.MastodonAPI.MastodonView do
|
||||
use Pleroma.Web, :view
|
||||
import Phoenix.HTML
|
||||
import Phoenix.HTML.Form
|
||||
end
|
|
@ -21,6 +21,13 @@ def user_fetcher(username) do
|
|||
plug Pleroma.Plugs.AuthenticationPlug, %{fetcher: &Router.user_fetcher/1}
|
||||
end
|
||||
|
||||
pipeline :mastodon_html do
|
||||
plug :accepts, ["html"]
|
||||
plug :fetch_session
|
||||
plug Pleroma.Plugs.OAuthPlug
|
||||
plug Pleroma.Plugs.AuthenticationPlug, %{fetcher: &Router.user_fetcher/1, optional: true}
|
||||
end
|
||||
|
||||
pipeline :well_known do
|
||||
plug :accepts, ["xml", "xrd+xml"]
|
||||
end
|
||||
|
@ -207,6 +214,14 @@ def user_fetcher(username) do
|
|||
get "/webfinger", WebFinger.WebFingerController, :webfinger
|
||||
end
|
||||
|
||||
scope "/web", Pleroma.Web.MastodonAPI do
|
||||
pipe_through :mastodon_html
|
||||
|
||||
get "/login", MastodonAPIController, :login
|
||||
post "/login", MastodonAPIController, :login_post
|
||||
get "/*path", MastodonAPIController, :index
|
||||
end
|
||||
|
||||
scope "/", Fallback do
|
||||
get "/*path", RedirectController, :redirector
|
||||
end
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,10 @@
|
|||
<h2>Login in to Mastodon Frontend</h2>
|
||||
<%= form_for @conn, mastodon_api_path(@conn, :login), [as: "authorization"], fn f -> %>
|
||||
<%= label f, :name, "Name" %>
|
||||
<%= text_input f, :name %>
|
||||
<br>
|
||||
<%= label f, :password, "Password" %>
|
||||
<%= password_input f, :password %>
|
||||
<br>
|
||||
<%= submit "Authorize" %>
|
||||
<% end %>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,43 @@
|
|||
CACHE MANIFEST
|
||||
#ver:11/12/2017, 12:40:57 PM
|
||||
#plugin:4.8.4
|
||||
|
||||
CACHE:
|
||||
/packs/features/compose-4617f6e912b5bfa71c43.js
|
||||
/packs/modals/onboarding_modal-399f44a19ddd0ddc4e9c.js
|
||||
/packs/features/public_timeline-d6e6bc704f49ebf922be.js
|
||||
/packs/features/community_timeline-20bc8a94c08809c127d0.js
|
||||
/packs/features/hashtag_timeline-3ed7e7bf18fd2fc04c9e.js
|
||||
/packs/emoji_picker-9cf581d158c1cefc73c9.js
|
||||
/packs/features/notifications-99d27ff7a90c7f701400.js
|
||||
/packs/features/home_timeline-c146f32b0118845677ee.js
|
||||
/packs/features/account_timeline-cad2550e777d3958eca4.js
|
||||
/packs/features/pinned_statuses-fc56dd5916a37286e823.js
|
||||
/packs/features/favourited_statuses-b15a9a6cc711cca1eb76.js
|
||||
/packs/features/status-1f1807fdb4d1fd6daf40.js
|
||||
/packs/features/following-9060b3726e6ad25f3621.js
|
||||
/packs/features/followers-6716b8606f70dfa12ed7.js
|
||||
/packs/features/account_gallery-b13924812f8dd47200c2.js
|
||||
/packs/modals/report_modal-7a2950f40d4867b9cbb0.js
|
||||
/packs/features/follow_requests-281e5b40331385149920.js
|
||||
/packs/features/mutes-60c139f123f8d11ed903.js
|
||||
/packs/features/blocks-e9605338ea941de78465.js
|
||||
/packs/features/reblogs-e284a8647e830c151a40.js
|
||||
/packs/features/favourites-083fedd11007764f7fad.js
|
||||
/packs/features/getting_started-b65f1e917d66a972f2bf.js
|
||||
/packs/features/generic_not_found-dc757b4cfe00489a06fb.js
|
||||
/packs/modals/embed_modal-c776fd6a0ea581675783.js
|
||||
/packs/status/media_gallery-7642f779bf4243e58b78.js
|
||||
/packs/application-1b1f37dff2aac402336b.js
|
||||
/packs/share-914b479bea45d0f6d4aa.js
|
||||
/packs/about-d6275c885cd0e28a1186.js
|
||||
/packs/public-88b87539fc95f07f2721.js
|
||||
/packs/default-99ffdcf166b2dedef105.js
|
||||
/packs/admin-1bab981afc4fd0d71402.js
|
||||
/packs/common-1789b98651001ef10c0b.js
|
||||
/packs/common-daadaac9454e7d14470e7954e3143dca.css
|
||||
/packs/default-818c1287ac3c764905d81e549d5e0160.css
|
||||
/packs/manifest.json
|
||||
|
||||
NETWORK:
|
||||
*
|
|
@ -0,0 +1,2 @@
|
|||
<!doctype html>
|
||||
<html manifest="manifest.appcache"></html>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 40 KiB |
Binary file not shown.
After Width: | Height: | Size: 142 KiB |
Binary file not shown.
After Width: | Height: | Size: 24 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
After Width: | Height: | Size: 434 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue