summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--package.lisp9
-rw-r--r--pastiche.lisp35
2 files changed, 32 insertions, 12 deletions
diff --git a/package.lisp b/package.lisp
index 8bce337..2e317e7 100644
--- a/package.lisp
+++ b/package.lisp
@@ -3,6 +3,15 @@
(defpackage #:pastiche
(:use #:cl)
(:import-from #:flatbind #:do>)
+ (:import-from
+ #:hypnotisml
+ #:<html>
+ #:<body>
+ #:<head>
+ #:<h4>
+ #:<a>
+ #:<pre>
+ #:@)
(:local-nicknames
(#:a #:alexandria-2)
(#:db #:bknr.datastore)
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))))