feat(pastes): set up redirection routes
Signed-off-by: SphericalKat <amolele@gmail.com>
This commit is contained in:
parent
750d62cc73
commit
f411017280
@ -12,6 +12,16 @@ defmodule KetbinWeb.PageController do
|
||||
|
||||
def show(conn, %{"id" => id}) do
|
||||
paste = Pastes.get_paste!(id)
|
||||
|
||||
if paste.is_url do
|
||||
redirect(conn, external: paste.content)
|
||||
else
|
||||
render(conn, "show.html", paste: paste)
|
||||
end
|
||||
end
|
||||
|
||||
def showlink(conn, %{"id" => id}) do
|
||||
paste = Pastes.get_paste!(id)
|
||||
render(conn, "show.html", paste: paste)
|
||||
end
|
||||
|
||||
@ -28,8 +38,13 @@ defmodule KetbinWeb.PageController do
|
||||
|
||||
case Pastes.create_paste(paste_params) do
|
||||
{:ok, paste} ->
|
||||
conn
|
||||
|> redirect(to: Routes.page_path(conn, :show, paste))
|
||||
unless is_url do
|
||||
conn
|
||||
|> redirect(to: Routes.page_path(conn, :show, paste))
|
||||
else
|
||||
conn
|
||||
|> redirect(to: Routes.page_path(conn, :showlink, paste))
|
||||
end
|
||||
|
||||
{:error, %Ecto.Changeset{} = changeset} ->
|
||||
render(conn, "index.html", changeset: changeset)
|
||||
|
@ -21,6 +21,7 @@ defmodule KetbinWeb.Router do
|
||||
|
||||
get "/", PageController, :index
|
||||
get "/:id", PageController, :show
|
||||
get "/v/:id", PageController, :showlink
|
||||
post "/", PageController, :create
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user