feat(pastes): add raw paste handler
Signed-off-by: SphericalKat <amolele@gmail.com>
This commit is contained in:
parent
40b55e47de
commit
75ac6be3a6
@ -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
|
||||||
|
@ -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()
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user