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,7 +20,7 @@ defmodule Ketbin.Pastes.Utils do
def is_url?(url) do def is_url?(url) do
try do try do
uri = URI.parse(url) 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 rescue
FunctionClauseError -> false FunctionClauseError -> false
end end

View File

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

View File

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