diff of 902127126e0ef5f14a67ed4b60ebe7362ea4f4c9

902127126e0ef5f14a67ed4b60ebe7362ea4f4c9
diff --git a/resources/sql/media-fns.sql b/resources/sql/media-fns.sql
index 796780a..47b7a22 100644
--- a/resources/sql/media-fns.sql
+++ b/resources/sql/media-fns.sql
@@ -1,9 +1,9 @@
 -- name: insert-media
 insert into blog.media (name, data) values ($1, $2) returning id;
 
--- name: get-media :? :1
+-- name: get-media
 -- returns: :array-hash
-select name, data from blog.media where id = $1§::uuid ;
+select name, data from blog.media where id = $1::uuid ;
 
 -- name: list-pictures*
 -- returns: :array-hash
@@ -15,4 +15,4 @@ delete from blog.media where id = $1§;
 
 -- name: select-referencing-posts* :?
 -- returns: :array-hash
-select * from blog.media_post_pairing where media_id = $1§;
+select * from blog.media_post_pairing where media_id = $1;
diff --git a/src/media/media-db.lisp b/src/media/media-db.lisp
index 4d1b844..af41a9b 100644
--- a/src/media/media-db.lisp
+++ b/src/media/media-db.lisp
@@ -3,7 +3,7 @@
   (:import-from :com.inuoe.jzon :parse)
   (:import-from :halisql :defqueries)
   (:import-from :lisp-fixup :fix-timestamp)
-  (:export :list-pictures :insert-media))
+  (:export :list-pictures :get-media :insert-media :select-referencing-posts*))
 
 (in-package :murja.media.media-db)
 
@@ -11,4 +11,3 @@
 
 (defun list-pictures ()
   (list-pictures*))
-  
diff --git a/src/routes/media-routes.lisp b/src/routes/media-routes.lisp
index 8b4ad44..bf3fe9a 100644
--- a/src/routes/media-routes.lisp
+++ b/src/routes/media-routes.lisp
@@ -3,7 +3,7 @@
   (:import-from :lisp-fixup :slurp-bytes)
   (:import-from :com.inuoe.jzon :stringify)
   (:import-from :murja.middleware.db :@transaction)
-  (:import-from :murja.media.media-db :list-pictures :insert-media)
+  (:import-from :murja.media.media-db :list-pictures :insert-media :select-referencing-posts* :get-media)
    
   (:import-from :murja.middleware.json :@json)
   (:import-from :murja.middleware.auth :@authenticated :@can? :*user*)
@@ -36,3 +36,19 @@
 	  (stringify pics)
 	  "[]")))
       
+(defroute referencing-route ("/api/pictures/referencing/:guid" :method :get
+							       :decorators (@transaction
+									    @authenticated)) ()
+  (stringify (select-referencing-posts* guid)))
+
+(defroute picture-route ("/api/pictures/:guid" :method :get
+					       :decorators (@transaction)) ()
+  (let ((pic (aref (get-media guid) 0)))
+    ;; murja doesn't persist images' exact mime (yet), and we don't want
+    ;; browsers calling straight to this endpoint downloading these images
+    ;; (so application/octet-stream can't be used), so we return nil as
+    ;; content-type (as the old clj-murja does) for now
+    (setf (hunchentoot:content-type*) nil)
+    (setf (hunchentoot:header-out "Content-Disposition")
+	  (format nil "inline; filename=~a" (gethash "name" pic)))
+    (gethash "data" pic)))