From 9586e51ed32d96c71e53f5c20def37444ba1b64d Mon Sep 17 00:00:00 2001 From: colin Date: Mon, 12 Aug 2024 07:18:12 -0700 Subject: Added raw link --- pastiche.lisp | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'pastiche.lisp') diff --git a/pastiche.lisp b/pastiche.lisp index 2c16af5..d768b42 100644 --- a/pastiche.lisp +++ b/pastiche.lisp @@ -142,7 +142,7 @@ E.g. you'd put this in a file. (service-protocol*) (service-domain*) (service-port*) - (http:route-to 'get-paste :id (filename paste)))) + (http:route-to 'view-paste :id (filename paste)))) (eval-when (:compile-toplevel :load-toplevel :execute) (def:const +paste-id-regex+ "(([a-zA-Z0-9]*-)+[0-9]+)" @@ -163,28 +163,39 @@ from make-paste-filename.")) (loop :for char :across str :do (write-escaped-char char)))) -(http:defendpoint get-paste +(http:defendpoint raw-paste + :get :route "raw" "paste" (:id +paste-id-regex+) + :returns "text/plain" + :parameters + (id string) + :var instance + :handle + (do> + paste :when= (or (lookup-paste id) (http:not-found instance)) + (a:read-file-into-string + (merge-pathnames (filename paste) (paste-path*))))) + + +(http:defendpoint view-paste :get :route "paste" (:id +paste-id-regex+) :returns "text/html" :parameters (id string) - :properties - (paste paste) - :authenticate - (or (setf paste (lookup-paste id)) - (http:not-found instance)) - :documentation "Fetch a " + :documentation "Show paste in an html page." :var instance :handle (do> + paste :when= (or (lookup-paste id) (http:not-found instance)) filename := (merge-pathnames (filename paste) (paste-path*)) content := (a:read-file-into-string filename) (with-output-to-string (out) (html:html - (html: - (html: - (html:

(title paste)) - (html:
 (escape-html-in-paste-content content))))
+       (
+        (
+         ( (@ :href (http:route-to 'raw-paste :id id))
+              "raw")
+         (

(title paste)) + (
 (escape-html-in-paste-content content))))
        out))))
 
 
-- 
cgit v1.2.3