feat(pastes): decide highlighting rules using extension
Signed-off-by: SphericalKat <amolele@gmail.com>
This commit is contained in:
		
							parent
							
								
									425fb2b571
								
							
						
					
					
						commit
						182a5b1e55
					
				| @ -13,21 +13,24 @@ defmodule KetbinWeb.PageController do | ||||
|   end | ||||
| 
 | ||||
|   def show(%{assigns: %{show_edit: show_edit}} = conn, %{"id" => id}) do | ||||
|     [head | tail] = String.split(id, ".") | ||||
| 
 | ||||
|     # fetch paste from db | ||||
|     paste = Pastes.get_paste!(id) | ||||
|     paste = Pastes.get_paste!(head) | ||||
| 
 | ||||
|     # paste is a url, redirect | ||||
|     # regular paste, show content | ||||
|     if paste.is_url do | ||||
|       redirect(conn, external: paste.content) | ||||
|     else | ||||
|       render(conn, "show.html", paste: paste, show_edit: show_edit) | ||||
|       render(conn, "show.html", paste: paste, show_edit: show_edit, extension: List.first(tail) || "") | ||||
|     end | ||||
|   end | ||||
| 
 | ||||
|   def showlink(%{assigns: %{show_edit: show_edit}} = conn, %{"id" => id}) do | ||||
|     paste = Pastes.get_paste!(id) | ||||
|     render(conn, "show.html", paste: paste, show_edit: show_edit) | ||||
|     [head | tail] = String.split(id, ".") | ||||
|     paste = Pastes.get_paste!(head) | ||||
|     render(conn, "show.html", paste: paste, show_edit: show_edit, extension: List.first(tail) || "") | ||||
|   end | ||||
| 
 | ||||
|   def raw(conn, %{"id" => id}) do | ||||
|  | ||||
| @ -97,12 +97,14 @@ defmodule KetbinWeb.UserAuth do | ||||
|   end | ||||
| 
 | ||||
|   def owns_paste(%{params: %{"id" => id}, assigns: %{current_user: user}} = conn, _params) do | ||||
|     paste = Pastes.get_paste!(id) | ||||
|     [head|_tail] = String.split(id, ".") | ||||
|     paste = Pastes.get_paste!(head) | ||||
|     assign(conn, :show_edit, (user && user.id == paste.belongs_to) || false) | ||||
|   end | ||||
| 
 | ||||
|   def ensure_owns_paste(%{params: %{"id" => id}, assigns: %{current_user: user}} = conn, _params) do | ||||
|     paste = Pastes.get_paste!(id) | ||||
|     [head|_tail] = String.split(id, ".") | ||||
|     paste = Pastes.get_paste!(head) | ||||
|     allow_edit = (user && user.id == paste.belongs_to) || false | ||||
|     unless allow_edit do | ||||
|       conn | ||||
|  | ||||
| @ -8,5 +8,5 @@ | ||||
| 		</a> | ||||
| 		<% end %> | ||||
| 	</div> | ||||
| 	<code class="break-word px-6 py-4 h-full w-full nomarkdown overflow-y-auto"><%= raw Ketbin.Utils.Syntax.highlight_text(@paste.content, "rs") %></code> | ||||
| 	<code class="break-word px-6 py-4 h-full w-full nomarkdown overflow-y-auto"><%= raw Ketbin.Utils.Syntax.highlight_text(@paste.content, @extension) %></code> | ||||
| </div> | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user