From 75ac6be3a6f7f862142267c3b8d04228a556152f Mon Sep 17 00:00:00 2001 From: SphericalKat Date: Sat, 14 Aug 2021 15:19:16 +0530 Subject: [PATCH] feat(pastes): add raw paste handler Signed-off-by: SphericalKat --- lib/ketbin/pastes/utils.ex | 4 ++-- lib/ketbin_web/controllers/page_controller.ex | 5 +++++ lib/ketbin_web/router.ex | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/ketbin/pastes/utils.ex b/lib/ketbin/pastes/utils.ex index d408c71..15c3c62 100644 --- a/lib/ketbin/pastes/utils.ex +++ b/lib/ketbin/pastes/utils.ex @@ -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 \ No newline at end of file +end diff --git a/lib/ketbin_web/controllers/page_controller.ex b/lib/ketbin_web/controllers/page_controller.ex index b8297d4..89f551f 100644 --- a/lib/ketbin_web/controllers/page_controller.ex +++ b/lib/ketbin_web/controllers/page_controller.ex @@ -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() diff --git a/lib/ketbin_web/router.ex b/lib/ketbin_web/router.ex index e0e47e0..3d5ee79 100644 --- a/lib/ketbin_web/router.ex +++ b/lib/ketbin_web/router.ex @@ -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