2021-09-01 12:43:55 +00:00
|
|
|
defmodule ArchitexWeb.Router do
|
|
|
|
use ArchitexWeb, :router
|
2021-06-22 12:09:25 +00:00
|
|
|
|
2021-09-01 12:43:55 +00:00
|
|
|
alias ArchitexWeb.Client.Plug.AuthenticateClient
|
2021-08-08 17:20:10 +00:00
|
|
|
|
|
|
|
# TODO: might be able to handle malformed JSON with custom body reader:
|
|
|
|
# https://elixirforum.com/t/write-malformed-json-in-the-body-plug/30578/13
|
2021-06-25 23:14:09 +00:00
|
|
|
|
2021-08-17 20:50:15 +00:00
|
|
|
# TODO: Split endpoint into client and federation?
|
|
|
|
|
2021-06-25 22:29:33 +00:00
|
|
|
pipeline :public do
|
2021-06-22 12:09:25 +00:00
|
|
|
plug :accepts, ["json"]
|
|
|
|
end
|
|
|
|
|
2021-08-06 21:14:27 +00:00
|
|
|
pipeline :authenticate_client do
|
2021-06-25 22:29:33 +00:00
|
|
|
plug :accepts, ["json"]
|
2021-08-17 20:50:15 +00:00
|
|
|
plug AuthenticateClient
|
2021-06-25 22:29:33 +00:00
|
|
|
end
|
|
|
|
|
2021-08-06 21:14:27 +00:00
|
|
|
pipeline :authenticate_server do
|
|
|
|
plug :accepts, ["json"]
|
|
|
|
end
|
|
|
|
|
2021-08-17 20:50:15 +00:00
|
|
|
# Public client endpoint.
|
2021-09-01 12:43:55 +00:00
|
|
|
scope "/_matrix/client", ArchitexWeb.Client do
|
2021-06-25 22:29:33 +00:00
|
|
|
pipe_through :public
|
2021-06-22 21:04:37 +00:00
|
|
|
|
2021-08-17 20:50:15 +00:00
|
|
|
scope "/r0" do
|
2021-08-27 13:09:17 +00:00
|
|
|
get "/directory/list/room/:room_id", RoomDirectoryController, :get_visibility
|
2021-09-08 15:32:10 +00:00
|
|
|
|
|
|
|
scope "/login" do
|
|
|
|
get "/", LoginController, :login_types
|
|
|
|
post "/", LoginController, :login
|
|
|
|
end
|
|
|
|
|
|
|
|
scope "/register" do
|
|
|
|
post "/", RegisterController, :register
|
|
|
|
get "/available", AccountController, :available
|
|
|
|
end
|
|
|
|
|
|
|
|
scope "/profile/:user_id" do
|
2021-09-08 18:21:55 +00:00
|
|
|
get "/", ProfileController, :profile
|
2021-09-08 15:32:10 +00:00
|
|
|
get "/avatar_url", ProfileController, :get_avatar_url
|
|
|
|
get "/displayname", ProfileController, :get_displayname
|
|
|
|
end
|
2021-06-22 21:04:37 +00:00
|
|
|
end
|
2021-06-22 23:49:47 +00:00
|
|
|
|
2021-08-17 20:50:15 +00:00
|
|
|
get "/versions", InfoController, :versions
|
|
|
|
end
|
|
|
|
|
|
|
|
# Public federation endpoint.
|
2021-09-01 12:43:55 +00:00
|
|
|
scope "/_matrix", ArchitexWeb.Federation do
|
2021-08-17 20:50:15 +00:00
|
|
|
scope "/key/v2" do
|
2021-08-06 13:52:03 +00:00
|
|
|
get "/server", KeyController, :get_signing_keys
|
|
|
|
end
|
2021-06-22 12:09:25 +00:00
|
|
|
end
|
2021-06-25 22:29:33 +00:00
|
|
|
|
2021-08-17 20:50:15 +00:00
|
|
|
# Authenticated client endpoint.
|
2021-09-01 12:43:55 +00:00
|
|
|
scope "/_matrix/client", ArchitexWeb.Client do
|
2021-08-06 21:14:27 +00:00
|
|
|
pipe_through :authenticate_client
|
2021-06-25 22:29:33 +00:00
|
|
|
|
2021-08-17 20:50:15 +00:00
|
|
|
scope "/r0" do
|
2021-06-25 22:29:33 +00:00
|
|
|
get "/account/whoami", AccountController, :whoami
|
2021-06-27 20:24:54 +00:00
|
|
|
post "/logout", AccountController, :logout
|
|
|
|
post "/logout/all", AccountController, :logout_all
|
2021-07-10 21:16:00 +00:00
|
|
|
post "/createRoom", RoomController, :create
|
2021-08-23 10:59:12 +00:00
|
|
|
get "/joined_rooms", RoomController, :joined_rooms
|
2021-09-06 18:33:23 +00:00
|
|
|
get "/capabilities", InfoController, :capabilities
|
2021-09-07 18:24:06 +00:00
|
|
|
get "/sync", SyncController, :sync
|
2021-09-08 15:32:10 +00:00
|
|
|
|
|
|
|
scope "/profile/:user_id" do
|
|
|
|
put "/avatar_url", ProfileController, :set_avatar_url
|
|
|
|
put "/displayname", ProfileController, :set_displayname
|
|
|
|
end
|
2021-07-30 13:56:24 +00:00
|
|
|
|
2021-08-27 13:09:17 +00:00
|
|
|
scope "/directory" do
|
|
|
|
put "/room/:alias", AliasesController, :create
|
|
|
|
put "/list/room/:room_id", RoomDirectoryController, :set_visibility
|
2021-07-30 13:56:24 +00:00
|
|
|
end
|
2021-08-24 23:27:03 +00:00
|
|
|
|
|
|
|
scope "/rooms/:room_id" do
|
|
|
|
post "/invite", RoomController, :invite
|
2021-08-25 10:25:14 +00:00
|
|
|
post "/join", RoomController, :join
|
2021-08-26 09:01:19 +00:00
|
|
|
post "/leave", RoomController, :leave
|
2021-08-26 12:32:24 +00:00
|
|
|
post "/kick", RoomController, :kick
|
2021-08-26 20:09:45 +00:00
|
|
|
post "/ban", RoomController, :ban
|
|
|
|
post "/unban", RoomController, :unban
|
2021-09-10 19:51:45 +00:00
|
|
|
put "/send/:event_type/:txn_id", RoomController, :send_message_event
|
2021-09-04 14:40:17 +00:00
|
|
|
get "/messages", RoomController, :messages
|
2021-09-10 19:51:45 +00:00
|
|
|
put "/state/:event_type/*state_key", RoomController, :send_state_event
|
2021-08-24 23:27:03 +00:00
|
|
|
end
|
2021-06-25 22:29:33 +00:00
|
|
|
end
|
|
|
|
end
|
2021-06-26 20:02:18 +00:00
|
|
|
|
2021-08-17 20:50:15 +00:00
|
|
|
# Authenticated federation endpoint.
|
2021-09-01 12:43:55 +00:00
|
|
|
scope "/_matrix/federation", ArchitexWeb.Federation do
|
2021-08-08 17:20:10 +00:00
|
|
|
pipe_through :authenticate_server
|
2021-08-06 21:14:27 +00:00
|
|
|
|
2021-08-17 20:50:15 +00:00
|
|
|
scope "/v1" do
|
|
|
|
get "/query/profile", QueryController, :profile
|
|
|
|
get "/event/:event_id", EventController, :event
|
2021-08-21 19:39:28 +00:00
|
|
|
get "/state/:room_id", EventController, :state
|
2021-08-22 10:19:47 +00:00
|
|
|
get "/state_ids/:room_id", EventController, :state_ids
|
2021-08-17 20:50:15 +00:00
|
|
|
end
|
2021-08-06 21:14:27 +00:00
|
|
|
end
|
|
|
|
|
2021-09-01 12:43:55 +00:00
|
|
|
scope "/", ArchitexWeb.Client do
|
2021-06-26 20:02:18 +00:00
|
|
|
match :*, "/*path", InfoController, :unrecognized
|
|
|
|
end
|
2021-06-22 12:09:25 +00:00
|
|
|
end
|