From 7a6f330497954952795ca4b1553ee4da6575b7c0 Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Thu, 22 Sep 2022 21:28:54 +0100 Subject: [PATCH] begin defroutes for viewing files in /storage/media. I need to work on this functionality a bit more. This is an end of session commit. Started it and it works but needs expanding. I could do with adding file-type checks and changing 'octet/stream' to something like 'image/png' depending on the file-type (storage in DB). This will stop the browser from downloading every file in /storage/media and allow the files which can be viewed in the browser (like images). --- src/web.lisp | 10 +++++++++- templates/user/storage.html | 5 +++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/web.lisp b/src/web.lisp index 2493b5a..59ae56d 100644 --- a/src/web.lisp +++ b/src/web.lisp @@ -738,6 +738,15 @@ (progn (utils:set-alert "You are not authorised to delete page.") (redirect "/login"))))))) +;; TODO: Add condition branches for file-type. +;; This is working but I could do with adding content-types for images +;; and text so the browser doesn't always down the asset/media/file. +(defroute ("/storage/view/:slug" :method :GET) (&key slug) + (if (storage:file-exists-p "" "media" slug) + `(200 (:content-type "octet/stream") + ,(storage:open-binary-file "" "media" slug)) + (on-exception *web* 404))) + (defroute ("/storage/manage" :method :GET) () (hermetic:auth (:logged-in) ;; Authorised @@ -843,7 +852,6 @@ (utils:set-alert "You are not authorised to view this page.") (redirect "/login")))))) -;; TODO: FINISH WORKING ON /STORAGE/DELETE DEFROUTE -- NEED TO TEST IT. (defroute ("/storage/delete/:slug" :method :POST) (&key slug) (destructuring-bind (&key authenticity-token &allow-other-keys) diff --git a/templates/user/storage.html b/templates/user/storage.html index 07f2117..a80f19c 100644 --- a/templates/user/storage.html +++ b/templates/user/storage.html @@ -26,7 +26,9 @@ {% for item in files %}

- + + + {{item.name}} {% if roles.administrator %}

@@ -42,5 +44,4 @@

{% endfor %} - {% endblock %}