fix some bugs n stuff

This commit is contained in:
zack 2024-10-24 20:22:37 -04:00
parent b925726977
commit d7559647e2
No known key found for this signature in database
GPG key ID: 5F873416BCF59F35
7 changed files with 90 additions and 21 deletions

View file

@ -1,4 +1,5 @@
defmodule ZoeyscomputerWeb.Router do
alias ZoeyscomputerWeb.DiscordPlug
use ZoeyscomputerWeb, :router
import ZoeyscomputerWeb.UserAuth
@ -17,6 +18,10 @@ defmodule ZoeyscomputerWeb.Router do
plug ZoeyscomputerWeb.Plugs.ApiAuthentication
end
pipeline :discord do
plug DiscordPlug
end
pipeline :api do
plug :accepts, ["json"]
end
@ -80,6 +85,8 @@ defmodule ZoeyscomputerWeb.Router do
live "/images/new", ImageLive.Index, :new
live "/images/:id/edit", ImageLive.Index, :edit
live "/images", ImageLive.Index, :index
live "/images/:id/show/edit", ImageLive.Show, :edit
live "/api-keys", ApiKeyLive.Index, :index
@ -101,9 +108,28 @@ defmodule ZoeyscomputerWeb.Router do
live "/users/confirm/:token", UserConfirmationLive, :edit
live "/users/confirm", UserConfirmationInstructionsLive, :new
live "/", HomeLive, :index
end
end
live "/images", ImageLive.Index, :index
live "/images/:id", ImageLive.Show, :show
scope "/", ZoeyscomputerWeb do
pipe_through :check_discord
live "/images/:id", ImageController, :show
end
def check_discord(conn, _opts) do
case get_req_header(conn, "user-agent") do
["Discord" <> _rest | _] ->
conn
|> put_private(:phoenix_pipeline, {:doscord, []})
|> DiscordPlug.call([])
["Discord-Bot/" <> _rest | _] ->
conn
|> put_private(:phoenix_pipeline, {:discord, []})
|> DiscordPlug.call([])
_ ->
conn |> put_private(:phoenix_pipeline, {:browser, []})
end
end
end