fix(pastes): attempt getting a non-split version of the paste id

Signed-off-by: Amogh Lele <amolele@gmail.com>
This commit is contained in:
Amogh Lele 2022-05-28 10:58:17 +05:30
parent 94451e37d8
commit 4fcf5489da
No known key found for this signature in database
GPG Key ID: 8FF3CF17CA7CFABD
2 changed files with 16 additions and 2 deletions

View File

@ -16,7 +16,13 @@ defmodule KetbinWeb.PageController do
[head | tail] = String.split(id, ".") [head | tail] = String.split(id, ".")
# fetch paste from db # 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 # paste is a url, redirect
# regular paste, show content # regular paste, show content

View File

@ -98,7 +98,15 @@ defmodule KetbinWeb.UserAuth do
def owns_paste(%{params: %{"id" => id}, assigns: %{current_user: user}} = conn, _params) do def owns_paste(%{params: %{"id" => id}, assigns: %{current_user: user}} = conn, _params) do
[head | _tail] = String.split(id, ".") [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) assign(conn, :show_edit, (user && user.id == paste.belongs_to) || false)
end end