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
|
def show(conn, %{"id" => id}) do
|
||||||
paste = Pastes.get_paste!(id)
|
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)
|
render(conn, "show.html", paste: paste)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -28,8 +38,13 @@ defmodule KetbinWeb.PageController do
|
|||||||
|
|
||||||
case Pastes.create_paste(paste_params) do
|
case Pastes.create_paste(paste_params) do
|
||||||
{:ok, paste} ->
|
{:ok, paste} ->
|
||||||
conn
|
unless is_url do
|
||||||
|> redirect(to: Routes.page_path(conn, :show, paste))
|
conn
|
||||||
|
|> redirect(to: Routes.page_path(conn, :show, paste))
|
||||||
|
else
|
||||||
|
conn
|
||||||
|
|> redirect(to: Routes.page_path(conn, :showlink, paste))
|
||||||
|
end
|
||||||
|
|
||||||
{:error, %Ecto.Changeset{} = changeset} ->
|
{:error, %Ecto.Changeset{} = changeset} ->
|
||||||
render(conn, "index.html", changeset: changeset)
|
render(conn, "index.html", changeset: changeset)
|
||||||
|
@ -21,6 +21,7 @@ defmodule KetbinWeb.Router do
|
|||||||
|
|
||||||
get "/", PageController, :index
|
get "/", PageController, :index
|
||||||
get "/:id", PageController, :show
|
get "/:id", PageController, :show
|
||||||
|
get "/v/:id", PageController, :showlink
|
||||||
post "/", PageController, :create
|
post "/", PageController, :create
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user