2025-01-03 14:45:35 +00:00
|
|
|
defmodule BrightWeb.Router do
|
|
|
|
use BrightWeb, :router
|
2025-01-11 03:10:04 +00:00
|
|
|
|
2025-01-11 12:47:23 +00:00
|
|
|
|
2025-01-03 14:45:35 +00:00
|
|
|
|
|
|
|
pipeline :browser do
|
|
|
|
plug :accepts, ["html", "json"]
|
|
|
|
plug :fetch_session
|
|
|
|
plug :fetch_live_flash
|
|
|
|
plug :put_root_layout, html: {BrightWeb.Layouts, :root}
|
|
|
|
plug :protect_from_forgery
|
|
|
|
plug :put_secure_browser_headers
|
|
|
|
end
|
|
|
|
|
2025-01-11 12:47:23 +00:00
|
|
|
|
2025-01-11 03:10:04 +00:00
|
|
|
|
|
|
|
|
2025-01-03 14:45:35 +00:00
|
|
|
defp fetch_current_user(conn, _) do
|
|
|
|
if user_uuid = get_session(conn, :current_uuid) do
|
|
|
|
assign(conn, :current_uuid, user_uuid)
|
|
|
|
else
|
|
|
|
new_uuid = Ecto.UUID.generate()
|
|
|
|
conn
|
|
|
|
|> assign(:current_uuid, new_uuid)
|
|
|
|
|> put_session(:current_uuid, new_uuid)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2025-01-11 12:47:23 +00:00
|
|
|
|
2025-01-03 14:45:35 +00:00
|
|
|
|
|
|
|
pipeline :api do
|
|
|
|
plug :accepts, ["json"]
|
|
|
|
end
|
|
|
|
|
2025-01-11 03:10:04 +00:00
|
|
|
scope "/" do
|
2025-01-11 12:47:23 +00:00
|
|
|
pipe_through [:browser]
|
2025-01-11 03:10:04 +00:00
|
|
|
|
2025-01-11 12:47:23 +00:00
|
|
|
# get "/streams/new", StreamController, :new
|
|
|
|
# post "/streams", StreamController, :create
|
2025-01-11 03:10:04 +00:00
|
|
|
end
|
|
|
|
|
2025-01-11 12:47:23 +00:00
|
|
|
|
2025-01-03 14:45:35 +00:00
|
|
|
scope "/", BrightWeb do
|
|
|
|
pipe_through :browser
|
|
|
|
|
|
|
|
get "/", PageController, :home
|
|
|
|
|
|
|
|
get "/patrons", PatronController, :index
|
|
|
|
get "/about", PageController, :about
|
|
|
|
get "/api", PageController, :api
|
2025-01-12 05:07:27 +00:00
|
|
|
get "/health", PageController, :health
|
2025-01-03 14:45:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
resources "/orders", OrderController, only: [:create, :show]
|
|
|
|
|
|
|
|
resources "/archive", StreamController
|
2025-01-11 03:10:04 +00:00
|
|
|
get "/streams", StreamController, :index
|
2025-01-11 12:47:23 +00:00
|
|
|
get "/streams/:id", StreamController, :show
|
|
|
|
get "/streams/new", StreamController, :new
|
|
|
|
post "/streams", StreamController, :create
|
2025-01-03 14:45:35 +00:00
|
|
|
|
|
|
|
resources "/vods", VodController
|
|
|
|
|
|
|
|
resources "/vtubers", VtuberController
|
|
|
|
resources "/vt", VtuberController do
|
|
|
|
resources "/vods", VodController
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2025-01-11 12:47:23 +00:00
|
|
|
|
|
|
|
|
2025-01-03 14:45:35 +00:00
|
|
|
# resources "/users", UserController
|
|
|
|
resources "/tags", TagController
|
|
|
|
|
|
|
|
## @todo DANGER, platforms must only be writable by admins, (unless we implement SVG sanitizing)
|
|
|
|
resources "/platforms", PlatformController
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
# Other scopes may use custom stacks.
|
|
|
|
scope "/api", BrightWeb do
|
|
|
|
pipe_through :api
|
|
|
|
resources "/urls", UrlController, except: [:new, :edit]
|
|
|
|
end
|
|
|
|
|
|
|
|
# Enable LiveDashboard and Swoosh mailbox preview in development
|
|
|
|
if Application.compile_env(:bright, :dev_routes) do
|
|
|
|
# If you want to use the LiveDashboard in production, you should put
|
|
|
|
# it behind authentication and allow only admins to access it.
|
|
|
|
# If your application does not have an admins-only section yet,
|
|
|
|
# you can use Plug.BasicAuth to set up some basic authentication
|
|
|
|
# as long as you are also using SSL (which you should anyway).
|
|
|
|
import Phoenix.LiveDashboard.Router
|
|
|
|
|
|
|
|
scope "/dev" do
|
|
|
|
pipe_through :browser
|
|
|
|
|
|
|
|
live_dashboard "/dashboard", metrics: BrightWeb.Telemetry
|
|
|
|
forward "/mailbox", Plug.Swoosh.MailboxPreview
|
|
|
|
end
|
|
|
|
end
|
2025-01-11 03:10:04 +00:00
|
|
|
|
|
|
|
## Authentication routes
|
|
|
|
|
|
|
|
scope "/", BrightWeb do
|
2025-01-11 12:47:23 +00:00
|
|
|
pipe_through [:browser]
|
2025-01-11 03:10:04 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-01-03 14:45:35 +00:00
|
|
|
end
|