feat(pastes): add raw paste handler

Signed-off-by: SphericalKat <amolele@gmail.com>
This commit is contained in:
Amogh Lele 2021-08-14 15:19:16 +05:30
parent 40b55e47de
commit 75ac6be3a6
No known key found for this signature in database
GPG Key ID: ED5C54FBBB920E51
3 changed files with 9 additions and 3 deletions

View File

@ -20,9 +20,9 @@ defmodule Ketbin.Pastes.Utils do
def is_url?(url) do
try do
uri = URI.parse(url)
uri.scheme != nil && uri.host =~ "." && Enum.member?(["https", "http"], uri.scheme)
uri.scheme != nil && uri.host =~ "." && Enum.member?(["https", "http", "mailto"], uri.scheme) && !(uri.host =~ "katb.in")
rescue
FunctionClauseError -> false
end
end
end
end

View File

@ -25,6 +25,11 @@ defmodule KetbinWeb.PageController do
render(conn, "show.html", paste: paste)
end
def raw(conn, %{"id" => id}) do
paste = Pastes.get_paste!(id)
text(conn, paste.content)
end
def create(conn, %{"paste" => paste_params}) do
# generate phonetic key
id = Utils.generate_key()

View File

@ -17,10 +17,11 @@ defmodule KetbinWeb.Router do
end
scope "/", KetbinWeb do
pipe_through :browser
pipe_through [:browser, :fetch_current_user]
get "/", PageController, :index
get "/:id", PageController, :show
get "/:id/raw", PageController, :raw
get "/v/:id", PageController, :showlink
post "/", PageController, :create
end