diff options
Diffstat (limited to 'pastiche.lisp')
-rw-r--r-- | pastiche.lisp | 35 |
1 files changed, 23 insertions, 12 deletions
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:<body> - (html:<h2> (title paste)) - (html:<pre> (escape-html-in-paste-content content)))) + (<html> + (<body> + (<a> (@ :href (http:route-to 'raw-paste :id id)) + "raw") + (<h4> (title paste)) + (<pre> (escape-html-in-paste-content content)))) out)))) |