diff --git a/lib/ketbin_web/controllers/page_controller.ex b/lib/ketbin_web/controllers/page_controller.ex index a042622..315cce6 100644 --- a/lib/ketbin_web/controllers/page_controller.ex +++ b/lib/ketbin_web/controllers/page_controller.ex @@ -16,7 +16,13 @@ defmodule KetbinWeb.PageController do [head | tail] = String.split(id, ".") # fetch paste from db - paste = Pastes.get_paste!(head) + paste = + try do + Pastes.get_paste!(head) + rescue + Ecto.NoResultsError -> + Pastes.get_paste!(id) + end # paste is a url, redirect # regular paste, show content diff --git a/lib/ketbin_web/controllers/user_auth.ex b/lib/ketbin_web/controllers/user_auth.ex index 748265e..dae64e4 100644 --- a/lib/ketbin_web/controllers/user_auth.ex +++ b/lib/ketbin_web/controllers/user_auth.ex @@ -98,7 +98,15 @@ defmodule KetbinWeb.UserAuth do def owns_paste(%{params: %{"id" => id}, assigns: %{current_user: user}} = conn, _params) do [head | _tail] = String.split(id, ".") - paste = Pastes.get_paste!(head) + + paste = + try do + Pastes.get_paste!(head) + rescue + Ecto.NoResultsError -> + Pastes.get_paste!(id) + end + assign(conn, :show_edit, (user && user.id == paste.belongs_to) || false) end